@Override protected boolean doCancel(TaskCancellationMode mode) { boolean result = false; if (mode.isAllowedToInterruptDependentSubmittedTasks()) { for (Task<?> t: secondaryJobsAll) { // secondary jobs are dependent result = ((TaskInternal<?>)t).cancel(mode) || result; } } return super.doCancel(mode) || result; // returns true if anything is successfully cancelled }
/** queues the task if possible, otherwise submits it asynchronously; returns the task for callers to * {@link Task#getUnchecked()} or {@link Task#blockUntilEnded()} */ public static <T> Task<T> submit(TaskAdaptable<T> task, Entity entity) { return queueIfPossible(task).orSubmitAsync(entity).asTask(); }
@Override public Object call() throws Exception { try { Tasks.setBlockingDetails("Retrieving "+ds); return ds.get(); } finally { Tasks.resetBlockingDetails(); } } }; String description = getDescription();
@Override public Task<?> call() { return Tasks.builder().dynamic(false).body(job).displayName("HA poller task").tag(BrooklynTaskTags.TRANSIENT_TASK_TAG) .description("polls HA status to see whether this node should promote").build(); } };
public Task<String> sayTask(String message, Duration duration, String message2) { return Tasks.<String>builder().displayName("say:"+message+(duration!=null ? ":wait("+duration+")" : "")+(message2!=null ? ":"+message2 : "")) .body(sayCallable(message, duration, message2)).build(); }
public void testDefaultWhenSwallowError() { ValueResolver<String> result = Tasks.resolving(newThrowTask(Duration.ZERO)).as(String.class).context(app).swallowExceptions().defaultValue("foo"); assertMaybeIsAbsent(result); Assert.assertEquals(result.get(), "foo"); }
public void testGetImmediately() { MyImmediateAndDeferredSupplier supplier = new MyImmediateAndDeferredSupplier(); CallInfo callInfo = Tasks.resolving(supplier).as(CallInfo.class).context(app).immediately(true).get(); assertImmediateFakeTaskFromMethod(callInfo, "testGetImmediately"); }
public void testImmediateSupplierWithTimeoutUsesBlocking() { MyImmediateAndDeferredSupplier supplier = new MyImmediateAndDeferredSupplier(); CallInfo callInfo = Tasks.resolving(supplier).as(CallInfo.class).context(app).timeout(Asserts.DEFAULT_LONG_TIMEOUT).get(); assertRealTaskNotFromMethod(callInfo, "testImmediateSupplierWithTimeoutUsesBlocking"); }
@Override public Maybe<?> call() throws Exception { return Tasks.resolving(dsl).as(type) .context(context) .description("Computing "+dsl) .immediately(true) .getMaybe(); } };
public void testSwallowError() { ValueResolver<String> result = Tasks.resolving(newThrowTask(Duration.ZERO)).as(String.class).context(app).swallowExceptions(); assertMaybeIsAbsent(result); assertThrowsOnGet(result); }
public void testDontSwallowError() { ValueResolver<String> result = Tasks.resolving(newThrowTask(Duration.ZERO)).as(String.class).context(app); assertThrowsOnGetMaybe(result); assertThrowsOnGet(result); }
/** sets extra status details on the current task, if possible (otherwise does nothing). * the extra status is presented in Task.getStatusDetails(true) */ public static void setExtraStatusDetails(String notes) { Task<?> current = current(); if (current instanceof TaskInternal) ((TaskInternal<?>)current).setExtraStatusText(notes); }
public static TaskQueueingContext getTaskQueuingContext() { TaskQueueingContext adder = getThreadTaskQueuingContext(); if (adder!=null) return adder; Task<?> t = Tasks.current(); if (t instanceof TaskQueueingContext) return (TaskQueueingContext) t; return null; }
public static Task<?> setBlockingTask(Task<?> blocker) { Task<?> current = current(); if (current instanceof TaskInternal) return ((TaskInternal<?>)current).setBlockingTask(blocker); return null; } public static void resetBlockingTask() {
@Override protected void finalize() throws Throwable { TaskFinalizer finalizer = Tasks.tag(this, TaskFinalizer.class, false); if (finalizer==null) finalizer = WARN_IF_NOT_RUN; finalizer.onTaskFinalization(this); }
@Override public Task<?> getProxyTarget() { return delegate().getProxyTarget(); } }
public <T> Task<T> scheduleWith(Map<?,?> flags, Task<T> task) { synchronized (task) { if (((TaskInternal<?>)task).getInternalFuture()!=null) return task; return submitNewTask(flags, task); } }