예제 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public ReplicatedLockTokenState unmarshal0(org.neo4j.storageengine.api.ReadableChannel channel) throws java.io.IOException, org.neo4j.causalclustering.messaging.EndOfStreamException
            public override ReplicatedLockTokenState Unmarshal0(ReadableChannel channel)
            {
                long     logIndex    = channel.Long;
                int      candidateId = channel.Int;
                MemberId member      = MemberMarshal.unmarshal(channel);

                return(new ReplicatedLockTokenState(logIndex, new ReplicatedLockTokenRequest(member, candidateId)));
            }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldMarshalClusterId() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldMarshalClusterId()
        {
            // given
            ClusterId    original     = new ClusterId(System.Guid.randomUUID());
            MemoryStream outputStream = new MemoryStream();

            // when
            OutputStreamWritableChannel writableChannel = new OutputStreamWritableChannel(outputStream);

            _marshal.marshal(original, writableChannel);

            InputStreamReadableChannel readableChannel = new InputStreamReadableChannel(new MemoryStream(outputStream.toByteArray()));
            ClusterId result = _marshal.unmarshal(readableChannel);

            // then
            assertNotSame(original, result);
            assertEquals(original, result);
        }
예제 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public VoteState unmarshal0(org.neo4j.storageengine.api.ReadableChannel channel) throws java.io.IOException, org.neo4j.causalclustering.messaging.EndOfStreamException
            public override VoteState Unmarshal0(ReadableChannel channel)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long term = channel.getLong();
                long term = channel.Long;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId member = memberMarshal.unmarshal(channel);
                MemberId member = MemberMarshal.unmarshal(channel);

                return(new VoteState(member, term));
            }
예제 #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public GlobalSessionTrackerState unmarshal0(org.neo4j.storageengine.api.ReadableChannel channel) throws java.io.IOException, org.neo4j.causalclustering.messaging.EndOfStreamException
            public override GlobalSessionTrackerState Unmarshal0(ReadableChannel channel)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long logIndex = channel.getLong();
                long logIndex = channel.Long;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int sessionTrackerSize = channel.getInt();
                int sessionTrackerSize = channel.Int;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Map<org.neo4j.causalclustering.identity.MemberId, LocalSessionTracker> sessionTrackers = new java.util.HashMap<>();
                IDictionary <MemberId, LocalSessionTracker> sessionTrackers = new Dictionary <MemberId, LocalSessionTracker>();

                for (int i = 0; i < sessionTrackerSize; i++)
                {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.identity.MemberId member = memberMarshal.unmarshal(channel);
                    MemberId member = MemberMarshal.unmarshal(channel);
                    if (member == null)
                    {
                        throw new System.InvalidOperationException("Null member");
                    }

                    long        mostSigBits     = channel.Long;
                    long        leastSigBits    = channel.Long;
                    System.Guid globalSessionId = new System.Guid(mostSigBits, leastSigBits);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int localSessionTrackerSize = channel.getInt();
                    int localSessionTrackerSize = channel.Int;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Map<long, long> lastSequenceNumberPerSession = new java.util.HashMap<>();
                    IDictionary <long, long> lastSequenceNumberPerSession = new Dictionary <long, long>();
                    for (int j = 0; j < localSessionTrackerSize; j++)
                    {
                        long localSessionId = channel.Long;
                        long sequenceNumber = channel.Long;
                        lastSequenceNumberPerSession[localSessionId] = sequenceNumber;
                    }
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final LocalSessionTracker localSessionTracker = new LocalSessionTracker(globalSessionId, lastSequenceNumberPerSession);
                    LocalSessionTracker localSessionTracker = new LocalSessionTracker(globalSessionId, lastSequenceNumberPerSession);
                    sessionTrackers[member] = localSessionTracker;
                }
                GlobalSessionTrackerState result = new GlobalSessionTrackerState();

                result.sessionTrackers = sessionTrackers;
                result.logIndex        = logIndex;
                return(result);
            }
예제 #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public T readState() throws java.io.IOException
        public override T ReadState()
        {
            try
            {
                using (ReadableClosableChannel channel = new ReadAheadChannel <>(_fileSystem.open(_file, OpenMode.READ)))
                {
                    return(_marshal.unmarshal(channel));
                }
            }
            catch (EndOfStreamException e)
            {
                _log.error("End of stream reached: " + _file);
                throw new IOException(e);
            }
        }
예제 #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertMarshalingEquality(io.netty.buffer.ByteBuf buffer, ReplicatedContent replicatedTx) throws java.io.IOException, org.neo4j.causalclustering.messaging.EndOfStreamException
        private void AssertMarshalingEquality(ByteBuf buffer, ReplicatedContent replicatedTx)
        {
            _marshal.marshal(replicatedTx, new NetworkWritableChannel(buffer));

            assertThat(_marshal.unmarshal(new NetworkReadableClosableChannelNetty4(buffer)), equalTo(replicatedTx));
        }
예제 #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf buffer, java.util.List<Object> list) throws Exception
        public override void Decode(ChannelHandlerContext ctx, ByteBuf buffer, IList <object> list)
        {
            ReadableChannel channel   = new NetworkReadableClosableChannelNetty4(buffer);
            ClusterId       clusterId = ClusterId.Marshal.INSTANCE.unmarshal(channel);

            int messageTypeWire = channel.Int;

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_Type[] values      = Enum.GetValues(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_Type));
            Org.Neo4j.causalclustering.core.consensus.RaftMessages_Type   messageType = values[messageTypeWire];

            MemberId from = RetrieveMember(channel);

            Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage result;

            if (messageType.Equals(VOTE_REQUEST))
            {
                MemberId candidate = RetrieveMember(channel);

                long term         = channel.Long;
                long lastLogIndex = channel.Long;
                long lastLogTerm  = channel.Long;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Request(from, term, candidate, lastLogIndex, lastLogTerm);
            }
            else if (messageType.Equals(VOTE_RESPONSE))
            {
                long term        = channel.Long;
                bool voteGranted = channel.Get() == 1;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Vote_Response(from, term, voteGranted);
            }
            else if (messageType.Equals(PRE_VOTE_REQUEST))
            {
                MemberId candidate = RetrieveMember(channel);

                long term         = channel.Long;
                long lastLogIndex = channel.Long;
                long lastLogTerm  = channel.Long;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_PreVote_Request(from, term, candidate, lastLogIndex, lastLogTerm);
            }
            else if (messageType.Equals(PRE_VOTE_RESPONSE))
            {
                long term        = channel.Long;
                bool voteGranted = channel.Get() == 1;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_PreVote_Response(from, term, voteGranted);
            }
            else if (messageType.Equals(APPEND_ENTRIES_REQUEST))
            {
                // how many
                long term         = channel.Long;
                long prevLogIndex = channel.Long;
                long prevLogTerm  = channel.Long;

                long leaderCommit = channel.Long;
                long count        = channel.Long;

                RaftLogEntry[] entries = new RaftLogEntry[( int )count];
                for (int i = 0; i < count; i++)
                {
                    long entryTerm = channel.Long;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.core.replication.ReplicatedContent content = marshal.unmarshal(channel);
                    ReplicatedContent content = _marshal.unmarshal(channel);
                    entries[i] = new RaftLogEntry(entryTerm, content);
                }

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request(from, term, prevLogIndex, prevLogTerm, entries, leaderCommit);
            }
            else if (messageType.Equals(APPEND_ENTRIES_RESPONSE))
            {
                long term        = channel.Long;
                bool success     = channel.Get() == 1;
                long matchIndex  = channel.Long;
                long appendIndex = channel.Long;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response(from, term, success, matchIndex, appendIndex);
            }
            else if (messageType.Equals(NEW_ENTRY_REQUEST))
            {
                ReplicatedContent content = _marshal.unmarshal(channel);

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_Request(from, content);
            }
            else if (messageType.Equals(HEARTBEAT))
            {
                long leaderTerm      = channel.Long;
                long commitIndexTerm = channel.Long;
                long commitIndex     = channel.Long;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat(from, leaderTerm, commitIndex, commitIndexTerm);
            }
            else if (messageType.Equals(HEARTBEAT_RESPONSE))
            {
                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_HeartbeatResponse(from);
            }
            else if (messageType.Equals(LOG_COMPACTION_INFO))
            {
                long leaderTerm = channel.Long;
                long prevIndex  = channel.Long;

                result = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo(from, leaderTerm, prevIndex);
            }
            else
            {
                throw new System.ArgumentException("Unknown message type");
            }

            list.Add(Org.Neo4j.causalclustering.core.consensus.RaftMessages_ReceivedInstantClusterIdAwareMessage.of(_clock.instant(), clusterId, result));
        }