Refine search
@Override public <T> Future<T> submit(Runnable task, T result) { return this.executor.submit(task, result); } }
@Override public void run() { taskDistributor.submitToMember(task, member); } }
@Override public void execute(Runnable task) { this.executor.execute(task); }
protected void resetStatistics(Callable<Boolean> statsTask) { logger.trace("resetStatistics.enter; going to reset stats for schema: {}", schemaName); int cnt = 0; Map<Member, Future<Boolean>> futures = execService.submitToAllMembers(statsTask); for (Map.Entry<Member, Future<Boolean>> entry: futures.entrySet()) { try { if (entry.getValue().get()) { cnt++; } } catch (InterruptedException | ExecutionException ex) { logger.error("resetStatistics.error: " + ex.getMessage() + " on member " + entry.getKey(), ex); } } logger.trace("resetStatistics.exit; reset stats on {} nodes", cnt); }
public static Map<Member, Long> getOperationCount(HazelcastInstance hz) { IExecutorService executorService = hz.getExecutorService("operationCountExecutor"); Map<Member, Future<Long>> futures = new HashMap<Member, Future<Long>>(); for (Member member : hz.getCluster().getMembers()) { Future<Long> future = executorService.submitToMember(new GetOperationCount(), member); futures.put(member, future); } Map<Member, Long> result = new HashMap<Member, Long>(); for (Map.Entry<Member, Future<Long>> entry : futures.entrySet()) { try { Member member = entry.getKey(); Long value = entry.getValue().get(); if (value == null) { value = 0L; } result.put(member, value); } catch (Exception e) { throw rethrow(e); } } return result; }
private DocumentAccessor runSimpleDocumentTask(Callable<DocumentAccessor> task, Properties props) throws BagriException { //checkDocumentProperties(props); Future<DocumentAccessor> future = execService.submit(task); try { DocumentAccessor result = future.get(); logger.trace("storeDocument.exit; returning: {}", result); return (DocumentAccessor) result; } catch (InterruptedException | ExecutionException ex) { // the document could be processed anyway.. logger.error("runSimpleDocumentTask.error", ex); throw new BagriException(ex, ecDocument); } }
public long pingMember(Member member) { try { long start = System.currentTimeMillis(); communicationExecutorService.submitToMember(new NoOp(), member).get(4, TimeUnit.SECONDS); return System.currentTimeMillis() - start; } catch (Exception e) { throw new RuntimeException(e); } }
Callable<String> task = new Echo(input); String key = "foo"; IMap map1 = hz.getMap("m1"); IMap map2 = hz.getMap("m2"); map1.put(key,1); map2.put(key,2); IExecutorService executorService = hz.getExecutorService("default"); Future<String> future = executorService.submitToKeyOwner(task, key); String echoResult = future.get();
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<Member>(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) { currentThread().interrupt(); e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } }
public static void main(String[] args) throws Exception { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); IExecutorService executor = hz.getExecutorService("executor"); Future<Integer> future = executor.submit(new ComputationHeavyTask(), MemberSelectors.LITE_MEMBER_SELECTOR); System.out.println("Result: " + future.get()); } }
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) { currentThread().interrupt(); e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } }
@Override public <T> DistributedAnswer<T> call(DistributedCall<T> callable, MemberSelector memberSelector, long timeoutMs) throws InterruptedException { IExecutorService executor = hzInstance.getExecutorService("default"); Map<Member, Future<T>> futures = executor.submitToMembers(callable, memberSelector); try { DistributedAnswer<T> distributedAnswer = new DistributedAnswer<>(); long maxTime = System.currentTimeMillis() + timeoutMs; for (Map.Entry<Member, Future<T>> entry : futures.entrySet()) { long remainingMs = Math.max(maxTime - System.currentTimeMillis(), 5L); try { T answer = entry.getValue().get(remainingMs, TimeUnit.MILLISECONDS); distributedAnswer.setAnswer(entry.getKey(), answer); } catch (ExecutionException e) { distributedAnswer.setFailed(entry.getKey(), e); } catch (TimeoutException e) { distributedAnswer.setTimedOut(entry.getKey()); } } return distributedAnswer; } finally { futures.values().forEach(f -> f.cancel(true)); } }
private static void notifyAdmins(HazelcastInstance sysInstance, Member local, String schemaName, boolean initialized) { int cnt = 0; IExecutorService execService = sysInstance.getExecutorService(PN_XDM_SYSTEM_POOL); Set<Member> admins = getAdmins(sysInstance); // notify admin about new schema node (local) // hzInstance -> system instance, SchemaManagement is in its context // submit task to init member in admin.. SchemaAdministrator adminTask = new SchemaAdministrator(schemaName, !initialized, local.getUuid()); Map<Member, Future<Boolean>> result = execService.submitToMembers(adminTask, admins); for (Map.Entry<Member, Future<Boolean>> e: result.entrySet()) { try { if (e.getValue().get()) { cnt++; } else { logger.info("notifyAdmins; failed admin notification on member {}", e.getKey()); } } catch (InterruptedException | ExecutionException ex) { logger.error("notifyAdmins.error; ", ex); } } logger.debug("notifyAdmins; notified {} admin nodes out of {} admins", cnt, admins.size()); }
Callable<String> task = new Echo(input); // Echo is just some Callable HazelcastInstance hz = Hazelcast.newHazelcastInstance(); IExecutorService executorService = hz.getExecutorService("default"); Future<String> future = executorService.submitToMember(task, member); String echoResult = future.get();
Collection<MemberResponse<T>> result = new ArrayList<MemberResponse<T>>(members.size()); Map<Member, Future<T>> resultFutures = execSvc.submitToMembers(callable, members); for(Entry<Member, Future<T>> futureEntry : resultFutures.entrySet()) { Future<T> future = futureEntry.getValue(); result.add(new MemberResponse<T>(member, future.get(maxWaitTime, unit))); } else { result.add(new MemberResponse<T>(member, future.get()));
public static void main(String[] args) throws Exception { int n = 10; if (args.length != 0) { n = Integer.parseInt(args[0]); } HazelcastInstance hz = Hazelcast.newHazelcastInstance(); IExecutorService executor = hz.getExecutorService("executor"); Future<Long> future = executor.submit(new FibonacciCallable(n)); try { long result = future.get(10, TimeUnit.SECONDS); System.out.println("Result: " + result); } catch (TimeoutException e) { System.err.println("A timeout occurred!"); future.cancel(true); } Hazelcast.shutdownAll(); } }
public static void main(String[] args) throws Exception { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); Map<String, Integer> map = hz.getMap("map"); for (int i = 0; i < 5; i++) { map.put(UUID.randomUUID().toString(), 1); } IExecutorService executor = hz.getExecutorService("executor"); Map<Member, Future<Integer>> result = executor.submitToAllMembers(new SumTask()); int sum = 0; for (Future<Integer> future : result.values()) { sum += future.get(); } System.out.println("Result: " + sum); } }
hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig); IExecutorService executorService = hazelcastInstance.getExecutorService("default"); Callable<String> myCallable = new MyCallable(); Map<Member, Future<String>> results = executorService.submitToAllMembers(myCallable); for (Future<String> result : results.values()) { log.info("Result from '{}'", result.get()); if (hazelcastInstance.getLifecycleService().isRunning()) { hazelcastInstance.shutdown();
Set<Member> all = hzInstance.getCluster().getMembers(); List<Member> named = new ArrayList<Member>(all.size()); String name = node.getName(); IExecutorService execService = hzInstance.getExecutorService(PN_XDM_SYSTEM_POOL); Map<Member, Future<Boolean>> result = execService.submitToMembers(setter, named); for (Map.Entry<Member, Future<Boolean>> entry: result.entrySet()) { try { Boolean ok = entry.getValue().get(); if (ok) cnt++; logger.debug("updateNodesInCluster; Member {} {}updated", entry.getKey(), ok ? "" : "NOT ");
Map<Member, Future<ResultCursor<DocumentAccessor>>> results = execService.submitToAllMembers(task); try { if (asynch) { result = results.values().iterator().next().get(); ((QueuedCursorImpl<DocumentAccessor>) result).init(repo.getHazelcastClient()); } else { if (repo.getHazelcastClient().getCluster().getMembers().size() > 1) { int fetchSize = Integer.parseInt(props.getProperty(pn_client_fetchSize, "0")); CombinedCursorImpl<DocumentAccessor> comb = new CombinedCursorImpl<>(fetchSize); for (Map.Entry<Member, Future<ResultCursor<DocumentAccessor>>> entry: results.entrySet()) { comb.addResults(entry.getValue().get()); result = results.values().iterator().next().get();