Class ScheduledProcessStartSource

java.lang.Object
de.aristaflow.adept2.core.eventmanager.common.AbstractEventSource<TimeScheduleEvent>
de.aristaflow.adept2.core.eventmanager.timeevents.ScheduledProcessStartSource
All Implemented Interfaces:
EventSource<TimeScheduleEvent>, ScheduledSource<TimeScheduleEvent>, TimeScheduleSource, Runnable

@ConfigurationDescription(properties={@Property(name="ScheduledStarts.<StartName>.Start",isRequired=true,documentationOnly=true,description="The first due time of the scheduled process start of this name in the configuration of the event manager: an ISO-8601 date-time, or a date and a time separated by \'T\' or a blank, with optional seconds and an optional time zone, for instance \'2026-01-01 06:00 Europe/Berlin\'. Without a time zone, the time zone of the event manager applies."),,,,,,,,,,,}) public class ScheduledProcessStartSource extends AbstractEventSource<TimeScheduleEvent> implements TimeScheduleSource
The source of the time events of one scheduled process start. It computes the due times of the start from its time schedule and its state and raises a ScheduledProcessStartEvent for each. It records a due time as the last time event before the event is handled, so that a due time is handled at most once, also across a crash, and afterwards the instance the trigger has started as the last instance. With a fixed delay, it checks once per period whether the instance the previous trigger has started has ended. Due times which have passed while no source ran are missed; of them, the latest is handled at once if the start catches up missed starts. It reads the state at its first run, which waits for the end of a run in progress of a source it replaces, so that it reads the state that run records.

The configuration of this source is that of the event manager, which holds the start whose name is the ID of this source, and its state. A disabled start does not run. A start of a template status has no form in the configuration, so this source gets it from the event manager by its name, and its state also records its period and whether this is a fixed rate, which the event manager needs to let the state expire once no source holds the start.

  • Field Details

    • eventManager

      protected final DefaultEventManager eventManager
      The event manager this source is a plugin of, which provides the sessions.
    • registry

      protected final Registry registry
      The registry of this source, which provides the process manager of an instance.
    • factory

      protected final ProcessModelFactory factory
      The factory creating the time schedule and the scheduled start of the start.
    • executionManager

      protected final ExecutionManager executionManager
      The execution manager naming the process manager of an instance.
    • conf

      protected Configuration conf
      The configuration of the event manager, which holds the start and its state.
    • processStart

      protected ScheduledProcessStart processStart
      The scheduled process start of this source.
    • lastTimeEvent

      protected Instant lastTimeEvent
      The last due time for which this source has raised an event, or the time the start has been registered if it has raised none since; null until the first run of this source has read the state.
    • lastInstance

      protected UUID lastInstance
      The ID of the instance which the last successful trigger of the start has started, null if no trigger has started one.
    • step

      The step of the next run, null if this source does not run any more.
    • nextRun

      protected Instant nextRun
      The time of the next run, null if this source does not run any more.
    • dueTime

      protected Instant dueTime
      The due time which the next run triggers if its step is ScheduledProcessStartSource.Step.TRIGGER.
    • pending

      protected boolean pending
      Whether the run which this source has named last has not reached its step yet, which a run does not while no handler is registered.
    • lastRunEnd

      protected Instant lastRunEnd
      The time the previous run of this source has ended, or the time this source has been created before its first run. A due time which has passed before it is missed.
  • Constructor Details

    • ScheduledProcessStartSource

      public ScheduledProcessStartSource(Configuration conf, DefaultEventManager eventManager, Registry registry) throws ServiceNotKnownException
      Creates the source of the time events of a scheduled process start as a plugin of the designated event manager, called by a service registry. The start is read when the configuration of this source is set.
      Parameters:
      conf - The configuration as provided from the registry, which this source does not use.
      eventManager - The event manager this event source is a plugin of.
      registry - The registry of this plugin.
      Throws:
      ServiceNotKnownException - If the factory of the process model or the execution manager cannot be retrieved, a ServiceNotKnownException will be thrown.
  • Method Details

    • setConfiguration

      public void setConfiguration(Configuration conf, String id) throws ConfigurationException
      Sets the (additional) configuration of this event source and its ID. The configuration is additional with respect to the configuration provided by the plugin load mechanism, if the event source is loaded as plugin.
      It is ensured that this method will be called before Runnable.run().

      The configuration is that of the event manager, which holds the start whose name is the designated ID, and its state, or only the state of a start of a template status, which the event manager provides. A start of a template status records its period and whether this is a fixed rate. The state is read at the first run, which follows at once unless a run in progress of a source this one replaces has to end first.

      Specified by:
      setConfiguration in interface EventSource<TimeScheduleEvent>
      Overrides:
      setConfiguration in class AbstractEventSource<TimeScheduleEvent>
      Parameters:
      conf - The configuration of this event source. This adheres (and overwrites) the configuration provided by the plugin loading, if this event source has been loaded as plugin. Whether this is allowed to be null depends on the implementation of the event source.
      id - The ID of this event source. This must not be null nor the empty string.
      Throws:
      ConfigurationException - If there are problems with the designated configuration (configuration is null although this is not allowed, a required configuration value is missing, ...), a ConfigurationException will be thrown.
    • getNextRunTime

      public Instant getNextRunTime()
      Description copied from interface: ScheduledSource
      Gets the time at which the event manager is to run this source next. A time which has passed lets the source run at once. This is called when the source is added, for a source added in place of a removed one when the removed one's run in progress has ended, and whenever a run of it has ended.
      Specified by:
      getNextRunTime in interface ScheduledSource<TimeScheduleEvent>
      Returns:
      The time at which this source is to run next or null if it has ended and is not to run any more.
    • checkForAndHandleEvent

      protected void checkForAndHandleEvent()
      Description copied from class: AbstractEventSource
      Checks for an event and handles it (usually by using AbstractEventSource.forwardEvent(Event, boolean, boolean)).
      Specified by:
      checkForAndHandleEvent in class AbstractEventSource<TimeScheduleEvent>
    • nextHandler

      protected boolean nextHandler(TimeScheduleEvent event, boolean consumed, boolean concurrent)
      Description copied from class: AbstractEventSource
      This method is called right before an event is offered to the next handler. In case of concurrent handling, this method will only be called once for all concurrent handling but this will be indicated by the corresponding parameter.
      Specified by:
      nextHandler in class AbstractEventSource<TimeScheduleEvent>
      Parameters:
      event - The event which is about to be handled by the next registered handler.
      consumed - Whether the event has been consumed yet.
      concurrent - Whether the next event handling is concurrent and thus the event will be offered to several event handler concurrently.
      Returns:
      Whether the event handling may continue. In case of serious problems preventing further event handling, return false here.
    • toString

      public String toString()
      Returns the hierarchical name of this source, which the event manager names when it logs about the runs of this source.
      Overrides:
      toString in class Object
      Returns:
      The hierarchical name of this source.
    • readState

      protected void readState()
      Reads the last time event and the last instance of the start from its state, which the first run of this source does. A value of the wrong form is logged and counts as none, so that the start records its state anew; a start without last time event records the time of this run as its registration, from which it counts its due times.
    • resume

      protected void resume()
      Computes the next step from the state as after a restart: with a fixed delay and an instance which the previous trigger has started, a check of this instance at once, otherwise the trigger of the first due time after the last time event.
    • trigger

      protected void trigger()
      Raises the event of the due time after recording the due time as the last time event, and records the instance the trigger has started as the last instance. If recording the due time fails, no event is raised, and the due time is handled as after a restart once the minimal delay has passed. The next step follows from the outcome of the trigger: a fixed rate continues with its next due time, a fixed delay checks the started instance a period later or counts the period from the last failed attempt or the end of the handling, and a one-shot start ends.
    • checkLastInstance

      protected void checkLastInstance()
      Checks whether the instance which the previous trigger has started has ended. The end of an ended instance plus the period is the next due time, and a vanished instance counts as ended at the check; a running instance is checked again a period later, and so is an instance which cannot be checked.
    • schedule

      protected void schedule(Instant due)
      Schedules the trigger of the designated due time. A due time which has passed after the end of the previous run of this source, or after its creation before its first run, is triggered at once, since no run could have triggered it earlier. A due time which has passed before is missed: if the start catches up missed starts, the latest due time missed is triggered at once; otherwise a fixed rate continues with its first due time after now, a fixed delay with the period from now, and a one-shot start ends.
      Parameters:
      due - The due time which to trigger or null if the start has none, which ends this source.
    • getFirstDueTimeAfter

      protected static Instant getFirstDueTimeAfter(TimeSchedule schedule, Instant time)
      Gets the first due time of the designated schedule after the designated time: its first start if this is later, otherwise with a fixed rate the first time of its grid after the designated time and with a fixed delay the designated time plus its period. A one-shot schedule has none after its first start.
      Parameters:
      schedule - The schedule of which to get the due time.
      time - The time after which to get the due time.
      Returns:
      The first due time of the designated schedule after the designated time or null if there is none.
    • getGridIndexAfter

      protected static long getGridIndexAfter(TimeSchedule schedule, Instant time)
      Gets the index of the first time of the grid of the designated fixed-rate schedule after the designated time. The index is estimated from the average length of the period, which is exact for a duration, and corrected by the deviation of the calendar.
      Parameters:
      schedule - The fixed-rate schedule of which to get the index.
      time - The time after which to get the index.
      Returns:
      The index of the first time of the grid after the designated time.
    • getGridTime

      protected static Instant getGridTime(TimeSchedule schedule, long index)
      Gets the time of the designated index of the grid of the designated fixed-rate schedule: its first start plus its period multiplied by the index, in the zone of the first start.
      Parameters:
      schedule - The fixed-rate schedule of which to get the time.
      index - The index of the time in the grid.
      Returns:
      The time of the designated index of the grid.
    • plusPeriod

      protected static Instant plusPeriod(TimeSchedule schedule, Instant time)
      Gets the designated time plus the period of the designated schedule in the zone of its first start, so that a calendar period keeps the local time across a change of daylight saving time.
      Parameters:
      schedule - The schedule of which to add the period.
      time - The time to which to add the period.
      Returns:
      The designated time plus the period of the designated schedule.