/** * Method for entity to make effector happen with correct semantics (right place, right task context), * when a method is called on that entity. * @throws ExecutionException */ public <T> T invokeEffectorMethodSync(final Entity entity, final Effector<T> eff, final Object args) throws ExecutionException { try { Task<?> current = Tasks.current(); if (current == null || !entity.equals(BrooklynTasks.getContextEntity(current)) || !isManagedLocally(entity)) { manageIfNecessary(entity, eff.getName()); // Wrap in a task if we aren't already in a task that is tagged with this entity Task<T> task = runAtEntity( EffectorUtils.getTaskFlagsForEffectorInvocation(entity, eff), entity, new Callable<T>() { public T call() { return invokeEffectorMethodLocal(entity, eff, args); }}); return task.get(); } else { return invokeEffectorMethodLocal(entity, eff, args); } } catch (Exception e) { // don't need to attach any message or warning because the Effector impl hierarchy does that (see calls to EffectorUtils.handleException) throw new ExecutionException(e); } }
public static TaskSummary taskSummary(Task<?> task) { try { Preconditions.checkNotNull(task); Entity entity = BrooklynTasks.getContextEntity(task); String entityId; String entityDisplayName;
public static LinkWithMetadata asLink(Task<?> t) { if (t==null) return null; MutableMap<String,Object> data = new MutableMap<String,Object>(); data.put("id", t.getId()); if (t.getDisplayName()!=null) data.put("taskName", t.getDisplayName()); Entity entity = BrooklynTasks.getContextEntity(t); if (entity!=null) { data.put("entityId", entity.getId()); if (entity.getDisplayName()!=null) data.put("entityDisplayName", entity.getDisplayName()); } return new LinkWithMetadata("/v1/activities/"+t.getId(), data); }