use of com.cloud.agent.Listener in project cloudstack by apache.
the class AgentManagerImpl method handleControlCommand.
private AgentControlAnswer handleControlCommand(final AgentAttache attache, final AgentControlCommand cmd) {
AgentControlAnswer answer = null;
for (final Pair<Integer, Listener> listener : _cmdMonitors) {
answer = listener.second().processControlCommand(attache.getId(), cmd);
if (answer != null) {
return answer;
}
}
s_logger.warn("No handling of agent control command: " + cmd + " sent from " + attache.getId());
return new AgentControlAnswer(cmd);
}
use of com.cloud.agent.Listener in project cloudstack by apache.
the class AgentAttache method processAnswers.
public boolean processAnswers(final long seq, final Response resp) {
resp.logD("Processing: ", true);
final Answer[] answers = resp.getAnswers();
boolean processed = false;
try {
Listener monitor = getListener(seq);
if (monitor == null) {
if (answers[0] != null && answers[0].getResult()) {
processed = true;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug(log(seq, "Unable to find listener."));
}
} else {
processed = monitor.processAnswers(_id, seq, answers);
if (s_logger.isTraceEnabled()) {
s_logger.trace(log(seq, (processed ? "" : " did not ") + " processed "));
}
if (!monitor.isRecurring()) {
unregisterListener(seq);
}
}
_agentMgr.notifyAnswersToMonitors(_id, seq, answers);
} finally {
// we should always trigger next command execution, even in failure cases - otherwise in exception case all the remaining will be stuck in the sync queue forever
if (resp.executeInSequence()) {
sendNext(seq);
}
}
return processed;
}
use of com.cloud.agent.Listener in project cloudstack by apache.
the class AgentAttache method cancelAllCommands.
protected void cancelAllCommands(final Status state, final boolean cancelActive) {
if (cancelActive) {
final Set<Map.Entry<Long, Listener>> entries = _waitForList.entrySet();
final Iterator<Map.Entry<Long, Listener>> it = entries.iterator();
while (it.hasNext()) {
final Map.Entry<Long, Listener> entry = it.next();
it.remove();
final Listener monitor = entry.getValue();
if (s_logger.isDebugEnabled()) {
s_logger.debug(log(entry.getKey(), "Sending disconnect to " + monitor.getClass()));
}
monitor.processDisconnect(_id, state);
}
}
}
use of com.cloud.agent.Listener in project cloudstack by apache.
the class AgentAttache method getNonRecurringListenersSize.
public int getNonRecurringListenersSize() {
List<Listener> nonRecurringListenersList = new ArrayList<Listener>();
if (_waitForList.isEmpty()) {
return 0;
} else {
final Set<Map.Entry<Long, Listener>> entries = _waitForList.entrySet();
final Iterator<Map.Entry<Long, Listener>> it = entries.iterator();
while (it.hasNext()) {
final Map.Entry<Long, Listener> entry = it.next();
final Listener monitor = entry.getValue();
if (!monitor.isRecurring()) {
//TODO - remove this debug statement later
s_logger.debug("Listener is " + entry.getValue() + " waiting on " + entry.getKey());
nonRecurringListenersList.add(monitor);
}
}
}
return nonRecurringListenersList.size();
}
use of com.cloud.agent.Listener in project cloudstack by apache.
the class AgentAttache method cancel.
protected synchronized void cancel(final long seq) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(log(seq, "Cancelling."));
}
final Listener listener = _waitForList.remove(seq);
if (listener != null) {
listener.processDisconnect(_id, Status.Disconnected);
}
int index = findRequest(seq);
if (index >= 0) {
_requests.remove(index);
}
}
Aggregations