Class InstanceStartEventHandler
- java.lang.Object
-
- de.aristaflow.adept2.core.eventmanager.common.AbstractEventHandler
-
- de.aristaflow.adept2.core.eventmanager.fileevents.InstanceStartEventHandler
-
- All Implemented Interfaces:
EventHandler
@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 class InstanceStartEventHandler extends AbstractEventHandler
An event handler for file events, that stores data from an occurred file event as input parameters in the data container of an instance and starts this instance afterwards.
The input parameters need to have specific names to allow for setting the values according to the file.
-
-
Field Summary
Fields Modifier and Type Field Description static 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.static String
CONF_PROCESS_TYPE
Configuration key: The process type of which to start the "latest" template in case the appropriate event occurs.protected AbstractEventManager
eventManager
The event manager for communicating with the runtime service.static String
PARAM_FILE
Process parameter name for the file.static String
PARAM_FILENAME
Process parameter name for the file name.static String
PARAM_LOCK_FILE
Process parameter name for the lock file.static String
PARAM_MODIFIED_DATE
Process parameter name for the file name.protected String
processType
The process type of which to start the "latest" template in case the appropriate event occurs.protected TemplateReference
template
The 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 InstanceStartEventHandler(org.apache.commons.configuration2.Configuration conf, AbstractEventManager eventManager, Registry registry)
Creates a new handler for file events that starts instances and stores data from the file in the instance input parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected TemplateReference
getAndCheckTemplate(SessionToken session)
Retrieves the "latest" template of the configured process type and checks for whether it has the right input parameter.boolean
handleEvent(Event eve, boolean consumed)
This method actually processes an event.protected void
processFileEvent(FileEvent event, Collection<? extends Parameter> inParams, InstanceDataContainer dataContainer)
Processes the file of 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
public 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.
-
template
protected TemplateReference template
The template which to instantiate in case an appropriate mail event occurs. This will be temporarily set tonull
if there are problems instantiating it.
-
eventManager
protected final AbstractEventManager eventManager
The event manager for communicating with the runtime service.
-
PARAM_FILENAME
public static final String PARAM_FILENAME
Process parameter name for the file name.- See Also:
- Constant Field Values
-
PARAM_MODIFIED_DATE
public static final String PARAM_MODIFIED_DATE
Process parameter name for the file name.- See Also:
- Constant Field Values
-
PARAM_FILE
public static final String PARAM_FILE
Process parameter name for the file.- See Also:
- Constant Field Values
-
PARAM_LOCK_FILE
public static final String PARAM_LOCK_FILE
Process parameter name for the lock file.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
InstanceStartEventHandler
public InstanceStartEventHandler(org.apache.commons.configuration2.Configuration conf, AbstractEventManager eventManager, Registry registry) throws ConfigurationException
Creates a new handler for file events that starts instances and stores data from the file in the instance input parameters.- Parameters:
conf
- The configuration for this plugin instance.eventManager
- The event manager for starting the process instance.registry
- The registry for retrieving the plugin instance name (handler ID).- Throws:
ConfigurationException
- If there are problems creating the configured file store or writing to it or the template cannot be retrieved or has the wrong input parameter, aConfigurationException
will be thrown.
-
-
Method Detail
-
handleEvent
public boolean handleEvent(Event eve, boolean consumed) throws EventHandlingException
Description copied from interface:EventHandler
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!- 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, anEventHandlingException
may 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.
-
getAndCheckTemplate
protected TemplateReference getAndCheckTemplate(SessionToken session) throws InvalidDataTypeException, NoSuchParameterException
Retrieves the "latest" template of the configured process type and checks for whether it has the right input parameter. 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:
session
- The session token used to retrieve the "latest" template.- Returns:
- The "latest" template of the configured process type or
null
in case the process type does not have a template. - Throws:
InvalidDataTypeException
- If the template has an input parameter mapping to a file event (due to its name) but has the wrong type, anInvalidDataTypeException
will be thrown.NoSuchParameterException
- If the template has a mandatory input parameter that does not map to a file event, aNoSuchParameterException
will be thrown.
-
processFileEvent
protected void processFileEvent(FileEvent event, Collection<? extends Parameter> inParams, InstanceDataContainer dataContainer) throws InvalidDataTypeException, NoSuchParameterException, IOException
Processes the file of 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.dataContainer
- The data container of the template in which to set the values.- Throws:
InvalidDataTypeException
- If writing to the data container fails due to a provided input parameter having another type in the data container or a parameter has a wrong user-defined type, anInvalidDataTypeException
will be thrown.NoSuchParameterException
- If writing to the data container fails due to a provided input parameter not being in the data container, aNoSuchParameterException
will be thrown.IOException
- If creating the value for an UDT fails, anIOException
will be thrown.
-
-