@Override
public void run() {
// Instantiate the replication data server.
final SequenceServer server = new SequenceServer(port, new ReplicationDataServerChannelPipelineFactory(
dataDirectory));
// Configure a listener to send sequence number events from the
// client to the server.
SequenceNumberClientListener numberListener = new SequenceNumberClientListener() {
@Override
public void notifySequenceNumber(long sequenceNumber) {
server.update(sequenceNumber);
}
};
// Create a sequence client restart manager so that our sequence
// client continues processing in the face of temporary connectivity
// issues.
SequenceClientRestartManager clientRestartManager = new SequenceClientRestartManager();
// Create the client for receiving updated sequence numbers..
SequenceNumberClientChannelPipelineFactory channelPipelineFactory =
new SequenceNumberClientChannelPipelineFactory(
clientRestartManager.getControl(), numberListener, "localhost");
SequenceClient client = new SequenceClient(new InetSocketAddress(notificationPort), channelPipelineFactory);
try {
// Start the server with the current replication number.
server.start(getCurrentSequenceNumber());
// Update the port. It may have been allocated dynamically if the
// port was specified as 0.
port = server.getPort();
// Run the client and perform restarts if it fails. This call will
// block.
clientRestartManager.manageClient(client);
} finally {
server.stop();
}
}