Search in sources :

Example 1 with Echo

use of com.hazelcast.console.Echo in project hazelcast by hazelcast.

the class ClientConsoleApp method executeOnMembers.

private void executeOnMembers(String[] args) {
    // executeOnMembers <echo-string>
    try {
        IExecutorService executorService = hazelcast.getExecutorService("default");
        Echo task = new Echo(args[1]);
        Map<Member, Future<String>> results = executorService.submitToAllMembers(task);
        for (Future f : results.values()) {
            println(f.get());
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}
Also used : Echo(com.hazelcast.console.Echo) Future(java.util.concurrent.Future) IExecutorService(com.hazelcast.core.IExecutorService) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.core.Member)

Example 2 with Echo

use of com.hazelcast.console.Echo in project hazelcast by hazelcast.

the class ClientConsoleApp method doExecute.

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) {
        e.printStackTrace();
    }
}
Also used : Echo(com.hazelcast.console.Echo) List(java.util.List) IList(com.hazelcast.core.IList) LinkedList(java.util.LinkedList) IExecutorService(com.hazelcast.core.IExecutorService) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.core.Member) LinkedList(java.util.LinkedList)

Aggregations

Echo (com.hazelcast.console.Echo)2 IExecutorService (com.hazelcast.core.IExecutorService)2 Member (com.hazelcast.core.Member)2 ExecutionException (java.util.concurrent.ExecutionException)2 IList (com.hazelcast.core.IList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Future (java.util.concurrent.Future)1