/** {@inheritDoc} */ @Override protected Void run(VisorComputeCancelSessionsTaskArg arg) { Set<IgniteUuid> sesIds = arg.getSessionIds(); if (sesIds != null && !sesIds.isEmpty()) { IgniteCompute compute = ignite.compute(ignite.cluster().forLocal()); Map<IgniteUuid, ComputeTaskFuture<Object>> futs = compute.activeTaskFutures(); for (IgniteUuid sesId : sesIds) { ComputeTaskFuture<Object> fut = futs.get(sesId); if (fut != null) fut.cancel(); } } return null; }
/** * Cancel a random task when required. */ private void performCancel() { iteration++; if (iteration % cancelRate == 0) { // Here we should have mostly running futures so just pick one. ComputeTaskFuture<Integer> futToCancel = futures.get( new Random().nextInt(futures.size()) ); try { futToCancel.cancel(); ignite.log().info("Task canceled: " + futToCancel.getTaskSession().getId()); } catch (IgniteException e) { ignite.log().warning(">>> Future cancellation failed: " + futToCancel.getTaskSession().getId(), e); } } } }
Thread.sleep(timeoutBeforeCancel); assert fut.cancel();
fut.cancel();
/** {@inheritDoc} */ @Override protected Void run(VisorComputeCancelSessionsTaskArg arg) { Set<IgniteUuid> sesIds = arg.getSessionIds(); if (sesIds != null && !sesIds.isEmpty()) { IgniteCompute compute = ignite.compute(ignite.cluster().forLocal()); Map<IgniteUuid, ComputeTaskFuture<Object>> futs = compute.activeTaskFutures(); for (IgniteUuid sesId : sesIds) { ComputeTaskFuture<Object> fut = futs.get(sesId); if (fut != null) fut.cancel(); } } return null; }