Source:
<code>public void invokeCallbackMethods() { initCommandExecutor(); Iterator<Entry<Guid, CommandContainer>> iterator = cmdCallbackMap.entrySet().iterator(); while (iterator.hasNext()) { Entry<Guid, CommandContainer> entry = iterator.next(); if ((entry.getValue().remainingDelay -= pollingRate) > 0) { continue; } Guid cmdId = entry.getKey(); CommandCallback callback = entry.getValue().callback; CommandStatus status = coco.getCommandStatus(cmdId); boolean errorInCallback = false; try { switch (status) { case FAILED: callback.onFailed(cmdId, coco.getChildCommandIds(cmdId)); break; case SUCCEEDED: callback.onSucceeded(cmdId, coco.getChildCommandIds(cmdId)); break; case ACTIVE: if (coco.getCommandEntity(cmdId).isExecuted()) { callback.doPolling(cmdId, coco.getChildCommandIds(cmdId)); } break; default: break; } } catch (Exception ex) { errorInCallback = true; handleError(ex, status, cmdId); } finally { if (CommandStatus.FAILED.equals(status) || (CommandStatus.SUCCEEDED.equals(status) && !errorInCallback)) { coco.updateCallbackNotified(cmdId); iterator.remove(); CommandEntity cmdEntity = coco.getCommandEntity(entry.getKey()); if (cmdEntity != null) { Guid rootCommandId = cmdEntity.getRootCommandId(); if (!Guid.isNullOrEmpty(rootCommandId) && cmdCallbackMap.containsKey(rootCommandId)) { cmdCallbackMap.get(rootCommandId).initialDelay = pollingRate; cmdCallbackMap.get(rootCommandId).remainingDelay = pollingRate; } } } else if (status != coco.getCommandStatus(cmdId)) { entry.getValue().initialDelay = pollingRate; entry.getValue().remainingDelay = pollingRate; } else { int maxDelay = Config.<Integer>getValue(ConfigValues.AsyncCommandPollingRateInSeconds); entry.getValue().initialDelay = Math.min(maxDelay, entry.getValue().initialDelay * 2); entry.getValue().remainingDelay = entry.getValue().initialDelay; } } <START> } <END> if (!cmdCallbackMap.isEmpty()) { markExpiredCommandsAsFailure(); } }</code><technical_language>this processing callbacks avoid terminating on-going command do processing ? selected list of callback active one</technical_language>

Target:
public void invokeCallbackMethods() { initCommandExecutor(); if (!cmdCallbackMap.isEmpty()) { markExpiredCommandsAsFailure(); } Iterator<Entry<Guid, CommandContainer>> iterator = cmdCallbackMap.entrySet().iterator(); while (iterator.hasNext()) { Entry<Guid, CommandContainer> entry = iterator.next(); if ((entry.getValue().remainingDelay -= pollingRate) > 0) { continue; } Guid cmdId = entry.getKey(); CommandCallback callback = entry.getValue().callback; CommandStatus status = coco.getCommandStatus(cmdId); boolean errorInCallback = false; try { switch (status) { case FAILED: callback.onFailed(cmdId, coco.getChildCommandIds(cmdId)); break; case SUCCEEDED: callback.onSucceeded(cmdId, coco.getChildCommandIds(cmdId)); break; case ACTIVE: if (coco.getCommandEntity(cmdId).isExecuted()) { callback.doPolling(cmdId, coco.getChildCommandIds(cmdId)); } break; default: break; } } catch (Exception ex) { errorInCallback = true; handleError(ex, status, cmdId); } finally { if (CommandStatus.FAILED.equals(status) || (CommandStatus.SUCCEEDED.equals(status) && !errorInCallback)) { coco.updateCallbackNotified(cmdId); iterator.remove(); CommandEntity cmdEntity = coco.getCommandEntity(entry.getKey()); if (cmdEntity != null) { Guid rootCommandId = cmdEntity.getRootCommandId(); if (!Guid.isNullOrEmpty(rootCommandId) && cmdCallbackMap.containsKey(rootCommandId)) { cmdCallbackMap.get(rootCommandId).initialDelay = pollingRate; cmdCallbackMap.get(rootCommandId).remainingDelay = pollingRate; } } } else if (status != coco.getCommandStatus(cmdId)) { entry.getValue().initialDelay = pollingRate; entry.getValue().remainingDelay = pollingRate; } else { int maxDelay = Config.<Integer>getValue(ConfigValues.AsyncCommandPollingRateInSeconds); entry.getValue().initialDelay = Math.min(maxDelay, entry.getValue().initialDelay * 2); entry.getValue().remainingDelay = entry.getValue().initialDelay; } } } }