Class MarkInstanceStartEventHandler
- java.lang.Object
-
- de.aristaflow.adept2.core.eventmanager.common.AbstractEventHandler
-
- de.aristaflow.adept2.core.eventmanager.fileevents.FileMarkHandler
-
- de.aristaflow.adept2.core.eventmanager.fileevents.MarkInstanceStartEventHandler
-
- All Implemented Interfaces:
EventHandler
@ConfigurationDescription(properties=) public class MarkInstanceStartEventHandler extends FileMarkHandler
An event handler for file events, that marks the files (rename, move) and afterwards stores data from an occurred file event as input parameters in the data container of an instance and starts this instance afterwards. When marking the file via deletion, this will take place after starting the instance. Make sure to provide the complete file to the process instance and not just a reference (URI). This reference will be invalid after deleting the file! This does not apply to renaming or moving since this takes place beforehand and therefore the reference will be for after remaining or moving.
The input parameters need to have specific names to allow for setting the values according to the file.
This handler considers a changed file as consumed.
NOTE: This is a combination ofFileMarkHandlerandInstanceStartEventHandler.
-
-
Field Summary
Fields Modifier and Type Field Description 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.static StringPARAM_FILEProcess parameter name for the file.static StringPARAM_FILENAMEProcess parameter name for the file name.static StringPARAM_LOCK_FILEProcess parameter name for the lock file.static StringPARAM_MODIFIED_DATEProcess parameter name for the file name.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.fileevents.FileMarkHandler
ADD_FILE, CONF_ADD_FILE, CONF_DELETE_FILE, CONF_HANDLE_CONSUMED, CONF_IS_CRITICAL, CONF_MARK_LOCK_FILE, CONF_MOVE_FILE, CONF_RENAME_FILE, CONF_REPLACE_EXISTING, CONF_TARGET_FOLDER, CONF_TARGET_NAME, DELETE_FILE, HANDLE_CONSUMED, MARK_LOCK_FILE, MOVE_FILE, RENAME_FILE, REPLACE_EXISTING, TARGET_FOLDER, TARGET_NAME
-
Fields inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventHandler
consuming, critical, exclusive, id, interruptible, logger
-
-
Constructor Summary
Constructors Constructor Description MarkInstanceStartEventHandler(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 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 voidprocessFileEvent(FileEvent event, Collection<? extends Parameter> inParams, InstanceDataContainer dataContainer, File file, File lockFile)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.fileevents.FileMarkHandler
markFile
-
Methods inherited from class de.aristaflow.adept2.core.eventmanager.common.AbstractEventHandler
getID, isConsuming, isCritical, isExclusive, isInterruptible
-
-
-
-
Field Detail
-
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 tonullif 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
-
MarkInstanceStartEventHandler
public MarkInstanceStartEventHandler(org.apache.commons.configuration2.Configuration conf, AbstractEventManager eventManager, Registry registry) throws ConfigurationExceptionCreates 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, aConfigurationExceptionwill be thrown.
-
-
Method Detail
-
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!- Specified by:
handleEventin interfaceEventHandler- Overrides:
handleEventin classFileMarkHandler- 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.
-
getAndCheckTemplate
protected TemplateReference getAndCheckTemplate(SessionToken session) throws de.aristaflow.adept2.core.eventmanager.fileevents.MarkInstanceStartEventHandler.TemplateLoadingException
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
nullin case the process type does not have a template. - Throws:
de.aristaflow.adept2.core.eventmanager.fileevents.MarkInstanceStartEventHandler.TemplateLoadingException- If the template has an input parameter mapping to a file event (due to its name) but has the wrong type or it has a mandatory input parameter that does not map to a file event, aTemplateLoadingExceptionwill be thrown.
-
processFileEvent
protected void processFileEvent(FileEvent event, Collection<? extends Parameter> inParams, InstanceDataContainer dataContainer, File file, File lockFile) 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, anInvalidDataTypeExceptionwill be thrown.NoSuchParameterException- If writing to the data container fails due to a provided input parameter not being in the data container, aNoSuchParameterExceptionwill be thrown.IOException- If creating the value for an UDT fails, anIOExceptionwill be thrown.
-
-