}
private void doExecute(boolean onKey, boolean onMember, String[] args) {
// executeOnKey <echo-string> <key>
try {
IExecutorService executorService = hazelcast.getExecutorService("default");
Echo callable = new Echo(args[1]);
Future<String> future;
if (onKey) {
String key = args[2];
future = executorService.submitToKeyOwner(callable, key);
} else if (onMember) {
int memberIndex = Integer.parseInt(args[2]);
List<Member> members = new LinkedList(hazelcast.getCluster().getMembers());
if (memberIndex >= members.size()) {
throw new IndexOutOfBoundsException("Member index: " + memberIndex + " must be smaller than " + members
.size());
}
Member member = members.get(memberIndex);
future = executorService.submitToMember(callable, member);
} else {
future = executorService.submit(callable);
}
println("Result: " + future.get());
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {