Class InstanceStartEventHandler
java.lang.Object
de.aristaflow.adept2.core.eventmanager.common.AbstractEventHandler
de.aristaflow.adept2.core.eventmanager.timeevents.InstanceStartEventHandler
- All Implemented Interfaces:
EventHandler
The handler which executes the triggers of scheduled process starts. For the event of a due time,
it starts an instance of the template of the start with the input values of the start, in the
session of the event manager, whose agent thereby becomes the initiator of the instance. It skips
the due time if the start has a fixed rate without overlap and its last instance still runs, if
its process reference resolves to no template which is released, instantiable, top-level usable
and not outdated, or if a mandatory input parameter of the template has no value; a value which
the template does not accept is dropped with a warning. A start refused for one of these reasons
or for the starter rule skips the due time as well, while any other exception fails the attempt,
which is retried at once up to the retry count of the start.
The handler sets the outcome of the trigger on the event and throws no critical exception, so that the schedule of the start continues.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AbstractEventManagerThe event manager of this handler, which provides the sessions and starts the instances.protected final ExecutionManagerThe execution manager naming the process manager of an instance.protected final RegistryThe registry of this handler, which provides the process manager of an instance.Fields inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventHandler
consuming, critical, exclusive, id, interruptible, logger -
Constructor Summary
ConstructorsConstructorDescriptionInstanceStartEventHandler(Configuration conf, AbstractEventManager eventManager, Registry registry) Creates the handler executing the triggers of scheduled process starts as a plugin of the designated event manager, called by a service registry. -
Method Summary
Modifier and TypeMethodDescriptionprotected TemplateReferencegetTemplate(SessionToken session, ScheduledProcessStartEvent event) Gets the template which the start of the designated event starts an instance of: the template of its template ID if it is released, instantiable, top-level usable and not outdated, or the latest template of its process type in this state.protected Map<String,Serializable> getValues(ScheduledProcessStartEvent event, TemplateReference template) Gets the input values of the start of the designated event which the designated template accepts.booleanhandleEvent(Event event, boolean consumed) This method actually processes an event.protected booleanisOverlapping(SessionToken session, ScheduledProcessStartEvent event) Gets whether the instance of the designated event would overlap the last instance of its start, which the start does not allow: whether the start has a fixed rate without overlap and its last instance still runs, a vanished instance running no more.protected voidskipRefused(ScheduledProcessStartEvent event, Exception refusal) Logs the skip of the due time of the designated event, whose start of an instance the designated exception has refused, unless the exception reports a lock conflict while the instance is created, which fails the attempt instead.protected UUIDstart(SessionToken session, ScheduledProcessStartEvent event, TemplateReference template, Map<String, Serializable> values) Starts an instance for the designated event with the designated input values: for a template ID an instance of the designated template, for a process type an instance of its latest template, which the start resolves again.protected UUIDstartProcessType(SessionToken session, ScheduledProcessStartEvent event, Map<String, Serializable> values) Starts an instance of the latest template of the process type of the start of the designated event with the designated input values.protected UUIDstartTemplate(SessionToken session, ScheduledProcessStartEvent event, TemplateReference template, Map<String, Serializable> values) Starts an instance of the designated template for the designated event with the designated input values in a data container, which is closed afterwards.protected voidExecutes the trigger of the designated event and sets its outcome on the event.Methods inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventHandler
getID, isConsuming, isCritical, isExclusive, isInterruptible
-
Field Details
-
eventManager
The event manager of this handler, which provides the sessions and starts the instances. -
registry
The registry of this handler, which provides the process manager of an instance. -
executionManager
The execution manager naming the process manager of an instance.
-
-
Constructor Details
-
InstanceStartEventHandler
public InstanceStartEventHandler(Configuration conf, AbstractEventManager eventManager, Registry registry) throws ServiceNotKnownException Creates the handler executing the triggers of scheduled process starts as a plugin of the designated event manager, called by a service registry.- Parameters:
conf- The configuration as provided from the registry, which this handler does not use.eventManager- The event manager this handler is a plugin of.registry- The registry of this plugin.- Throws:
ServiceNotKnownException- If the execution manager cannot be retrieved, aServiceNotKnownExceptionwill be thrown.
-
-
Method Details
-
handleEvent
This method actually processes an event. What is done depends on the implementation of the event handler. Some restrictions may apply depending on the produced event. Only events will be received for which the event handler is registered. However, to improve robustness, an event handler should check the event before processing. If it cannot handle the provided event, this method should just return.
Event handling is usually synchronously, that is, this method will only be executed by one thread at a time. If another event of the same type occurs while still handling the previous event, the second event will be suspended until the previous event has been completely handled. There is no need to start a separate thread while handling to improve performance. But it is not forbidden to do so. Handling that takes place in a new thread is not exclusive any more and therefore must not consume the event!The trigger of an event of a scheduled process start which has not been consumed is executed, and its outcome is set on the event. This method throws no
EventHandlingException.- Parameters:
event- The event that occurred and for which this event handler is registered.consumed- Whether the event has been consumed by a previous event handler.- Returns:
- Whether the event has been consumed (that is changed) while
handling it. If the event has been consumed before the current
handing, it will have to remain consumed (implementations must
return
true).
-
trigger
Executes the trigger of the designated event and sets its outcome on the event. A failed attempt is retried at once up to the retry count of the start, and a retry repeats the steps which the failed attempt has not completed: the checks if they have failed, otherwise the start.- Parameters:
event- The event of the scheduled process start whose trigger to execute.
-
isOverlapping
protected boolean isOverlapping(SessionToken session, ScheduledProcessStartEvent event) throws ServiceNotKnownException Gets whether the instance of the designated event would overlap the last instance of its start, which the start does not allow: whether the start has a fixed rate without overlap and its last instance still runs, a vanished instance running no more. A due time with such an overlap is skipped and logged.- Parameters:
session- The session of the event manager.event- The event of the scheduled process start whose due time to check.- Returns:
- Whether the instance of the designated event would overlap the last instance of its start, which the start does not allow.
- Throws:
ServiceNotKnownException- If the process manager holding the last instance cannot be retrieved, aServiceNotKnownExceptionwill be thrown.
-
getTemplate
Gets the template which the start of the designated event starts an instance of: the template of its template ID if it is released, instantiable, top-level usable and not outdated, or the latest template of its process type in this state. A due time without such a template is skipped and logged.- Parameters:
session- The session of the event manager.event- The event of the scheduled process start whose template to get.- Returns:
- The template to start an instance of or
nullif there is none, so that the due time is skipped.
-
getValues
protected Map<String,Serializable> getValues(ScheduledProcessStartEvent event, TemplateReference template) Gets the input values of the start of the designated event which the designated template accepts. A value which the template does not accept is dropped and logged as a warning, and a due time with a mandatory input parameter of the template without a value is skipped and logged.- Parameters:
event- The event of the scheduled process start whose input values to get.template- The template to start an instance of.- Returns:
- The input values to start the instance with, indexed by the names of their input
parameters, or
nullif a mandatory input parameter has no value, so that the due time is skipped.
-
start
protected UUID start(SessionToken session, ScheduledProcessStartEvent event, TemplateReference template, Map<String, Serializable> values) throws InvalidTemplateStateException, InvalidDataTypeExceptionStarts an instance for the designated event with the designated input values: for a template ID an instance of the designated template, for a process type an instance of its latest template, which the start resolves again. A start refused by an exception which repeats one of the checks of this handler or refuses the starter rule skips the due time and is logged.- Parameters:
session- The session of the event manager, in which the instance is started.event- The event of the scheduled process start whose instance to start.template- The template which the process reference of the start resolves to.values- The input values to start the instance with, indexed by the names of their input parameters.- Returns:
- The ID of the started instance or
nullif the start has been refused, so that the due time is skipped. - Throws:
InvalidTemplateStateException- If the instance cannot be created due to a lock conflict, anInvalidTemplateStateExceptionwill be thrown.InvalidDataTypeException- If the data container of a template ID refuses a value of another type, anInvalidDataTypeExceptionwill be thrown.
-
startTemplate
protected UUID startTemplate(SessionToken session, ScheduledProcessStartEvent event, TemplateReference template, Map<String, Serializable> values) throws InvalidTemplateStateException, InvalidDataTypeExceptionStarts an instance of the designated template for the designated event with the designated input values in a data container, which is closed afterwards.- Parameters:
session- The session of the event manager, in which the instance is started.event- The event of the scheduled process start whose instance to start.template- The template of which to start an instance.values- The input values to start the instance with, indexed by the names of their input parameters.- Returns:
- The ID of the started instance or
nullif the start has been refused, so that the due time is skipped. - Throws:
InvalidTemplateStateException- If the instance cannot be created due to a lock conflict, anInvalidTemplateStateExceptionwill be thrown.InvalidDataTypeException- If the data container refuses a value of another type, anInvalidDataTypeExceptionwill be thrown.
-
startProcessType
protected UUID startProcessType(SessionToken session, ScheduledProcessStartEvent event, Map<String, Serializable> values) throws InvalidTemplateStateExceptionStarts an instance of the latest template of the process type of the start of the designated event with the designated input values. The start resolves the latest template again and creates and closes the data container itself, except that the caller closes the data container of a start refused for its values.- Parameters:
session- The session of the event manager, in which the instance is started.event- The event of the scheduled process start whose instance to start.values- The input values to start the instance with, indexed by the names of their input parameters.- Returns:
- The ID of the started instance or
nullif the start has been refused, so that the due time is skipped. - Throws:
InvalidTemplateStateException- If the instance cannot be created due to a lock conflict, anInvalidTemplateStateExceptionwill be thrown.
-
skipRefused
protected void skipRefused(ScheduledProcessStartEvent event, Exception refusal) throws InvalidTemplateStateException Logs the skip of the due time of the designated event, whose start of an instance the designated exception has refused, unless the exception reports a lock conflict while the instance is created, which fails the attempt instead.- Parameters:
event- The event of the scheduled process start whose start has been refused.refusal- The exception refusing the start.- Throws:
InvalidTemplateStateException- If the designated exception reports a lock conflict while the instance is created, anInvalidTemplateStateExceptionwill be thrown.
-