public static void main(final String[] args) {
// Bootstrap logging system
PropertyConfigurator.configure(getBootstrapLoggingProperties());
final Injector injector = ClientGuiceModule.getInjector();
final ShutdownManager shutdownManager = injector.getInstance(ShutdownManager.class);
// Add shutdown hook to call shutdown if control c or OS SIGTERM is received.
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
shutdownManager.shutdownAll();
}
});
// Starts the client in a loop that exponentially backs off.
while (true) {
try {
// Only try to back-off if we have unsuccessful connections.
if (unsuccessfulAttempts > 0) {
long backOffTime = (long) Math.min(
MAX_BACKOFF_TIME, Math.pow(2, unsuccessfulAttempts) * 1000L);
try {
// Sleep for the amount of time needed.
Thread.sleep(backOffTime);
} catch (InterruptedException e) {
LOG.error("Interrupted while trying to exponentially back off. Exiting.");
break;
}
LOG.info("Starting agent after " + unsuccessfulAttempts + " unsuccessful attempts." +
" Next connect in " + backOffTime + " milliseconds.");
} else if (unsuccessfulAttempts == -1) {
// We are being told to quit probably because we were only configured to start once.
break;
}
injector.getInstance(Client.class).parseFlagsValidateAndConnect(args);
} catch (Exception e) { // This is an outside server loop. Catch everything.
LOG.error("Agent died.", e);
shutdownManager.shutdownAll();
}
}
}