use of com.cloud.utils.nio.NioClient in project cloudstack by apache.
the class Agent method reconnect.
protected void reconnect(final Link link) {
if (!_reconnectAllowed) {
return;
}
synchronized (this) {
if (_startup != null) {
_startup.cancel();
_startup = null;
}
}
link.close();
link.terminated();
setLink(null);
cancelTasks();
_resource.disconnected();
int inProgress = 0;
do {
_shell.getBackoffAlgorithm().waitBeforeRetry();
s_logger.info("Lost connection to the server. Dealing with the remaining commands...");
inProgress = _inProgress.get();
if (inProgress > 0) {
s_logger.info("Cannot connect because we still have " + inProgress + " commands in progress.");
}
} while (inProgress > 0);
_connection.stop();
try {
_connection.cleanUp();
} catch (final IOException e) {
s_logger.warn("Fail to clean up old connection. " + e);
}
while (_connection.isStartup()) {
_shell.getBackoffAlgorithm().waitBeforeRetry();
}
_connection = new NioClient("Agent", _shell.getHost(), _shell.getPort(), _shell.getWorkers(), this);
do {
s_logger.info("Reconnecting...");
try {
_connection.start();
} catch (final NioConnectionException e) {
s_logger.warn("NIO Connection Exception " + e);
s_logger.info("Attempted to connect to the server, but received an unexpected exception, trying again...");
}
_shell.getBackoffAlgorithm().waitBeforeRetry();
} while (!_connection.isStartup());
s_logger.info("Connected to the server");
}
Aggregations