Class ScheduledProcessStartSource
- All Implemented Interfaces:
EventSource<TimeScheduleEvent>,ScheduledSource<TimeScheduleEvent>,TimeScheduleSource,Runnable
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumThe steps of a run of this source. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ConfigurationThe configuration of the event manager, which holds the start and its state.protected InstantThe due time which the next run triggers if its step isScheduledProcessStartSource.Step.TRIGGER.protected final DefaultEventManagerThe event manager this source is a plugin of, which provides the sessions.protected final ExecutionManagerThe execution manager naming the process manager of an instance.protected final ProcessModelFactoryThe factory creating the time schedule and the scheduled start of the start.protected UUIDThe ID of the instance which the last successful trigger of the start has started,nullif no trigger has started one.protected InstantThe time the previous run of this source has ended, or the time this source has been created before its first run.protected InstantThe 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;nulluntil the first run of this source has read the state.protected InstantThe time of the next run,nullif this source does not run any more.protected booleanWhether the run which this source has named last has not reached its step yet, which a run does not while no handler is registered.protected ScheduledProcessStartThe scheduled process start of this source.protected final RegistryThe registry of this source, which provides the process manager of an instance.protected ScheduledProcessStartSource.StepThe step of the next run,nullif this source does not run any more.Fields inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventSource
eventType, handlerList, id, lock, logger, sourceType, thread, threadLock -
Constructor Summary
ConstructorsConstructorDescriptionScheduledProcessStartSource(Configuration conf, DefaultEventManager eventManager, Registry registry) 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. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidChecks for an event and handles it (usually by usingAbstractEventSource.forwardEvent(Event, boolean, boolean)).protected voidChecks whether the instance which the previous trigger has started has ended.protected static InstantgetFirstDueTimeAfter(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.protected static longgetGridIndexAfter(TimeSchedule schedule, Instant time) Gets the index of the first time of the grid of the designated fixed-rate schedule after the designated time.protected static InstantgetGridTime(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.Gets the time at which the event manager is to run this source next.protected booleannextHandler(TimeScheduleEvent event, boolean consumed, boolean concurrent) This method is called right before an event is offered to the next handler.protected static InstantplusPeriod(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.protected voidReads the last time event and the last instance of the start from its state, which the first run of this source does.protected voidresume()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.protected voidSchedules the trigger of the designated due time.voidsetConfiguration(Configuration conf, String id) Sets the (additional) configuration of this event source and its ID.toString()Returns the hierarchical name of this source, which the event manager names when it logs about the runs of this source.protected voidtrigger()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.Methods inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventSource
addAll, addedHandlerLocked, addedHandlerLocked, addHandler, createPattern, forwardEvent, getEventHandler, getHierarchicalSourceName, getID, getType, maskedInterrupt, maskInterrupt, removeHandler, removingHandlerLocked, replaceValueParams, run, unmaskInterruptMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface de.aristaflow.adept2.model.events.sources.EventSource
addAll, addHandler, getEventHandler, getHierarchicalSourceName, getID, getType, removeHandlerMethods inherited from interface de.aristaflow.adept2.model.events.sources.ScheduledSource
terminate
-
Field Details
-
eventManager
The event manager this source is a plugin of, which provides the sessions. -
registry
The registry of this source, which provides the process manager of an instance. -
factory
The factory creating the time schedule and the scheduled start of the start. -
executionManager
The execution manager naming the process manager of an instance. -
conf
The configuration of the event manager, which holds the start and its state. -
processStart
The scheduled process start of this source. -
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;nulluntil the first run of this source has read the state. -
lastInstance
The ID of the instance which the last successful trigger of the start has started,nullif no trigger has started one. -
step
The step of the next run,nullif this source does not run any more. -
nextRun
The time of the next run,nullif this source does not run any more. -
dueTime
The due time which the next run triggers if its step isScheduledProcessStartSource.Step.TRIGGER. -
pending
protected boolean pendingWhether 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
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, aServiceNotKnownExceptionwill be thrown.
-
-
Method Details
-
setConfiguration
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 beforeRunnable.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:
setConfigurationin interfaceEventSource<TimeScheduleEvent>- Overrides:
setConfigurationin classAbstractEventSource<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 benulldepends on the implementation of the event source.id- The ID of this event source. This must not benullnor the empty string.- Throws:
ConfigurationException- If there are problems with the designated configuration (configuration isnullalthough this is not allowed, a required configuration value is missing, ...), aConfigurationExceptionwill be thrown.
-
getNextRunTime
Description copied from interface:ScheduledSourceGets 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:
getNextRunTimein interfaceScheduledSource<TimeScheduleEvent>- Returns:
- The time at which this source is to run next or
nullif it has ended and is not to run any more.
-
checkForAndHandleEvent
protected void checkForAndHandleEvent()Description copied from class:AbstractEventSourceChecks for an event and handles it (usually by usingAbstractEventSource.forwardEvent(Event, boolean, boolean)).- Specified by:
checkForAndHandleEventin classAbstractEventSource<TimeScheduleEvent>
-
nextHandler
Description copied from class:AbstractEventSourceThis 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:
nextHandlerin classAbstractEventSource<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
falsehere.
-
toString
Returns the hierarchical name of this source, which the event manager names when it logs about the runs 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
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 ornullif the start has none, which ends this source.
-
getFirstDueTimeAfter
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
nullif there is none.
-
getGridIndexAfter
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
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
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.
-