T
- Actor type.public abstract class AbstractFutureActionContext<T>
extends java.lang.Object
SchedulableActionContext
that is designed to be used with
ExecutorService
. This is a convenience class for creating an ActionEngine
.Modifier | Constructor and Description |
---|---|
protected |
AbstractFutureActionContext(ActionEngine engine,
Action<T> action)
Creates a new instance of AbstractFutureActionContext with the supplied engine and action.
|
protected |
AbstractFutureActionContext(ActionEngine engine,
Action<T> action,
ActionBindings sourceBindings)
Creates a new instance of AbstractFutureActionContext with the supplied engine, action and
source bindings.
|
Modifier and Type | Method and Description |
---|---|
void |
await()
Awaits the execution (or cancellation of the action).
|
boolean |
cancel()
Cancels the associated action.
|
<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.
|
protected java.util.concurrent.Future<?> |
getFuture()
Gets the future associated to the action task.
|
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 |
isPeriodicOnException()
Whether the action will continue to reschedule on exception.
|
<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.
|
void |
setActor(T actor)
Sets the referenced actor.
|
protected void |
setFuture(java.util.concurrent.Future<?> future)
Sets the future of the associated action task.
|
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, wait
schedule, scheduleAndAwait
getOptActor, hasActor, isPeriodic
containsKey
protected AbstractFutureActionContext(ActionEngine engine, Action<T> action)
engine
- Parent engine.action
- Action this context is for.protected AbstractFutureActionContext(ActionEngine engine, Action<T> action, ActionBindings sourceBindings)
engine
- Parent engine.action
- The action this context is for.sourceBindings
- Bindings to shallow copy.public void await() throws java.lang.InterruptedException
ActionContext
java.lang.InterruptedException
- If the current thread was interrupted.public boolean cancel()
ActionContext
protected java.util.concurrent.Future<?> getFuture()
public boolean isCancelled()
ActionContext
public boolean isDone()
ActionContext
protected void setFuture(java.util.concurrent.Future<?> future)
future
- Future to set.public <S> S get(java.lang.String key)
ActionBindings
get
in interface ActionBindings
key
- Key to check.public Action<T> getAction()
SchedulableActionContext
getAction
in interface SchedulableActionContext<T>
public T getActor()
ActionContext
getActor
in interface ActionContext<T>
public ActionEngine getEngine()
ActionContext
getEngine
in interface ActionContext<T>
public long getInitialDelay(java.util.concurrent.TimeUnit unit)
SchedulableActionContext
getInitialDelay
in interface SchedulableActionContext<T>
unit
- TimeUnit to convert to.public long getPeriod(java.util.concurrent.TimeUnit unit)
ActionContext
getPeriod
in interface ActionContext<T>
unit
- TimeUnit to convert period to.public boolean isPeriodicOnException()
ActionContext
isPeriodicOnException
in interface ActionContext<T>
public <S> S put(java.lang.String key, S value)
ActionBindings
put
in interface ActionBindings
key
- Key to bind value to.value
- Value to bind.public void putAll(java.util.Map<java.lang.String,?> map)
ActionBindings
putAll
in interface ActionBindings
map
- Key-value pairs to bind.public <S> S remove(java.lang.String key)
ActionBindings
remove
in interface ActionBindings
key
- Key to check.public void removeAll()
ActionBindings
removeAll
in interface ActionBindings
public void setActor(T actor)
SchedulableActionContext
setActor
in interface SchedulableActionContext<T>
actor
- Actor.public void setInitialDelay(long initialDelay, java.util.concurrent.TimeUnit unit)
SchedulableActionContext
setInitialDelay
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)
SchedulableActionContext
setPeriod
in interface SchedulableActionContext<T>
period
- Period to set (can be 0
).unit
- TimeUnit period is in.public void setPeriodicOnException(boolean periodicOnException)
SchedulableActionContext
setPeriodicOnException
in interface SchedulableActionContext<T>
periodicOnException
- Whether the action should continue.public java.util.Map<java.lang.String,?> toMap()
ActionBindings
toMap
in interface ActionBindings