Class 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 of FileMarkHandler and InstanceStartEventHandler.
  • Field Details

    • CONF_PROCESS_TYPE

      @Deprecated(since="16.1.0", forRemoval=true) public static final String CONF_PROCESS_TYPE
      Deprecated, for removal: This API element is subject to removal in a future version.
      Configuration key: The process type of which to start the "latest" template in case the appropriate event occurs.
      See Also:
    • 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 to null 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:
    • PARAM_MODIFIED_DATE

      public static final String PARAM_MODIFIED_DATE
      Process parameter name for the file name.
      See Also:
    • PARAM_FILE

      public static final String PARAM_FILE
      Process parameter name for the file.
      See Also:
    • PARAM_LOCK_FILE

      public static final String PARAM_LOCK_FILE
      Process parameter name for the lock file.
      See Also:
  • Constructor Details

    • MarkInstanceStartEventHandler

      public MarkInstanceStartEventHandler(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, a ConfigurationException will be thrown.
  • Method Details

    • 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!
      Specified by:
      handleEvent in interface EventHandler
      Overrides:
      handleEvent in class FileMarkHandler
      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, an EventHandlingException 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 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 null in 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, a TemplateLoadingException will 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, an InvalidDataTypeException will be thrown.
      NoSuchParameterException - If writing to the data container fails due to a provided input parameter not being in the data container, a NoSuchParameterException will be thrown.
      IOException - If creating the value for an UDT fails, an IOException will be thrown.