use of com.openmeap.util.ThrowableList in project OpenMEAP by OpenMEAP.
the class AbstractClusterServiceMgmtNotifier method notify.
public <E extends Event<T>> void notify(final E event, List<ProcessingEvent> events) throws ClusterNotificationException {
final ThrowableList exceptions = new ThrowableList();
onBeforeNotify(event);
final Map<String, Boolean> urlRequestCompleteStatus = new HashMap<String, Boolean>();
GlobalSettings globalSettings = modelManager.getGlobalSettings();
List<ClusterNode> clusterNodes = globalSettings.getClusterNodes();
for (ClusterNode thisNode : clusterNodes) {
URL thisUrl = null;
try {
thisUrl = new URL(thisNode.getServiceWebUrlPrefix());
} catch (MalformedURLException e) {
logger.error("Could not create URL object from " + thisNode.getServiceWebUrlPrefix() + ": {}", e);
continue;
}
if (executorService != null) {
logger.debug("Making request to {} using the executor.", thisUrl);
executorService.execute(new Runnable() {
URL url;
public void run() {
notifyMakeRequest(exceptions, url, urlRequestCompleteStatus, event);
}
Runnable setUrl(URL url) {
this.url = url;
return this;
}
}.setUrl(thisUrl));
} else {
logger.debug("Making request to {} serially.", thisUrl);
notifyMakeRequest(exceptions, thisUrl, urlRequestCompleteStatus, event);
}
}
// this set of if-else handles any exceptions in the list accumulated
if (executorService != null && executorTimeout != null) {
try {
// terminate, but make sure nothing is still waiting when we terminate
if (!executorService.awaitTermination(executorTimeout, TimeUnit.SECONDS)) {
executorService.shutdownNow();
List<String> waiting = new ArrayList<String>();
for (Map.Entry<String, Boolean> completed : urlRequestCompleteStatus.entrySet()) {
if (completed.getValue().equals(Boolean.FALSE)) {
waiting.add(completed.getKey());
}
}
logger.error("Blocking timed-out still waiting to notify: {}", StringUtils.join(waiting, ", "));
throw new ClusterNotificationException(String.format("Blocking timed-out still waiting to notify: %s", StringUtils.join(waiting, ", ")));
}
} catch (InterruptedException ie) {
throw new ClusterNotificationException("The notification thread was interrupted", ie);
}
} else if (exceptions.size() > 0) {
throw new ClusterNotificationException(String.format("The following exceptions were thrown: %s", exceptions.getMessages()));
}
onAfterNotify(event);
}
Aggregations