Search in sources :

Example 1 with StateTransitionLogger

use of org.neo4j.cluster.statemachine.StateTransitionLogger in project neo4j by neo4j.

the class NetworkMock method newTestProtocolServer.

protected TestProtocolServer newTestProtocolServer(int serverId, URI serverUri) {
    ProtocolServerFactory protocolServerFactory = new MultiPaxosServerFactory(new ClusterConfiguration("default", logService.getInternalLogProvider()), logService.getInternalLogProvider(), monitors.newMonitor(StateMachines.Monitor.class));
    ServerIdElectionCredentialsProvider electionCredentialsProvider = new ServerIdElectionCredentialsProvider();
    electionCredentialsProvider.listeningAt(serverUri);
    TestProtocolServer protocolServer = new TestProtocolServer(logService.getInternalLogProvider(), timeoutStrategy, protocolServerFactory, serverUri, new InstanceId(serverId), new InMemoryAcceptorInstanceStore(), electionCredentialsProvider);
    protocolServer.addStateTransitionListener(new StateTransitionLogger(logService.getInternalLogProvider(), new AtomicBroadcastSerializer(new ObjectStreamFactory(), new ObjectStreamFactory())));
    return protocolServer;
}
Also used : AtomicBroadcastSerializer(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer) StateTransitionLogger(org.neo4j.cluster.statemachine.StateTransitionLogger) ServerIdElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ServerIdElectionCredentialsProvider) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) InMemoryAcceptorInstanceStore(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InMemoryAcceptorInstanceStore) ObjectStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory)

Example 2 with StateTransitionLogger

use of org.neo4j.cluster.statemachine.StateTransitionLogger in project neo4j by neo4j.

the class NetworkedServerFactory method newNetworkedServer.

public ProtocolServer newNetworkedServer(final Config config, AcceptorInstanceStore acceptorInstanceStore, ElectionCredentialsProvider electionCredentialsProvider) {
    final NetworkReceiver receiver = new NetworkReceiver(networkReceiverMonitor, new NetworkReceiver.Configuration() {

        @Override
        public HostnamePort clusterServer() {
            return config.get(ClusterSettings.cluster_server);
        }

        @Override
        public int defaultPort() {
            return 5001;
        }

        @Override
        public String name() {
            return null;
        }
    }, logProvider);
    final NetworkSender sender = new NetworkSender(networkSenderMonitor, new NetworkSender.Configuration() {

        @Override
        public int defaultPort() {
            return 5001;
        }

        @Override
        public int port() {
            return config.get(ClusterSettings.cluster_server).getPort();
        }
    }, receiver, logProvider);
    ExecutorLifecycleAdapter stateMachineExecutor = new ExecutorLifecycleAdapter(() -> Executors.newSingleThreadExecutor(new NamedThreadFactory("State machine", namedThreadFactoryMonitor)));
    final ProtocolServer protocolServer = protocolServerFactory.newProtocolServer(config.get(ClusterSettings.server_id), timeoutStrategy, receiver, sender, acceptorInstanceStore, electionCredentialsProvider, stateMachineExecutor, objectInputStreamFactory, objectOutputStreamFactory, config);
    receiver.addNetworkChannelsListener(new NetworkReceiver.NetworkChannelsListener() {

        private StateTransitionLogger logger;

        @Override
        public void listeningAt(URI me) {
            protocolServer.listeningAt(me);
            if (logger == null) {
                logger = new StateTransitionLogger(logProvider, new AtomicBroadcastSerializer(objectInputStreamFactory, objectOutputStreamFactory));
                protocolServer.addStateTransitionListener(logger);
            }
        }

        @Override
        public void channelOpened(URI to) {
        }

        @Override
        public void channelClosed(URI to) {
        }
    });
    life.add(stateMachineExecutor);
    // Timeout timer - triggers every 10 ms
    life.add(new Lifecycle() {

        private ScheduledExecutorService scheduler;

        @Override
        public void init() throws Throwable {
            protocolServer.getTimeouts().tick(System.currentTimeMillis());
        }

        @Override
        public void start() throws Throwable {
            scheduler = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("timeout"));
            scheduler.scheduleWithFixedDelay(new Runnable() {

                @Override
                public void run() {
                    long now = System.currentTimeMillis();
                    protocolServer.getTimeouts().tick(now);
                }
            }, 0, 10, TimeUnit.MILLISECONDS);
        }

        @Override
        public void stop() throws Throwable {
            scheduler.shutdownNow();
        }

        @Override
        public void shutdown() throws Throwable {
        }
    });
    // Add this last to ensure that timeout service is setup first
    life.add(sender);
    life.add(receiver);
    return protocolServer;
}
Also used : AtomicBroadcastSerializer(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NamedThreadFactory(org.neo4j.helpers.NamedThreadFactory) HostnamePort(org.neo4j.helpers.HostnamePort) Lifecycle(org.neo4j.kernel.lifecycle.Lifecycle) URI(java.net.URI) NetworkReceiver(org.neo4j.cluster.com.NetworkReceiver) StateTransitionLogger(org.neo4j.cluster.statemachine.StateTransitionLogger) NetworkSender(org.neo4j.cluster.com.NetworkSender)

Aggregations

AtomicBroadcastSerializer (org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer)2 StateTransitionLogger (org.neo4j.cluster.statemachine.StateTransitionLogger)2 URI (java.net.URI)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 NetworkReceiver (org.neo4j.cluster.com.NetworkReceiver)1 NetworkSender (org.neo4j.cluster.com.NetworkSender)1 ObjectStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory)1 InMemoryAcceptorInstanceStore (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InMemoryAcceptorInstanceStore)1 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)1 ServerIdElectionCredentialsProvider (org.neo4j.cluster.protocol.election.ServerIdElectionCredentialsProvider)1 HostnamePort (org.neo4j.helpers.HostnamePort)1 NamedThreadFactory (org.neo4j.helpers.NamedThreadFactory)1 Lifecycle (org.neo4j.kernel.lifecycle.Lifecycle)1