// Le server object. This is where all the magic happens.
final ServerStatus serverStatus = injector.getInstance(ServerStatus.class);
serverStatus.initialize();
ActivityWriter activityWriter = null;
ServiceManager serviceManager = null;
try {
activityWriter = injector.getInstance(ActivityWriter.class);
serviceManager = injector.getInstance(ServiceManager.class);
} catch (ProvisionException e) {
for (Message message : e.getErrorMessages()) {
if (message.getCause() instanceof MongoException) {
LOG.error(UI.wallString("Unable to connect to MongoDB. Is it running and the configuration correct?"));
System.exit(-1);
}
}
LOG.error("Guice error", e);
System.exit(-1);
} catch (Exception e) {
LOG.error("Unexpected exception", e);
System.exit(-1);
}
final ActivityWriter finalActivityWriter = activityWriter;
final ServiceManager finalServiceManager = serviceManager;
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
String msg = "SIGNAL received. Shutting down.";
LOG.info(msg);
finalActivityWriter.write(new Activity(msg, Main.class));
GracefulShutdown shutdown = injector.getInstance(GracefulShutdown.class);
shutdown.runWithoutExit();
finalServiceManager.stopAsync().awaitStopped();
}
});
// Register this node.
final NodeService nodeService = injector.getInstance(NodeService.class);