public void setFinalizer(TaskFinalizer f) { TaskFinalizer finalizer = Tasks.tag(this, TaskFinalizer.class, false); if (finalizer!=null && finalizer!=f) throw new IllegalStateException("Cannot apply multiple finalizers"); if (isDone()) throw new IllegalStateException("Finalizer cannot be set on task "+this+" after it is finished"); tags.add(f); }
@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); }
/** returns the first tag found on the given task which matches the given type, looking up the submission hierarachy if necessary */ @SuppressWarnings("unchecked") public static <T> T tag(@Nullable Task<?> task, Class<T> type, boolean recurseHierarchy) { // support null task to make it easier for callers to walk hierarchies if (task==null) return null; for (Object tag: task.getTags()) if (type.isInstance(tag)) return (T)tag; if (!recurseHierarchy) return null; return tag(task.getSubmittedByTask(), type, true); }
public static Entity getTargetOrContextEntity(Task<?> t) { if (t==null) return null; Entity result = getWrappedEntityOfType(t, CONTEXT_ENTITY); if (result!=null) return result; result = getWrappedEntityOfType(t, TARGET_ENTITY); if (result!=null) { log.warn("Context entity found by looking at target entity tag, not context entity"); return result; } result = Tasks.tag(t, Entity.class, false); if (result!=null) { log.warn("Context entity found by looking at 'Entity' tag, not wrapped entity"); } return result; }
public static Object getTargetOrContextEntityTag(Task<?> task) { if (task == null) return null; Object result = getWrappedEntityTagOfType(task, CONTEXT_ENTITY); if (result!=null) return result; result = getWrappedEntityTagOfType(task, TARGET_ENTITY); if (result!=null) return result; result = Tasks.tag(task, Entity.class, false); if (result!=null) return result; return null; }