Exemplo n.º 1
0
        /// <summary>
        /// Sets up the supporting infrastructure and communication hooks for our state machines. This is here to support
        /// an external requirement for assembling protocol servers given an existing set of state machines (used to prove
        /// correctness).
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("rawtypes") public ProtocolServer constructSupportingInfrastructureFor(InstanceId me, org.neo4j.cluster.com.message.MessageSource input, org.neo4j.cluster.com.message.MessageSender output, DelayedDirectExecutor executor, org.neo4j.cluster.timeout.Timeouts timeouts, java.util.concurrent.Executor stateMachineExecutor, final org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext context, org.neo4j.cluster.statemachine.StateMachine[] machines)
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        public virtual ProtocolServer ConstructSupportingInfrastructureFor(InstanceId me, MessageSource input, MessageSender output, DelayedDirectExecutor executor, Timeouts timeouts, Executor stateMachineExecutor, MultiPaxosContext context, StateMachine[] machines)
        {
            StateMachines stateMachines = new StateMachines(_logging, _stateMachinesMonitor, input, output, timeouts, executor, stateMachineExecutor, me);

            foreach (StateMachine machine in machines)
            {
                stateMachines.AddStateMachine(machine);
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ProtocolServer server = new ProtocolServer(me, stateMachines, logging);
            ProtocolServer server = new ProtocolServer(me, stateMachines, _logging);

            server.AddBindingListener(me1 => context.ClusterContext.setBoundAt(me1));

            stateMachines.AddMessageProcessor(new HeartbeatRefreshProcessor(stateMachines.Outgoing, context.ClusterContext));
            input.AddMessageProcessor(new HeartbeatIAmAliveProcessor(stateMachines.Outgoing, context.ClusterContext));

            Cluster cluster = server.NewClient(typeof(Cluster));

            cluster.AddClusterListener(new HeartbeatJoinListener(stateMachines.Outgoing));
            cluster.AddClusterListener(new HeartbeatLeftListener(context.HeartbeatContext, _logging));

            context.HeartbeatContext.addHeartbeatListener(new HeartbeatReelectionListener(server.NewClient(typeof(Election)), _logging));
            context.ClusterContext.addClusterListener(new ClusterLeaveReelectionListener(server.NewClient(typeof(Election)), _logging));

            StateMachineRules rules = (new StateMachineRules(stateMachines.Outgoing)).rule(ClusterState.start, ClusterMessage.create, ClusterState.entered, @internal(AtomicBroadcastMessage.entered), @internal(ProposerMessage.join), @internal(AcceptorMessage.join), @internal(LearnerMessage.join), @internal(HeartbeatMessage.join), @internal(ElectionMessage.created), @internal(SnapshotMessage.join)).rule(ClusterState.discovery, ClusterMessage.configurationResponse, ClusterState.joining, @internal(AcceptorMessage.join), @internal(LearnerMessage.join), @internal(AtomicBroadcastMessage.join)).rule(ClusterState.discovery, ClusterMessage.configurationResponse, ClusterState.entered, @internal(AtomicBroadcastMessage.entered), @internal(ProposerMessage.join), @internal(AcceptorMessage.join), @internal(LearnerMessage.join), @internal(HeartbeatMessage.join), @internal(ElectionMessage.join), @internal(SnapshotMessage.join)).rule(ClusterState.joining, ClusterMessage.configurationChanged, ClusterState.entered, @internal(AtomicBroadcastMessage.entered), @internal(ProposerMessage.join), @internal(AcceptorMessage.join), @internal(LearnerMessage.join), @internal(HeartbeatMessage.join), @internal(ElectionMessage.join), @internal(SnapshotMessage.join)).rule(ClusterState.joining, ClusterMessage.joinFailure, ClusterState.start, @internal(AtomicBroadcastMessage.leave), @internal(AcceptorMessage.leave), @internal(LearnerMessage.leave), @internal(ProposerMessage.leave)).rule(ClusterState.entered, ClusterMessage.leave, ClusterState.start, @internal(AtomicBroadcastMessage.leave), @internal(AcceptorMessage.leave), @internal(LearnerMessage.leave), @internal(HeartbeatMessage.leave), @internal(SnapshotMessage.leave), @internal(ElectionMessage.leave), @internal(ProposerMessage.leave)).rule(ClusterState.entered, ClusterMessage.leave, ClusterState.start, @internal(AtomicBroadcastMessage.leave), @internal(AcceptorMessage.leave), @internal(LearnerMessage.leave), @internal(HeartbeatMessage.leave), @internal(ElectionMessage.leave), @internal(SnapshotMessage.leave), @internal(ProposerMessage.leave)).rule(ClusterState.leaving, ClusterMessage.configurationChanged, ClusterState.start, @internal(AtomicBroadcastMessage.leave), @internal(AcceptorMessage.leave), @internal(LearnerMessage.leave), @internal(HeartbeatMessage.leave), @internal(ElectionMessage.leave), @internal(SnapshotMessage.leave), @internal(ProposerMessage.leave)).rule(ClusterState.leaving, ClusterMessage.leaveTimedout, ClusterState.start, @internal(AtomicBroadcastMessage.leave), @internal(AcceptorMessage.leave), @internal(LearnerMessage.leave), @internal(HeartbeatMessage.leave), @internal(ElectionMessage.leave), @internal(SnapshotMessage.leave), @internal(ProposerMessage.leave));

            stateMachines.AddStateTransitionListener(rules);

            return(server);
        }
Exemplo n.º 2
0
        public ProtocolServer(InstanceId me, StateMachines stateMachines, LogProvider logProvider)
        {
            this._me = me;
            this.StateMachinesConflict = stateMachines;
            this._msgLog = logProvider.getLog(this.GetType());

            StateMachineConversations conversations = new StateMachineConversations(me);

            ProxyFactory = new StateMachineProxyFactory(stateMachines, conversations, me, logProvider);
            stateMachines.AddMessageProcessor(ProxyFactory);
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAlwaysAddItsInstanceIdToOutgoingMessages()
        public virtual void ShouldAlwaysAddItsInstanceIdToOutgoingMessages()
        {
            InstanceId me = new InstanceId(42);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<org.neo4j.cluster.com.message.Message> sentOut = new java.util.LinkedList<>();
            IList <Message> sentOut = new LinkedList <Message>();

            /*
             * Lots of setup required. Must have a sender that keeps messages so we can see what the machine sent out.
             * We must have the StateMachines actually delegate the incoming message and retrieve the generated outgoing.
             * That means we need an actual StateMachine with a registered MessageType. And most of those are void
             * methods, which means lots of Answer objects.
             */
            // Given
            MessageSender sender = mock(typeof(MessageSender));

            // The sender, which adds messages outgoing to the list above.
            doAnswer(invocation =>
            {
                ((IList <Org.Neo4j.cluster.com.message.Message>)sentOut).AddRange(invocation.getArgument(0));
                return(null);
            }).when(sender).process(ArgumentMatchers.any <IList <Message <? extends MessageType> > >());

            StateMachines stateMachines = new StateMachines(NullLogProvider.Instance, mock(typeof(StateMachines.Monitor)), mock(typeof(MessageSource)), sender, mock(typeof(Timeouts)), mock(typeof(DelayedDirectExecutor)), ThreadStart.run, me);

            // The state machine, which has a TestMessage message type and simply adds a HEADER_TO header to the messages it
            // is handed to handle.
            StateMachine machine = mock(typeof(StateMachine));

            when(machine.MessageType).then((Answer <object>)invocation => typeof(TestMessage));
            doAnswer(invocation =>
            {
                Message message      = invocation.getArgument(0);
                MessageHolder holder = invocation.getArgument(1);
                message.setHeader(Message.HEADER_TO, "to://neverland");
                holder.offer(message);
                return(null);
            }).when(machine).handle(any(typeof(Message)), any(typeof(MessageHolder)));
            stateMachines.AddStateMachine(machine);

            // When
            stateMachines.Process(Message.@internal(TestMessage.Message1));

            // Then
            assertEquals("StateMachines should not make up messages from thin air", 1, sentOut.Count);
            Message sent = sentOut[0];

            assertTrue("StateMachines should add the instance-id header", sent.hasHeader(Message.HEADER_INSTANCE_ID));
            assertEquals("StateMachines should add instance-id header that has the correct value", me.ToString(), sent.getHeader(Message.HEADER_INSTANCE_ID));
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") public ProtocolServer newProtocolServer(InstanceId me, org.neo4j.cluster.com.message.MessageSource input, org.neo4j.cluster.com.message.MessageSender output, java.util.concurrent.Executor stateMachineExecutor, DelayedDirectExecutor executor, org.neo4j.cluster.timeout.Timeouts timeouts, org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext context, org.neo4j.cluster.protocol.snapshot.SnapshotContext snapshotContext)
        public virtual ProtocolServer NewProtocolServer(InstanceId me, MessageSource input, MessageSender output, Executor stateMachineExecutor, DelayedDirectExecutor executor, Timeouts timeouts, MultiPaxosContext context, SnapshotContext snapshotContext)
        {
            return(ConstructSupportingInfrastructureFor(me, input, output, executor, timeouts, stateMachineExecutor, context, new StateMachine[]
            {
                new StateMachine(context.AtomicBroadcastContext, typeof(AtomicBroadcastMessage), AtomicBroadcastState.start, _logging),
                new StateMachine(context.AcceptorContext, typeof(AcceptorMessage), AcceptorState.start, _logging),
                new StateMachine(context.ProposerContext, typeof(ProposerMessage), ProposerState.start, _logging),
                new StateMachine(context.LearnerContext, typeof(LearnerMessage), LearnerState.start, _logging),
                new StateMachine(context.HeartbeatContext, typeof(HeartbeatMessage), HeartbeatState.start, _logging),
                new StateMachine(context.ElectionContext, typeof(ElectionMessage), ElectionState.start, _logging),
                new StateMachine(snapshotContext, typeof(SnapshotMessage), SnapshotState.start, _logging),
                new StateMachine(context.ClusterContext, typeof(ClusterMessage), ClusterState.start, _logging)
            }));
        }
Exemplo n.º 5
0
        public override ProtocolServer NewProtocolServer(InstanceId me, TimeoutStrategy timeoutStrategy, MessageSource input, MessageSender output, AcceptorInstanceStore acceptorInstanceStore, ElectionCredentialsProvider electionCredentialsProvider, Executor stateMachineExecutor, ObjectInputStreamFactory objectInputStreamFactory, ObjectOutputStreamFactory objectOutputStreamFactory, Config config)
        {
            DelayedDirectExecutor executor = new DelayedDirectExecutor(_logging);

            // Create state machines
            Timeouts timeouts = new Timeouts(timeoutStrategy);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext context = new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext(me, org.neo4j.helpers.collection.Iterables.iterable(new org.neo4j.cluster.protocol.election.ElectionRole(org.neo4j.cluster.protocol.cluster.ClusterConfiguration.COORDINATOR)), new org.neo4j.cluster.protocol.cluster.ClusterConfiguration(initialConfig.getName(), logging, initialConfig.getMemberURIs()), executor, logging, objectInputStreamFactory, objectOutputStreamFactory, acceptorInstanceStore, timeouts, electionCredentialsProvider, config);
            MultiPaxosContext context = new MultiPaxosContext(me, Iterables.iterable(new ElectionRole(ClusterConfiguration.COORDINATOR)), new ClusterConfiguration(_initialConfig.Name, _logging, _initialConfig.MemberURIs), executor, _logging, objectInputStreamFactory, objectOutputStreamFactory, acceptorInstanceStore, timeouts, electionCredentialsProvider, config);

            SnapshotContext snapshotContext = new SnapshotContext(context.ClusterContext, context.LearnerContext);

            return(NewProtocolServer(me, input, output, stateMachineExecutor, executor, timeouts, context, snapshotContext));
        }
Exemplo n.º 6
0
        public TestProtocolServer(LogProvider logProvider, TimeoutStrategy timeoutStrategy, ProtocolServerFactory factory, URI serverUri, InstanceId instanceId, AcceptorInstanceStore acceptorInstanceStore, ElectionCredentialsProvider electionCredentialsProvider)
        {
            this._serverUri = serverUri;
            this.Receiver   = new TestMessageSource(this);
            this.Sender     = new TestMessageSender(this);

            _stateMachineExecutor = new DelayedDirectExecutor(logProvider);

            Config config = mock(typeof(Config));

            when(config.Get(ClusterSettings.MaxAcceptors)).thenReturn(10);
            when(config.Get(ClusterSettings.StrictInitialHosts)).thenReturn(false);

            ServerConflict = factory.NewProtocolServer(instanceId, timeoutStrategy, Receiver, Sender, acceptorInstanceStore, electionCredentialsProvider, _stateMachineExecutor, new ObjectStreamFactory(), new ObjectStreamFactory(), config);

            ServerConflict.listeningAt(serverUri);
        }
Exemplo n.º 7
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public StateMachines(org.neo4j.logging.LogProvider logProvider, Monitor monitor, org.neo4j.cluster.com.message.MessageSource source, final org.neo4j.cluster.com.message.MessageSender sender, org.neo4j.cluster.timeout.Timeouts timeouts, DelayedDirectExecutor executor, java.util.concurrent.Executor stateMachineExecutor, InstanceId instanceId)
        public StateMachines(LogProvider logProvider, Monitor monitor, MessageSource source, MessageSender sender, Timeouts timeouts, DelayedDirectExecutor executor, Executor stateMachineExecutor, InstanceId instanceId)
        {
            this._log                   = logProvider.getLog(this.GetType());
            this._monitor               = monitor;
            this._sender                = sender;
            this._executor              = executor;
            this._stateMachineExecutor  = stateMachineExecutor;
            this._timeouts              = timeouts;
            this._instanceIdHeaderValue = instanceId.ToString();

            _outgoing = new OutgoingMessageHolder(this);
            timeouts.AddMessageProcessor(this);
            source.AddMessageProcessor(this);
        }