Class Schedule

  • All Implemented Interfaces:
    IAction, ISchedule
    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 Detail

      • tickCount

        protected double tickCount
      • 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 interface ISchedule
        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 interface ISchedule
        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 interface ISchedule
        Returns:
        the current user time units.
      • setTimeQuantity

        public void setTimeQuantity​(javax.measure.Quantity<?> newUnits)
        Sets the current user time units.
        Specified by:
        setTimeQuantity in interface ISchedule
        Parameters:
        newUnits - the new user time units.
      • getActionCount

        public int getActionCount()
        Gets the number of currently scheduled actions.
        Specified by:
        getActionCount in interface ISchedule
        Returns:
        the number of currently scheduled 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.
        Specified by:
        schedule in interface ISchedule
        Parameters:
        scheduleParams - the scheduling parameters specifying start time etc.
        action - the action to schedule for execution
        Returns:
        the actual action that was scheduled for execution.
      • 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 interface ISchedule
        Parameters:
        scheduleParams - the scheduling parameters specifying start time etc.
        target - the object on which to call the named method
        methodName - the name of the method to call
        methodParams - 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 interface ISchedule
        Parameters:
        scheduleParams - the scheduling parameters specifying start time etc.
        target - the Iterable containing the objects to call the method on
        methodName - the name of the method to call
        shuffle - whether to shuffle the items in the iterable before calling the method on the objects therein
        methodParams - 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.
        Specified by:
        schedule in interface ISchedule
        Parameters:
        obj - the object whose annotated methods should scheduled
        Returns:
        a List of the actual action scheduled for execution. An object may have more than one of its methods annotated for scheduling execution and so a list is returned.
      • 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 interface ISchedule
        Parameters:
        annotatedObj - the object whose annotated method should scheduled
        parameters - 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 interface ISchedule
        Parameters:
        scheduleParams - the scheduling parameters describing start time etc.
        annotatedObj - the object containing the annotated methods
        parameters - 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 interface ISchedule
        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.
        Specified by:
        execute in interface IAction
        Specified by:
        execute in interface ISchedule
      • executeEndActions

        public void executeEndActions()
        Executes all the actions scheduled to execute at the end of the model run.
        Specified by:
        executeEndActions in interface ISchedule
      • 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 interface ISchedule
        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 interface ISchedule
        Returns:
        if the schedule is in finishing mode
        See Also:
        NonModelAction, ISchedulableAction.isNonModelAction()