Package repast.simphony.engine.schedule
Class Schedule
- java.lang.Object
-
- repast.simphony.engine.schedule.Schedule
-
- Direct Known Subclasses:
DefaultGraphSchedule
public class Schedule extends Object implements ISchedule
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:
IAction
,ScheduleParameters
,ISchedulableActionFactory
,DefaultSchedulableActionFactory
-
-
Field Summary
Fields Modifier and Type Field Description protected ISchedulableActionFactory
actionFactory
protected ActionQueue
actionQueue
protected ScheduleGroup
endActions
protected ScheduleGroup
groupToExecute
protected double
tickCount
protected javax.measure.Quantity<?>
userTimeQuantity
User time quantity converts some abstract quantity to a schedule tick value, and visa versa.
-
Constructor Summary
Constructors Constructor Description Schedule()
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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.measure.Quantity<?>
convertTicksToTimeQuantity(double ticks)
Converters the given time units into ticks using the current time units setting.Double
convertTimeQuantityToTicks(javax.measure.Quantity<?> timeUnitsToConvert)
Converters the given time units into ticks using the current time units setting.ISchedulableAction
createAction(ScheduleParameters scheduleParams, Object annotatedObj, Object... parameters)
Schedules the best matching ScheduleMethod annotated method for execution.void
execute()
Executes the schedule.void
executeEndActions()
Executes all the actions scheduled to execute at the end of the model run.int
getActionCount()
Gets the number of currently scheduled actions.int
getModelActionCount()
Returns the number of actions that do not have aNonModelAction
annotation, attached to them along with the number ofISchedulableAction
s whoseISchedulableAction.isNonModelAction()
method returns false.double
getTickCount()
Gets the current tick count.javax.measure.Quantity<?>
getTickCountInTimeQuantity()
Gets the current tick count in user time units.javax.measure.Quantity<?>
getTimeQuantity()
Gets the current user time units.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.ISchedulableAction
peekNextAction()
protected void
preExecute()
Collects the actions to be executed at the current clock tick.boolean
removeAction(ISchedulableAction action)
Removes the specified action from this Schedule.List<ISchedulableAction>
schedule(Object obj)
Schedules for execution any methods in the specified object that have been annotated with the ScheduledMethod annotation.ISchedulableAction
schedule(Object annotatedObj, Object... parameters)
Schedules the best matching ScheduleMethod annotated method for execution.ISchedulableAction
schedule(ScheduleParameters scheduleParams, Object target, String methodName, Object... methodParams)
Schedules the named method call on the specified target with the specified parameters.ISchedulableAction
schedule(ScheduleParameters scheduleParams, IAction action)
Schedules the specified IAction for execution according to the specified schedule parameters.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.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.void
setTimeQuantity(javax.measure.Quantity<?> newUnits)
Sets the current user time units.
-
-
-
Field Detail
-
actionQueue
protected ActionQueue actionQueue
-
tickCount
protected double tickCount
-
groupToExecute
protected ScheduleGroup groupToExecute
-
endActions
protected ScheduleGroup endActions
-
actionFactory
protected ISchedulableActionFactory actionFactory
-
userTimeQuantity
protected javax.measure.Quantity<?> userTimeQuantity
User 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 Detail
-
Schedule
public Schedule()
Creates a Schedule that by default uses a DefaultSchedulableActionFactory to create its scheduled actions.
-
Schedule
public Schedule(ISchedulableActionFactory factory)
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 Detail
-
getTickCount
public double getTickCount()
Gets the current tick count. This is the current value of the simulation clock.- Specified by:
getTickCount
in 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:
getTickCountInTimeQuantity
in interfaceISchedule
- Returns:
- the current tick count in user time units.
-
convertTimeQuantityToTicks
public Double convertTimeQuantityToTicks(javax.measure.Quantity<?> timeUnitsToConvert)
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:
getTimeQuantity
in interfaceISchedule
- Returns:
- the current user time units.
-
setTimeQuantity
public void setTimeQuantity(javax.measure.Quantity<?> newUnits)
Sets the current user time units.- Specified by:
setTimeQuantity
in interfaceISchedule
- Parameters:
newUnits
- the new user time units.
-
getActionCount
public int getActionCount()
Gets the number of currently scheduled actions.- Specified by:
getActionCount
in interfaceISchedule
- Returns:
- the number of currently scheduled actions.
-
getModelActionCount
public int getModelActionCount()
Returns the number of actions that do not have aNonModelAction
annotation, attached to them along with the number ofISchedulableAction
s whoseISchedulableAction.isNonModelAction()
method returns false.- Specified by:
getModelActionCount
in interfaceISchedule
- Returns:
- the number of actions that are model actions, not back-end actions
-
peekNextAction
public ISchedulableAction peekNextAction()
- Returns:
- next action on schedule queue
-
schedule
public ISchedulableAction schedule(ScheduleParameters scheduleParams, IAction action)
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:
schedule
in 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:
scheduleIterable
in 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
public List<ISchedulableAction> schedule(Object obj)
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
public ISchedulableAction schedule(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 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.- Specified by:
schedule
in interfaceISchedule
- Parameters:
annotatedObj
- the object whose annotated method should scheduledparameters
- 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:
ScheduledMethod
-
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:
createAction
in 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:
ScheduledMethod
-
removeAction
public boolean removeAction(ISchedulableAction action)
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:
removeAction
in 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:
executeEndActions
in 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:
setFinishing
in interfaceISchedule
- Parameters:
finishing
- if the schedule is to be in finishing mode- See Also:
NonModelAction
,ISchedulableAction.isNonModelAction()
-
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:
isFinishing
in interfaceISchedule
- Returns:
- if the schedule is in finishing mode
- See Also:
NonModelAction
,ISchedulableAction.isNonModelAction()
-
-