Package repast.simphony.engine.schedule
Class Schedule
java.lang.Object
repast.simphony.engine.schedule.Schedule
- Direct Known Subclasses:
DefaultGraphSchedule
Manages the execution of IAction-s according to a simulation clock. The clock, measured in "ticks", is
incremeneted at the completion of the execution of all the IActions scheduled for execution at that clock tick.
The parameters of a scheduled IAction are set using a ScheduledParameters object which specifies the start time,
interval, priority and so forth of the action to be scheduled. The actual actions that a Schedule ultimately
schedules are produced by a ISchedulableActionFactory interface. By implementing this interface and creating a
Schedule that uses it, users can customize the type of actions that get scheduled. By default a Schedule uses a
DefaultSchedulableActionFactory.
- Version:
- $Revision: 1.1 $ $Date: 2005/12/21 22:25:34 $
- Author:
- Nick Collier
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ISchedulableActionFactoryprotected ActionQueueprotected ScheduleGroupprotected ScheduleGroupprotected doubleprotected javax.measure.Quantity<?>User time quantity converts some abstract quantity to a schedule tick value, and visa versa. -
Constructor Summary
ConstructorsConstructorDescriptionSchedule()Creates a Schedule that by default uses a DefaultSchedulableActionFactory to create its scheduled actions.Schedule(ISchedulableActionFactory factory) Creates a Schedule that will use the specified ISchedulableActionFactory to create its scheduled actions. -
Method Summary
Modifier and TypeMethodDescriptionjavax.measure.Quantity<?>convertTicksToTimeQuantity(double ticks) Converters the given time units into ticks using the current time units setting.convertTimeQuantityToTicks(javax.measure.Quantity<?> timeUnitsToConvert) Converters the given time units into ticks using the current time units setting.createAction(ScheduleParameters scheduleParams, Object annotatedObj, Object... parameters) Schedules the best matching ScheduleMethod annotated method for execution.voidexecute()Executes the schedule.voidExecutes all the actions scheduled to execute at the end of the model run.intGets the number of currently scheduled actions.intReturns the number of actions that do not have aNonModelActionannotation, attached to them along with the number ofISchedulableActions whoseISchedulableAction.isNonModelAction()method returns false.doubleGets the current tick count.javax.measure.Quantity<?>Gets the current tick count in user time units.javax.measure.Quantity<?>Gets the current user time units.booleanReturns whether or not the simultation is finishing, which means that this schedule will no longer allow actions to be scheduled or rescheduled.protected voidCollects the actions to be executed at the current clock tick.booleanremoveAction(ISchedulableAction action) Removes the specified action from this Schedule.Schedules for execution any methods in the specified object that have been annotated with the ScheduledMethod annotation.Schedules the best matching ScheduleMethod annotated method for execution.schedule(ScheduleParameters scheduleParams, Object target, String methodName, Object... methodParams) Schedules the named method call on the specified target with the specified parameters.schedule(ScheduleParameters scheduleParams, IAction action) Schedules the specified IAction for execution according to the specified schedule parameters.scheduleIterable(ScheduleParameters scheduleParams, Iterable target, String methodName, boolean shuffle, Object... methodParams) Schedules the named method call on each object returned by specified target with the specified parameters.voidsetFinishing(boolean finishing) Sets whether or not the simultation is finishing, which means that this schedule will no longer allow actions to be scheduled or rescheduled.voidsetTimeQuantity(javax.measure.Quantity<?> newUnits) Sets the current user time units.
-
Field Details
-
actionQueue
-
tickCount
protected double tickCount -
groupToExecute
-
endActions
-
actionFactory
-
userTimeQuantity
protected javax.measure.Quantity<?> userTimeQuantityUser time quantity converts some abstract quantity to a schedule tick value, and visa versa. For example the user might want 1.0 tick to represent 2 time seconds. Java Quantity is generic, and we do not restrict the type to a *Time* quantity, so the tick can represent any quantity.
-
-
Constructor Details
-
Schedule
public Schedule()Creates a Schedule that by default uses a DefaultSchedulableActionFactory to create its scheduled actions. -
Schedule
Creates a Schedule that will use the specified ISchedulableActionFactory to create its scheduled actions.- Parameters:
factory- the factory to use to create the actions that the Schedule will schedule
-
-
Method Details
-
getTickCount
public double getTickCount()Gets the current tick count. This is the current value of the simulation clock.- Specified by:
getTickCountin interfaceISchedule- Returns:
- the current tick count.
-
getTickCountInTimeQuantity
public javax.measure.Quantity<?> getTickCountInTimeQuantity()Gets the current tick count in user time units. This is the current value of the simulation clock in user time units.- Specified by:
getTickCountInTimeQuantityin interfaceISchedule- Returns:
- the current tick count in user time units.
-
convertTimeQuantityToTicks
Converters the given time units into ticks using the current time units setting.- Parameters:
timeUnitsToConvert- the time units to convert.- Returns:
- the converted ticks.
-
convertTicksToTimeQuantity
public javax.measure.Quantity<?> convertTicksToTimeQuantity(double ticks) Converters the given time units into ticks using the current time units setting.- Parameters:
ticks- time units to convert.- Returns:
- the converted ticks.
-
getTimeQuantity
public javax.measure.Quantity<?> getTimeQuantity()Gets the current user time units.- Specified by:
getTimeQuantityin interfaceISchedule- Returns:
- the current user time units.
-
setTimeQuantity
public void setTimeQuantity(javax.measure.Quantity<?> newUnits) Sets the current user time units.- Specified by:
setTimeQuantityin interfaceISchedule- Parameters:
newUnits- the new user time units.
-
getActionCount
public int getActionCount()Gets the number of currently scheduled actions.- Specified by:
getActionCountin interfaceISchedule- Returns:
- the number of currently scheduled actions.
-
getModelActionCount
public int getModelActionCount()Returns the number of actions that do not have aNonModelActionannotation, attached to them along with the number ofISchedulableActions whoseISchedulableAction.isNonModelAction()method returns false.- Specified by:
getModelActionCountin interfaceISchedule- Returns:
- the number of actions that are model actions, not back-end actions
-
peekNextAction
- Returns:
- next action on schedule queue
-
schedule
Schedules the specified IAction for execution according to the specified schedule parameters. -
schedule
public ISchedulableAction schedule(ScheduleParameters scheduleParams, Object target, String methodName, Object... methodParams) Schedules the named method call on the specified target with the specified parameters.- Specified by:
schedulein interfaceISchedule- Parameters:
scheduleParams- the scheduling parameters specifying start time etc.target- the object on which to call the named methodmethodName- the name of the method to callmethodParams- the parameters of the method named for execution- Returns:
- the actual action that was scheduled for execution.
-
scheduleIterable
public ISchedulableAction scheduleIterable(ScheduleParameters scheduleParams, Iterable target, String methodName, boolean shuffle, Object... methodParams) Schedules the named method call on each object returned by specified target with the specified parameters. Note that if the Iterable is not a list shuffling is not optimized can potentialy be quite slow.- Specified by:
scheduleIterablein interfaceISchedule- Parameters:
scheduleParams- the scheduling parameters specifying start time etc.target- the Iterable containing the objects to call the method onmethodName- the name of the method to callshuffle- whether to shuffle the items in the iterable before calling the method on the objects thereinmethodParams- the parameters of the method named for execution- Returns:
- the actual action that was scheduled for execution.
-
schedule
Schedules for execution any methods in the specified object that have been annotated with the ScheduledMethod annotation. The ScheduledMethod annotation tags the method as one that should be scheduled for execution and also provides the scheduling parameters for the scheduling of that method. -
schedule
Schedules the best matching ScheduleMethod annotated method for execution. The ScheduledMethod annotation tags the method as one that should be scheduled for execution and also provides the scheduling parameters for the scheduling of that method. The specified parameters will be passed to that method on execution. The method will be selected by choosing the annotated method whose parameters best match the specified parameters. -
createAction
public ISchedulableAction createAction(ScheduleParameters scheduleParams, Object annotatedObj, Object... parameters) Schedules the best matching ScheduleMethod annotated method for execution. The ScheduledMethod annotation tags the method as one that should be scheduled for execution. The specified parameters will be passed to that method on execution. The method will be selected by choosing the annotated method whose parameters best match the specified parameters. Any ScheduleParameters derived from the ScheduledMethod annotation will be ignored and replaced by the specified ScheduleParameters.- Specified by:
createActionin interfaceISchedule- Parameters:
scheduleParams- the scheduling parameters describing start time etc.annotatedObj- the object containing the annotated methodsparameters- the parameters to pass to the method call and to use to find the method itself- Returns:
- the actual action scheduled for execution.
- See Also:
-
removeAction
Removes the specified action from this Schedule. Actions should not be scheduled for removal at the same tick in which they are executing. In those cases, removeAction will always return false.- Specified by:
removeActionin interfaceISchedule- Parameters:
action- the ISchedulableAction to remove- Returns:
- whether or not the action was removed.
-
preExecute
protected void preExecute()Collects the actions to be executed at the current clock tick. The current clock is the "nextTime" of the action at the front of the action queue. All the actions set to execute at that time are gathered into the groupToExecute and the simulation tick count is set to that time. -
execute
public void execute()Executes the schedule. Schedule execution consists of determining the current clock tick, executing all the actions scheduled for execution at that tick, and then rescheduling any actions that have a repeating frequency. -
executeEndActions
public void executeEndActions()Executes all the actions scheduled to execute at the end of the model run.- Specified by:
executeEndActionsin interfaceISchedule
-
setFinishing
public void setFinishing(boolean finishing) Sets whether or not the simultation is finishing, which means that this schedule will no longer allow actions to be scheduled or rescheduled. This is used to execute the back-end actions one final time after the model actions have been completed.- Specified by:
setFinishingin interfaceISchedule- Parameters:
finishing- if the schedule is to be in finishing mode- See Also:
-
isFinishing
public boolean isFinishing()Returns whether or not the simultation is finishing, which means that this schedule will no longer allow actions to be scheduled or rescheduled. This is used to execute the back-end actions one final time after the model actions have been completed.- Specified by:
isFinishingin interfaceISchedule- Returns:
- if the schedule is in finishing mode
- See Also:
-