/** blocks for the task to be completed * <p> * needed in any context where subsequent commands assume the task has completed. * not needed in a context where the task is simply being built up and queued. * <p> * throws if there are any errors */ public void andWaitForSuccess() { task.getUnchecked(); } }
@Override public T get() { return task.asTask().getUnchecked(); } };
@Override public void update() { Task<?> task = updateAsync(); if (task != null) task.getUnchecked(); }
/** causes the task to be submitted *synchronously* if it hasn't already been submitted; * useful in contexts such as libraries where callers may be either on a legacy call path * (which assumes all commands complete immediately) * */ public TaskQueueingResult<T> orSubmitAndBlock() { if (orSubmitInternal()) task.getUnchecked(); return this; } /** blocks for the task to be completed
/** blocks, throwing if there was an exception */ public Void get() { return getTask().getUnchecked(); }
/** blocks, returns the fetched file as a string, throwing if there was an exception */ public String get() { return getTask().getUnchecked(); }
@Override @Effector(description = "Restart the process/service represented by an entity") public void restart() { log.info("Invoking restart (method) on "+this); invoke(RESTART).getUnchecked(); }
/** Common implementation for stop in parent nodes; just invokes stop on all children of the entity */ public static void stop(EntityLocal e) { log.debug("Stopping entity "+e); Iterable<Entity> startables = filterStartableManagedEntities(e.getChildren()); if (!Iterables.isEmpty(startables)) { Entities.invokeEffector(e, startables, Startable.STOP).getUnchecked(); } if (log.isDebugEnabled()) log.debug("Stopped entity "+e); }
@Override @Effector(description = "Stop the process/service represented by an entity") public void stop() { log.info("Invoking stop (method) on "+this); invoke(STOP).getUnchecked(); }
/** Common implementation for restart in parent nodes; just invokes stop on all children of the entity */ public static void restart(EntityLocal e) { log.debug("Restarting entity "+e); Iterable<Entity> startables = filterStartableManagedEntities(e.getChildren()); if (!Iterables.isEmpty(startables)) { Entities.invokeEffector(e, startables, Startable.RESTART).getUnchecked(); } if (log.isDebugEnabled()) log.debug("Restarted entity "+e); }
/** submits the given task if needed, and gets the result (unchecked) * only permitted in a queueing context (ie a DST main job) */ // things get really confusing if you try to queueInTaskHierarchy -- easy to cause deadlocks! public static <T> T get(TaskAdaptable<T> t) { return queueIfNeeded(t).asTask().getUnchecked(); }
/** Returns the result of the last task queued in this context, coerced to the given type */ protected <V> V last(Class<V> type) { Task<?> last = waitForLast(); if (last==null) throw new IllegalStateException("No last task available (in "+DynamicTasks.getTaskQueuingContext()+")"); if (!Tasks.isQueuedOrSubmitted(last)) throw new IllegalStateException("Last task "+last+" has not been queued or submitted; will not block on its result"); return TypeCoercions.coerce(last.getUnchecked(), type); } }
/** Common implementation for start in parent nodes; just invokes start on all children of the entity */ public static void start(EntityLocal e, Collection<? extends Location> locations) { log.debug("Starting entity "+e+" at "+locations); Iterable<Entity> startables = filterStartableManagedEntities(e.getChildren()); if (!Iterables.isEmpty(startables)) { Entities.invokeEffector(e, startables, Startable.START, MutableMap.of("locations", locations)).getUnchecked(); } }
public int execute() { if (DynamicTasks.getTaskQueuingContext()!=null) { return queue().getUnchecked(); } else { return executeInternal(); } }
@Override public boolean isRunning() { return DynamicTasks.queue(getRequiredConfig(IS_RUNNING_TASK)).asTask().getUnchecked(); }
/** convenience for starting an entity, esp a new Startable instance which has been created dynamically * (after the application is started) */ public static void start(Entity e, Collection<? extends Location> locations) { if (!isManaged(e) && !manage(e)) { log.warn("Using discouraged mechanism to start management -- Entities.start(Application, Locations) -- caller should create and use the preferred management context"); startManagement(e); } if (e instanceof Startable) Entities.invokeEffector((EntityLocal)e, e, Startable.START, MutableMap.of("locations", locations)).getUnchecked(); }
@Override @Effector(description = "Start the process/service represented by an entity") public void start(@EffectorParam(name = "locations") Collection<? extends Location> locations) { log.info("Invoking start (method) on "+this); invoke(START, ConfigBag.newInstance().configure(StartParameters.LOCATIONS, locations).getAllConfig()) .getUnchecked(); }
/** stops, destroys, and unmanages the given entity -- does as many as are valid given the type and state */ public static void destroy(Entity e) { if (isManaged(e)) { if (e instanceof Startable) Entities.invokeEffector((EntityLocal)e, e, Startable.STOP).getUnchecked(); if (e instanceof EntityInternal) ((EntityInternal)e).destroy(); unmanage(e); log.debug("destroyed and unmanaged "+e+"; mgmt now "+ (e.getApplicationId()==null ? "(no app)" : e.getApplication().getManagementContext())+" - managed? "+isManaged(e)); } else { log.debug("skipping destroy of "+e+": not managed"); } }
/** * If custom behaviour is required by sub-classes, consider overriding {@link #doStart()}. */ @Override public final void start(final Collection<? extends Location> locations) { if (DynamicTasks.getTaskQueuingContext() != null) { doStart(locations); } else { Task<?> task = Tasks.builder().name("start").body(new Runnable() { public void run() { doStart(locations); } }).build(); Entities.submit(this, task).getUnchecked(); } }
/** * If custom behaviour is required by sub-classes, consider overriding {@link #doStop()}. */ @Override public final void restart() { if (DynamicTasks.getTaskQueuingContext() != null) { doRestart(); } else { Task<?> task = Tasks.builder().name("restart").body(new Runnable() { public void run() { doRestart(); } }).build(); Entities.submit(this, task).getUnchecked(); } }