in src/main/java/com/revo/deployr/client/broker/engine/RBrokerEngine.java [664:767]
final public void run() {
while (taskBrokerIsActive.get()) {
int tasksHandledOnLoop = 0;
try {
while (liveTaskTokens.isEmpty() &&
taskBrokerIsActive.get()) {
try {
Thread.currentThread().sleep(
LIVE_TASK_TOKEN_PEEK_INTERVAL);
} catch (InterruptedException iex) {
}
}
for (RTaskToken rTaskToken : liveTaskTokens) {
boolean repeatTaskFound = false;
if (rTaskToken.isDone()) {
RTaskResult result = null;
try {
// Extract task result.
result =
(RTaskResult) rTaskToken.getResult();
if (taskListener != null) {
if (((RTaskResultImpl) result).repeatTask) {
repeatTaskFound = true;
} else {
try {
taskListener.onTaskCompleted(
rTaskToken.getTask(), result);
} catch (Exception ontcx) {
/*
* RBrokerEngine onTaskCompleted
* is * calling back into client
* application code. That code
* could erroneously throw an
* Exception back into
* RBrokerEngine. If so, swallow
* it.
*/
}
}
}
} catch (Exception ex) {
Throwable cause = ex;
if (ex instanceof ExecutionException)
cause = ex.getCause();
if (taskListener != null) {
try {
taskListener.onTaskError(
rTaskToken.getTask(), cause);
} catch (Exception ontex) {
/*
* RBrokerEngine onTaskError is
* calling back into client application
* code. That code could erroneously
* throw an Exception back into
* RBrokerEngine. If so, swallow it.
*/
}
}
}
liveTaskTokens.remove(rTaskToken);
if (!repeatTaskFound) {
tasksHandledOnLoop++;
updateBrokerStats(result);
}
}
}
} catch (Exception ex) {
if (brokerListener != null) {
brokerListener.onRuntimeError(ex);
}
}
if (tasksHandledOnLoop > 0) {
if (brokerListener != null) {
brokerListener.onRuntimeStats(buildStats(),
maxConcurrency());
}
}
} // while taskBrokerIsActive
}