private <T> Future<T> submit(DistributedTask dt) { ClientDistributedTask cdt = null; InnerFutureTask inner = (InnerFutureTask) dt.getInner(); check(inner.getCallable()); if (dt instanceof MultiTask) { if (inner.getMembers() == null) { Set<Member> set = new HashSet<Member>(); set.add(inner.getMember()); cdt = new ClientDistributedTask(inner.getCallable(), null, set, null); } } if (cdt == null) { cdt = new ClientDistributedTask(inner.getCallable(), inner.getMember(), inner.getMembers(), inner.getKey()); } return submit(dt, cdt); }
public Object doSynchronousClusterTask(ClusterTask task, byte[] nodeID) { if (cluster == null) { return null; } Member member = getMember(nodeID); Object result = null; // Check that the requested member was found if (member != null) { // Asynchronously execute the task on the target member DistributedTask<Object> distributedTask = new DistributedTask<Object>( new CallableTask<Object>(task), member); logger.debug("Executing DistributedTask: " + task.getClass().getName()); hazelcast.getExecutorService().execute(distributedTask); try { result = distributedTask.get(MAX_CLUSTER_EXECUTION_TIME, TimeUnit.SECONDS); logger.debug("DistributedTask result: " + (result == null ? "null" : result)); } catch (TimeoutException te) { logger.error("Failed to execute cluster task within " + MAX_CLUSTER_EXECUTION_TIME + " seconds", te); } catch (Exception e) { logger.error("Failed to execute cluster task", e); } } else { logger.warn("Requested node " + StringUtils.getString(nodeID) + " not found in cluster"); } return result; }
void notifyCompletion(final DistributedTask dtask) { final InnerFutureTask innerFutureTask = (InnerFutureTask) dtask.getInner(); getEventExecutorService().execute(new Runnable() { public void run() { innerFutureTask.innerDone(); if (innerFutureTask.getExecutionCallback() != null) { innerFutureTask.getExecutionCallback().done(dtask); } } }); }
MembersCall(String name, Set<Member> members, Data callable, DistributedTask dtask) { this.name = name; this.members = members; this.callable = callable; this.dtask = dtask; this.innerFutureTask = (InnerFutureTask) dtask.getInner(); }
MemberCall(String name, MemberImpl member, Data callable, DistributedTask dtask, boolean singleTask, ExecutionListener executionListener) { this.name = name; this.member = member; this.callable = callable; this.dtask = dtask; this.innerFutureTask = (InnerFutureTask) dtask.getInner(); this.singleTask = singleTask; this.target = member.getAddress(); this.executionListener = executionListener; }
public <T> Future<T> submit(Runnable runnable, T t) { if (runnable instanceof DistributedTask) { return submit((DistributedTask) runnable); } else { return submit(DistributedTask.callable(runnable, t)); } }
@Test public void testDistributedTask() throws ExecutionException, InterruptedException { SomeTask task = (SomeTask) context.getBean("someTask"); Future<Long> f = instance1.getExecutorService().submit(task); Assert.assertEquals(bean.value, f.get().longValue()); Future<Long> f2 = (Future<Long>) instance1.getExecutorService() .submit(new DistributedTask<Long>(new SomeTask())); Assert.assertEquals(bean.value, f2.get().longValue()); }
@Test public void testTransactionalTask() throws ExecutionException, InterruptedException { Future f = instance1.getExecutorService().submit(new DistributedTask(new SomeTransactionalTask(), instance2.getCluster().getLocalMember())); f.get(); Assert.assertTrue("transaction manager could not proxy the submitted task.", transactionManager.isCommitted()); }
public boolean doClusterTask(final ClusterTask task, byte[] nodeID) { if (cluster == null) { return false; } Member member = getMember(nodeID); // Check that the requested member was found if (member != null) { // Asynchronously execute the task on the target member logger.debug("Executing asynchronous DistributedTask: " + task.getClass().getName()); hazelcast.getExecutorService().execute( new DistributedTask<Object>(new CallableTask<Object>(task), member)); return true; } else { logger.warn("Requested node " + StringUtils.getString(nodeID) + " not found in cluster"); return false; } }
MemberCall(String name, MemberImpl member, Data callable, DistributedTask dtask) { this(name, member, callable, dtask, true, null); }
public <T> Future<T> submit(Callable<T> task) { if (task instanceof DistributedTask) { return submit((Runnable) task, null); } return submit(new DistributedTask(task), null); }
public <T> Future<T> submit(Callable<T> callable) { return submit(new DistributedTask(callable)); }