Class AbstractInstanceStartEventHandler<T extends Event>
- java.lang.Object
-
- de.aristaflow.adept2.core.eventmanager.common.AbstractEventHandler
-
- de.aristaflow.adept2.core.eventmanager.common.AbstractInstanceStartEventHandler<T>
-
- Type Parameters:
T- The type of the handled event.
- All Implemented Interfaces:
EventHandler
- Direct Known Subclasses:
InstanceStartEventHandler,InstanceStartEventHandler
@ConfigurationDescription(properties={@Property(name="IsCritical",type=BOOLEAN,defaultValue="true",description="Whether the event handler is critical and problems handling the event should abort all handling of the current event."),,}) public abstract class AbstractInstanceStartEventHandler<T extends Event> extends AbstractEventHandler
This class provides the basic means for an instance start event handler, that is, providing the attributes of anEventHandleras well as retrieving the "latest" template to instantiate and let subclasses check for its input parameters. It also creates an instance after subclasses have handled the event, that is, created the appropriate input data filled with data from the event.
-
-
Field Summary
Fields Modifier and Type Field Description static StringCONF_CHECK_TEMPLATE_ON_STARTUPConfiguration key: Whether to ensure that the template exists during startup.protected static StringCONF_IS_CRITICALConfiguration key: Whether the event handler is critical and problems handling the event should abort all handling of the current event.static StringCONF_PROCESS_TYPEConfiguration key: The process type of which to start the "latest" template in case the appropriate event occurs.protected AbstractEventManagereventManagerThe event manager for communicating with the runtime service.protected Class<T>eventTypeThe class representing the event type handled by this class.protected StringprocessTypeThe process type of which to start the "latest" template in case the appropriate event occurs.protected TemplateReferencetemplateThe template which to instantiate in case an appropriate mail event occurs.-
Fields inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventHandler
consuming, critical, exclusive, id, interruptible, logger
-
-
Constructor Summary
Constructors Constructor Description AbstractInstanceStartEventHandler(org.apache.commons.configuration2.Configuration conf, boolean exclusive, boolean consuming, Class<T> eventType, AbstractEventManager eventManager, Registry registry)Creates a new event handler starting instances having the designated ID and the designated flags.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidcheckInputParameter(TemplateReference templ, Collection<ProcessModelParameter> inParams)Checks for whether the designated template has the right input parameters.protected TemplateReferencegetAndCheckTemplate(SessionToken session)Retrieves the "latest" template of the configured process type and checks for whether it has the right input parameter.booleanhandleEvent(Event eve, boolean consumed)This method actually processes an event.protected abstract voidprocessEvent(T event, Collection<ProcessModelParameter> inParams, InstanceDataContainer dc)Processes the designated event and sets the values of the input parameters in the designated data container.-
Methods inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventHandler
getID, isConsuming, isCritical, isExclusive, isInterruptible
-
-
-
-
Field Detail
-
CONF_IS_CRITICAL
protected static final String CONF_IS_CRITICAL
Configuration key: Whether the event handler is critical and problems handling the event should abort all handling of the current event.- See Also:
- Constant Field Values
-
CONF_PROCESS_TYPE
public static final String CONF_PROCESS_TYPE
Configuration key: The process type of which to start the "latest" template in case the appropriate event occurs.- See Also:
- Constant Field Values
-
processType
protected final String processType
The process type of which to start the "latest" template in case the appropriate event occurs.
-
CONF_CHECK_TEMPLATE_ON_STARTUP
public static final String CONF_CHECK_TEMPLATE_ON_STARTUP
Configuration key: Whether to ensure that the template exists during startup.- See Also:
- Constant Field Values
-
template
protected TemplateReference template
The template which to instantiate in case an appropriate mail event occurs. This will be temporarily set tonullif there are problems instantiating it.
-
eventManager
protected final AbstractEventManager eventManager
The event manager for communicating with the runtime service.
-
-
Constructor Detail
-
AbstractInstanceStartEventHandler
public AbstractInstanceStartEventHandler(org.apache.commons.configuration2.Configuration conf, boolean exclusive, boolean consuming, Class<T> eventType, AbstractEventManager eventManager, Registry registry) throws ConfigurationExceptionCreates a new event handler starting instances having the designated ID and the designated flags. If the handler is consuming or critical, it will also be exclusive.- Parameters:
conf- The configuration for this plugin instance.exclusive- Whether this handler needs to handle events exclusively. If this handler is consuming or critical, this parameter will be ignored.consuming- Whether this handler may consume events. If the handler is consuming, it is also exclusive.eventType- The class representing the event type handled by this class.eventManager- The event manager for starting the process instance.registry- The registry to get the ID of this handler (the simple name of the plugin instance).- Throws:
ConfigurationException- If there are problems retrieving the template of the configured process type or this template does not have the required input parameters, aConfigurationExceptionwill be thrown.
-
-
Method Detail
-
getAndCheckTemplate
protected TemplateReference getAndCheckTemplate(SessionToken session) throws InvalidDataTypeException, NoSuchParameterException, ConfigurationException
Retrieves the "latest" template of the configured process type and checks for whether it has the right input parameter.- Parameters:
session- The session token used to retrieve the "latest" template.- Returns:
- The "latest" template of the configured process type or
nullin case the process type does not have a template. - Throws:
InvalidDataTypeException- If the template has an input parameter mapping to a wrong type with respect to the event type, anInvalidDataTypeExceptionwill be thrown.NoSuchParameterException- If the template is missing an input parameter that is required for event handling or it has a mandatory input parameter that cannot be supplied by the event type, aNoSuchParameterExceptionwill be thrown.ConfigurationException- If there are other problems, they will be wrapped in aConfigurationExceptionwhich will be directly forwarded.
-
checkInputParameter
protected abstract void checkInputParameter(TemplateReference templ, Collection<ProcessModelParameter> inParams) throws InvalidDataTypeException, NoSuchParameterException, ConfigurationException
Checks for whether the designated template has the right input parameters. An input parameter having the right name for a file event must be of the right data type and there must not be any mandatory input parameter that do not have an appropriate file event name.- Parameters:
templ- The template reference found as "latest" template of the configured process type.inParams- The input parameters of the designated template.- Throws:
InvalidDataTypeException- If the template has an input parameter mapping to a wrong type with respect to the event type, anInvalidDataTypeExceptionwill be thrown.NoSuchParameterException- If the template is missing an input parameter that is required for event handling or it has a mandatory input parameter that cannot be supplied by the event type, aNoSuchParameterExceptionwill be thrown.ConfigurationException- If there are other problems, they will be wrapped in aConfigurationExceptionwhich will be directly forwarded.
-
handleEvent
public boolean handleEvent(Event eve, boolean consumed) throws EventHandlingException
Description copied from interface:EventHandlerThis 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!- Parameters:
eve- 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). - Throws:
EventHandlingException- If there have been problems handling the event, anEventHandlingExceptionmay be thrown. If this is critical, the event handling for the current event will stop. If it is non-critical, other event handlers will also get the event for handling it.
If event handling fails, the corresponding event handler needs to roll back its changes, especially a consuming event handler.
-
processEvent
protected abstract void processEvent(T event, Collection<ProcessModelParameter> inParams, InstanceDataContainer dc) throws Exception
Processes the designated event and sets the values of the input parameters in the designated data container.- Parameters:
event- The event which to process and which provides the values for the input parameters.inParams- The input parameters of the template.dc- The data container of the template in which to set the values.- Throws:
Exception- If there are problems handling the event, an arbitrary exception will be thrown leading to appropriate exception handling. This is usually aborting event handling and removing the loaded template so that it gets re-loaded.
-
-