Package jsl.modeling.elements
Class TimedAction
- java.lang.Object
-
- jsl.simulation.ModelElement
-
- jsl.simulation.SchedulingElement
-
- jsl.modeling.elements.TimedAction
-
- All Implemented Interfaces:
ObservableIfc
,GetNameIfc
,IdentityIfc
public class TimedAction extends SchedulingElement
A TimedAction represents a set of actions associated with an event that can be repeated at regular intervals. Each TimedAction can have any number of TimedActionListeners attached that represent the actions that should occur when the event occurs. The attached listeners are called in the order defined by their priority. By default, the event will be automatically scheduled to occur at the start of each replication. By default the event will automatically repeat according to the provided interval.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jsl.simulation.ModelElement
ModelElement.EventBuilderIfc<T>, ModelElement.EventScheduler<T>, ModelElement.ModelElementComparator, ModelElement.RequestBuilder, ModelElement.RequestDurationIfc, ModelElement.RequestTimeIfc, ModelElement.RequestUsingIfc, ModelElement.TimedUpdateEventAction, ModelElement.TimeUnitIfc<T>, ModelElement.WarmUpEventAction
-
-
Field Summary
-
Fields inherited from class jsl.simulation.ModelElement
AFTER_EXPERIMENT, AFTER_REPLICATION, BEFORE_EXPERIMENT, BEFORE_REPLICATION, CONDITIONAL_ACTION_REGISTRATION, DEFAULT_TIMED_EVENT_PRIORITY, INITIALIZED, MONTE_CARLO, myAfterExperimentOption, myAfterReplicationOption, myBeforeExperimentOption, myBeforeReplicationOption, myInitializationOption, myLengthOfWarmUp, myModelElements, myMonteCarloOption, myObservableComponent, myReplicationEndedOption, myTimedUpdateActionListener, myTimedUpdateEvent, myTimedUpdateInterval, myTimedUpdateOption, myTimedUpdatePriority, myWarmUpActionListener, myWarmUpEvent, myWarmUpIndicator, myWarmUpOption, myWarmUpPriority, NONE, REMOVED_FROM_MODEL, REPLICATION_ENDED, TIME_UNIT_DAY, TIME_UNIT_HOUR, TIME_UNIT_MILLISECOND, TIME_UNIT_MINUTE, TIME_UNIT_SECOND, TIME_UNIT_WEEK, TIMED_UPDATE, UPDATE, WARMUP
-
-
Constructor Summary
Constructors Constructor Description TimedAction(ModelElement parent)
TimedAction(ModelElement parent, double time)
TimedAction(ModelElement parent, double time, java.lang.String name)
TimedAction(ModelElement parent, RandomIfc actionTime)
TimedAction(ModelElement parent, RandomIfc actionTime, boolean schedInitFlag, boolean repeatActionFlag, java.lang.String name)
Creates a Timed Action
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
afterReplication()
This method should be overridden by subclasses that need actions performed after each replication.protected void
attachTimedActionListener(TimedActionListener listener)
Adds a listener to react to the action event Listeners are ordered by their compareTo() methodvoid
cancelAction()
Causes the event associated with the actions to be canceled if it had been scheduled.boolean
getRepeatActionFlag()
True means the action will repeat.boolean
getScheduleOnInitializeFlag()
This flag indicates whether or not the action will automatically be scheduled when initialize() is called.RandomIfc
getTimeBetweenActions()
RandomIfc
getTimeBetweenActionsForReplications()
protected void
initialize()
This method should be overridden by subclasses that need actions performed to initialize prior to a replication.protected void
notifyTimedActionListeners(JSLEvent event)
boolean
removeTimedActionListener(TimedActionListener listener)
Removes the listener so that it does not react to the action eventvoid
scheduleAction()
If the action has not been previously scheduled this method causes the action to be scheduled according to it's action time distribution.void
setRepeatActionFlag(boolean repeatActionFlag)
True means the action will repeat.void
setScheduleOnInitializeFlag(boolean flag)
Sets the flag that indicates whether or not the action will be automatically scheduled when initialize() is called.void
setTimeBetweenActions(double time)
Sets the time between actions to be a constant time for the current replicationvoid
setTimeBetweenActions(RandomIfc actionTime)
Sets the time between actions for the current replicationvoid
setTimeBetweenActionsInitialRandomSource(double time)
Sets the time between actions to be a constant time for all replicationsvoid
setTimeBetweenActionsInitialRandomSource(RandomIfc actionTime)
Sets the time between actions for all replications-
Methods inherited from class jsl.simulation.SchedulingElement
cancelEvent, rescheduleEvent, rescheduleEvent, rescheduleEvent, rescheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent
-
Methods inherited from class jsl.simulation.ModelElement
addObserver, addObserverToModelElements, afterExperiment, afterExperiment_, afterReplication_, asString, beforeExperiment, beforeExperiment_, beforeReplication, beforeReplication_, buildEventGenerator, cancelTimedUpdateEvent, cancelWarmUpEvent, changeParentModelElement, checkForAfterExperiment, checkForAfterReplication, checkForBeforeExperiment, checkForBeforeReplication, checkForConditionalActionRegistration, checkForInitialize, checkForMonteCarlo, checkForRemoveFromModel, checkForReplicationEnded, checkForTimedUpdate, checkForUpdate, checkForWarmUp, checkObserverState, checkWarmUpOption, clearModelElementObservers, contains, countObservers, createEntity, createEntity, createQObject, day, deleteObserver, deleteObserverFromModelElements, deleteObservers, findModelElementWithWarmUpEvent, getAfterExperimentOption, getAfterReplicationOption, getAllCounters, getAllModelElements, getAllRandomElements, getAllResponseVariables, getAllVariables, getBeforeExperimentOption, getBeforeReplicationOption, getChildModelElementIterator, getCurrentReplicationNumber, getDefaultEntityType, getExecutive, getExperiment, getId, getInitializationOption, getInitializationOrderAsString, getLeftPreOrderTraversalCount, getLengthOfWarmUp, getModel, getModelElementCompartor, getModelElementsAsString, getModelElementsAsString, getModelElementsAsString, getMonteCarloOption, getName, getNumberOfModelElements, getObserverState, getParentModelElement, getPreviousObserverState, getReplicationEndedOption, getRightPreOrderTraversalCount, getSimulation, getSpatialModel, getStringLabel, getThisElementsCounters, getThisElementsModelElements, getThisElementsRandomVariables, getThisElementsResponseVariables, getThisElementsVariables, getTime, getTimedUpdateInterval, getTimedUpdateOption, getUpdateNotificationFlag, getVariable, getWarmUpEventTime, getWarmUpOption, hour, indent, initialize_, isTimedUpdateEventScheduled, isWarmedUp, isWarmUpEventScheduled, isWarmUpScheduled, millisecond, minute, montecarlo, montecarlo_, notifyAfterExperimentObservers, notifyAfterReplicationObservers, notifyBeforeExperimentObservers, notifyBeforeReplicationObservers, notifyConditionalActionRegistrationObservers, notifyInitializationObservers, notifyMonteCarloObservers, notifyObservers, notifyObservers, notifyRemovingFromModelObservers, notifyReplicationEndedObservers, notifyTimedUpdateObservers, notifyUpdateObservers, notifyWarmUpObservers, registerConditionalActions, registerConditionalActions_, removedFromModel, removeFromModel, replicationEnded, replicationEnded_, schedule, second, seize, setAfterExperimentOption, setAfterExperimentOptionForModelElements, setAfterReplicationOption, setAfterReplicationOptionForModelElements, setBeforeExperimentOption, setBeforeExperimentOptionForModelElements, setBeforeReplicationOption, setBeforeReplicationOptionForModelElements, setInitializationOption, setInitializationOptionForModelElements, setLengthOfWarmUp, setModel, setMonteCarloOption, setMonteCarloOptionForModelElements, setName, setObserverState, setParentModelElement, setReplicationEndedOption, setReplicationEndedOptionForModelElements, setSpatialModel, setStringLabel, setTimedUpdateInterval, setTimedUpdateOption, setTimedUpdateOptionForModelElements, setUpdateNotificationFlag, setWarmUpOption, setWarmUpOptionForModelElements, stopExecutive, stopExecutive, timedUpdate, timedUpdate_, toString, update, useControls, warmUp, warmUp_, week
-
-
-
-
Constructor Detail
-
TimedAction
public TimedAction(ModelElement parent)
- Parameters:
parent
- the parent model element
-
TimedAction
public TimedAction(ModelElement parent, double time)
- Parameters:
parent
- the parent model elementtime
- the time between actions
-
TimedAction
public TimedAction(ModelElement parent, double time, java.lang.String name)
- Parameters:
parent
- the parent model elementtime
- the time between actionsname
- the name of the model element
-
TimedAction
public TimedAction(ModelElement parent, RandomIfc actionTime)
- Parameters:
parent
- the parent model elementactionTime
- the time between actions
-
TimedAction
public TimedAction(ModelElement parent, RandomIfc actionTime, boolean schedInitFlag, boolean repeatActionFlag, java.lang.String name)
Creates a Timed Action- Parameters:
parent
- the parent model elementactionTime
- the time between actionsschedInitFlag
- Indicates whether to schedule initial action at initializationrepeatActionFlag
- Indicates whether the actions will automatically repeat after their first occurrencename
- the name of the model element
-
-
Method Detail
-
getTimeBetweenActions
public final RandomIfc getTimeBetweenActions()
- Returns:
- Returns the actionTime.
-
getTimeBetweenActionsForReplications
public final RandomIfc getTimeBetweenActionsForReplications()
- Returns:
- Returns the actionTime.
-
setTimeBetweenActionsInitialRandomSource
public final void setTimeBetweenActionsInitialRandomSource(double time)
Sets the time between actions to be a constant time for all replications- Parameters:
time
- the initial time between actions
-
setTimeBetweenActionsInitialRandomSource
public final void setTimeBetweenActionsInitialRandomSource(RandomIfc actionTime)
Sets the time between actions for all replications- Parameters:
actionTime
- The actionTime to set.
-
setTimeBetweenActions
public final void setTimeBetweenActions(double time)
Sets the time between actions to be a constant time for the current replication- Parameters:
time
- the time between actions
-
setTimeBetweenActions
public final void setTimeBetweenActions(RandomIfc actionTime)
Sets the time between actions for the current replication- Parameters:
actionTime
- The actionTime to set.
-
getScheduleOnInitializeFlag
public boolean getScheduleOnInitializeFlag()
This flag indicates whether or not the action will automatically be scheduled when initialize() is called. By default this option is false.- Returns:
- true means that it is automatic
-
setScheduleOnInitializeFlag
public void setScheduleOnInitializeFlag(boolean flag)
Sets the flag that indicates whether or not the action will be automatically scheduled when initialize() is called. WARNING: If this is changed, it affects the next replication to be initialized() and all subsequent replications. Thus, the initialization of replications may not be the same. The recommended use is prior to any replications being executed.- Parameters:
flag
- true means it will be scheduled
-
cancelAction
public final void cancelAction()
Causes the event associated with the actions to be canceled if it had been scheduled. The next scheduled action will not occur.
-
getRepeatActionFlag
public final boolean getRepeatActionFlag()
True means the action will repeat. By default the action will repeat.- Returns:
- Returns the repeatActionFlag.
-
setRepeatActionFlag
public final void setRepeatActionFlag(boolean repeatActionFlag)
True means the action will repeat. By default the action will repeat. WARNING: If this is changed, this controls whether the action will be repeated after the next event occurs. The actions will not be repeated for the rest of the replication and for any subsequent replications. Thus, replications may not be the same. The recommended use is prior to any replications being executed.- Parameters:
repeatActionFlag
- The repeatActionFlag to set.
-
attachTimedActionListener
protected void attachTimedActionListener(TimedActionListener listener)
Adds a listener to react to the action event Listeners are ordered by their compareTo() method- Parameters:
listener
- the timed action listener
-
removeTimedActionListener
public boolean removeTimedActionListener(TimedActionListener listener)
Removes the listener so that it does not react to the action event- Parameters:
listener
- , the listener to be removed- Returns:
- true if it was removed
-
scheduleAction
public final void scheduleAction()
If the action has not been previously scheduled this method causes the action to be scheduled according to it's action time distribution. If the action has been canceled, then the action is scheduled for a new time according to it's action time. If the action is already scheduled and not canceled, this method has no effect.
-
initialize
protected void initialize()
Description copied from class:ModelElement
This method should be overridden by subclasses that need actions performed to initialize prior to a replication. It is called once before each replication occurs if the model element wants initialization. It is called after beforeReplication() is called- Overrides:
initialize
in classModelElement
-
afterReplication
protected void afterReplication()
Description copied from class:ModelElement
This method should be overridden by subclasses that need actions performed after each replication. It is called after replicationEnded() has been called.- Overrides:
afterReplication
in classModelElement
-
notifyTimedActionListeners
protected final void notifyTimedActionListeners(JSLEvent event)
-
-