T - Actor type.public abstract class AbstractManualActionContext<T> extends java.lang.Object implements java.lang.Comparable<AbstractManualActionContext<?>>
SchedulableActionContext that is designed to be used
manually. This class should be used whenever controlling the execution state of work is
important. The action should be performed with performAction(). This is a convenience
class for creating an ActionEngine.ManualWorkQueue,
ManualActionEngine,
ForkJoinActionEngine| Modifier | Constructor and Description |
|---|---|
protected |
AbstractManualActionContext(ActionEngine engine,
Action<T> action)
Creates a new instance of AbstractManualActionContext with the supplied engine and action.
|
protected |
AbstractManualActionContext(ActionEngine engine,
Action<T> action,
ActionBindings sourceBindings)
Creates a new instance of AbstractManualActionContext with the supplied engine, action and
source bindings.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
addAsWork()
Used to add this context as work to a queue.
|
void |
await()
Awaits the execution (or cancellation of the action).
|
boolean |
cancel()
Cancels the associated action.
|
int |
compareTo(AbstractManualActionContext<?> o) |
<S> S |
get(java.lang.String key)
Gets the value bound to the supplied key.
|
Action<T> |
getAction()
Gets the action this context is for.
|
T |
getActor()
Gets the associated actor.
|
ActionEngine |
getEngine()
Gets the associated engine.
|
long |
getEstimated()
Gets the ideal estimated execution time (nanos).
|
long |
getInitialDelay(java.util.concurrent.TimeUnit unit)
Gets the initial delay.
|
long |
getPeriod(java.util.concurrent.TimeUnit unit)
Gets the actions repeat period.
|
boolean |
isCancelled()
Whether the action has been cancelled.
|
boolean |
isDone()
Whether the action has been ran (or cancelled).
|
boolean |
isPeforming()
Whether the action is currently being performed.
|
boolean |
isPeriodicOnException()
Whether the action will continue to reschedule on exception.
|
void |
performAction()
Performs the action (setting context state).
|
<S> S |
put(java.lang.String key,
S value)
Binds the supplied key-value pair.
|
void |
putAll(java.util.Map<java.lang.String,?> map)
Binds all of the key-value pairs in the supplied map.
|
<S> S |
remove(java.lang.String key)
Removes the value bound to the supplied key.
|
void |
removeAll()
Removes all key-value pairs.
|
protected abstract void |
removeAsWork()
Used to remove context as work from a queue.
|
protected void |
reset()
Resets the context to its starting state.
|
void |
schedule()
Schedules the action for execution.
|
void |
scheduleAndAwait()
This is a convenience method for scheduling and then awaiting execution (or cancellation) of
the action.
|
void |
setActor(T actor)
Sets the referenced actor.
|
void |
setInitialDelay(long initialDelay,
java.util.concurrent.TimeUnit unit)
Sets the initial delay.
|
void |
setPeriod(long period,
java.util.concurrent.TimeUnit unit)
Sets the period.
|
void |
setPeriodicOnException(boolean periodicOnException)
Sets whether the action continues to reschedule after an exception.
|
java.util.Map<java.lang.String,?> |
toMap()
Maps the key-values combinations.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetOptActor, hasActor, isPeriodiccontainsKeyprotected AbstractManualActionContext(ActionEngine engine, Action<T> action)
engine - Parent engine.action - Action this context is for.protected AbstractManualActionContext(ActionEngine engine, Action<T> action, ActionBindings sourceBindings)
engine - Parent engine.action - The action this context is for.sourceBindings - Bindings to shallow copy.protected abstract void addAsWork()
public void await()
throws java.lang.InterruptedException
ActionContextawait in interface ActionContext<T>java.lang.InterruptedException - If the current thread was interrupted.public boolean cancel()
ActionContextcancel in interface ActionContext<T>public int compareTo(AbstractManualActionContext<?> o)
compareTo in interface java.lang.Comparable<AbstractManualActionContext<?>>public long getEstimated()
System.nanoTime()public boolean isCancelled()
ActionContextisCancelled in interface ActionContext<T>public boolean isDone()
ActionContextisDone in interface ActionContext<T>public boolean isPeforming()
public void performAction()
throws java.lang.InterruptedException
java.lang.InterruptedException - If action throws this or this is interrupted.protected abstract void removeAsWork()
protected void reset()
public void schedule()
SchedulableActionContextschedule in interface SchedulableActionContext<T>public void scheduleAndAwait()
throws java.lang.InterruptedException
SchedulableActionContextscheduleAndAwait in interface SchedulableActionContext<T>java.lang.InterruptedException - If the current thread was interrupted.public <S> S get(java.lang.String key)
ActionBindingsget in interface ActionBindingskey - Key to check.public Action<T> getAction()
SchedulableActionContextgetAction in interface SchedulableActionContext<T>public T getActor()
ActionContextgetActor in interface ActionContext<T>public ActionEngine getEngine()
ActionContextgetEngine in interface ActionContext<T>public long getInitialDelay(java.util.concurrent.TimeUnit unit)
SchedulableActionContextgetInitialDelay in interface SchedulableActionContext<T>unit - TimeUnit to convert to.public long getPeriod(java.util.concurrent.TimeUnit unit)
ActionContextgetPeriod in interface ActionContext<T>unit - TimeUnit to convert period to.public boolean isPeriodicOnException()
ActionContextisPeriodicOnException in interface ActionContext<T>public <S> S put(java.lang.String key,
S value)
ActionBindingsput in interface ActionBindingskey - Key to bind value to.value - Value to bind.public void putAll(java.util.Map<java.lang.String,?> map)
ActionBindingsputAll in interface ActionBindingsmap - Key-value pairs to bind.public <S> S remove(java.lang.String key)
ActionBindingsremove in interface ActionBindingskey - Key to check.public void removeAll()
ActionBindingsremoveAll in interface ActionBindingspublic void setActor(T actor)
SchedulableActionContextsetActor in interface SchedulableActionContext<T>actor - Actor.public void setInitialDelay(long initialDelay,
java.util.concurrent.TimeUnit unit)
SchedulableActionContextsetInitialDelay in interface SchedulableActionContext<T>initialDelay - Initial delay to set (can be 0).unit - TimeUnit delay is in.public void setPeriod(long period,
java.util.concurrent.TimeUnit unit)
SchedulableActionContextsetPeriod in interface SchedulableActionContext<T>period - Period to set (can be 0).unit - TimeUnit period is in.public void setPeriodicOnException(boolean periodicOnException)
SchedulableActionContextsetPeriodicOnException in interface SchedulableActionContext<T>periodicOnException - Whether the action should continue.public java.util.Map<java.lang.String,?> toMap()
ActionBindingstoMap in interface ActionBindings