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;
}
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;
}
Aggregations