// looking for nodes and check if exist
Set<Node> recipientList = new HashSet<Node>();
if (nodeIds != null && !nodeIds.isEmpty()) {
for (String nodeId : nodeIds) {
Node node = clusterManager.findNodeById(nodeId);
if (node == null) {
System.err.println("Cluster node " + nodeId + " doesn't exist");
} else {
recipientList.add(node);
}
}
} else {
if (status == null) {
// in case of status display, select all nodes
recipientList = clusterManager.listNodes();
} else {
// in case of status change, select only the local node
recipientList.add(clusterManager.getNode());
}
}
if (recipientList.size() < 1) {
return null;
}
command.setDestination(recipientList);
command.setHandlerName(handlerName);
command.setStatus(status);
Map<Node, ManageHandlersResult> results = executionContext.execute(command);
if (results == null || results.isEmpty()) {
System.out.println("No result received within given timeout");
} else {
System.out.println(String.format(HEADER_FORMAT, "Node", "Status", "Event Handler"));
for (Map.Entry<Node,ManageHandlersResult> handlersResultEntry : results.entrySet()) {
Node node = handlersResultEntry.getKey();
String local = " ";
if (node.equals(clusterManager.getNode())) {
local = "*";
}
ManageHandlersResult result = handlersResultEntry.getValue();
if (result != null && result.getHandlers() != null) {
for (Map.Entry<String,String> handlerEntry: result.getHandlers().entrySet()) {
String handler = handlerEntry.getKey();
String s = handlerEntry.getValue();
System.out.println(String.format(OUTPUT_FORMAT, local, node.getId(), s, handler));
}
}
}
}
return null;