ParticipantId participantId = ParticipantId.from(cliParser.getOptionValue("participantId"));
String participantClass = cliParser.getOptionValue("participantClass");
@SuppressWarnings("unchecked")
Class<? extends AbstractParticipantService> clazz =
(Class<? extends AbstractParticipantService>) Class.forName(participantClass);
final AbstractParticipantService containerParticipant =
clazz.getConstructor(HelixConnection.class, ClusterId.class, ParticipantId.class)
.newInstance(connection, clusterId, participantId);
containerParticipant.startAsync();
containerParticipant.awaitRunning(60, TimeUnit.SECONDS);
containerParticipant
.getParticipant()
.getMessagingService()
.registerMessageHandlerFactory(MessageType.SHUTDOWN.toString(),
new ShutdownMessageHandlerFactory(containerParticipant, connection));
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
LOG.info("Received a shutdown signal. Stopping participant");
containerParticipant.stopAsync();
containerParticipant.awaitTerminated();
connection.disconnect();
}
}) {
});