}
@Override
public void writeResponse(ManagementCenterService mcs, JsonObject root) throws Exception {
final JsonObject jsonResult = new JsonObject();
ArrayList results;
if (targetAllMembers) {
final Set<Member> members = mcs.getHazelcastInstance().getCluster().getMembers();
final ArrayList list = new ArrayList(members.size());
for (Member member : members) {
list.add(mcs.callOnMember(member, new ScriptExecutorOperation(engine, script, bindings)));
}
results = list;
} else {
final ArrayList list = new ArrayList(targets.size());
for (String address : targets) {
final AddressUtil.AddressHolder addressHolder = AddressUtil.getAddressHolder(address);
final Address targetAddress = new Address(addressHolder.getAddress(), addressHolder.getPort());
list.add(mcs.callOnAddress(targetAddress, new ScriptExecutorOperation(engine, script, bindings)));
}
results = list;
}
StringBuffer sb = new StringBuffer();
for (Object result : results) {
if (result instanceof String) {
sb.append(result);
} else if (result instanceof List) {
final List list = (List) result;
for (Object o : list) {
sb.append(o).append("\n");
}
} else if (result instanceof Map) {
final Map map = (Map) result;
for (Object o : map.entrySet()) {
final Map.Entry entry = (Map.Entry) o;
sb.append(entry.getKey()).append("->").append(entry.getValue()).append("\n");
}
} else if (result == null) {
sb.append("error");
}
sb.append("\n");
}
jsonResult.add("scriptResult", sb.toString());
root.add("result", jsonResult);
}