Class AddSourceRunnable

  • All Implemented Interfaces:
    Runnable

    public class AddSourceRunnable
    extends Object
    implements Runnable
    A Runnable for adding an event source for a specific worklist item. Since problems when adding an event source are rather common, this AddSourceRunnable reschedules itself for retrying several times.
    The number of retries as well as the time between retries can be configured per activity. If an activity configuration does not provide a corresponding value, the defaults configured for the event manager will be used. If all retries have been unsuccessful, the activity will be failed.
    • Field Detail

      • EVENT_SOURCE_ADDING_FAILED_STATE

        public static final String EVENT_SOURCE_ADDING_FAILED_STATE
        State for adding the event source failed finally.
        See Also:
        Constant Field Values
      • EVENT_SOURCE_ADDING_FAILED_CODE

        public static final long EVENT_SOURCE_ADDING_FAILED_CODE
        Code for adding the event source failed finally.
        See Also:
        Constant Field Values
      • logger

        protected final Logger logger
        The logger of this runnable.
      • worklistItem

        protected final ClientWorklistItem worklistItem
        The worklist item for which to add an event source.
      • handler

        protected final de.aristaflow.adept2.core.automaticclient.AbstractWorklistHandler handler
        The worklist handler for re-retrieving the worklist item.
      • runningItems

        protected final Map<EBPInstanceReference,​Triple<String,​String,​String>> runningItems
        The activities currently being added and the ones currently being polled. The EBP instance references are mapped to the corresponding execution session. The execution session will be null while the event source is being added for the corresponding activity.
      • eventManager

        protected final AbstractEventManager eventManager
        The event manager which to use for starting and selecting the activity as well as eventually adding the event source.
      • retryDelay

        protected long retryDelay
        The time in milliseconds before retrying to add the event source.
        This will be set to the value configured for the event manager until the activity configuration is available. Afterwards it will use the value from the activity configuration if this provides a value.
      • currentRun

        protected int currentRun
        The number of times the event source has been tried to add. This is incremented before a try to add the event source.
      • retries

        protected int retries
        The maximum number of tries to add the event source before the corresponding activity will be failed.
        This will be set to the value configured for the event manager until the activity configuration is available. Afterwards it will use the value from the activity configuration if this provides a value.
    • Constructor Detail

      • AddSourceRunnable

        public AddSourceRunnable​(ClientWorklistItem item,
                                 int retries,
                                 long retryDelay,
                                 de.aristaflow.adept2.core.automaticclient.AbstractWorklistHandler handler,
                                 Map<EBPInstanceReference,​Triple<String,​String,​String>> runningItems,
                                 ScheduledObjectOneWorkExecutor<WorklistItem> executor,
                                 AbstractEventManager eventManager,
                                 LogService logService)
        Creates a new AddSourceRunnable for adding event sources for specific worklist items.
        Parameters:
        item - The worklist item for which to add an event source.
        retries - The maximum number of tries to add the event source before the corresponding activity will be failed.
        retryDelay - The time in milliseconds before retrying to add the event source.
        handler - The worklist handler for re-retrieving the worklist item.
        runningItems - The activities currently having an event source or of which the event source is currently being added.
        executor - The poll service for rescheduling event source adders in case adding the event source fails (again).
        eventManager - The event manager which to use for starting and selecting the activity as well as eventually adding the event source.
        logService - The log service to retrieve the logger from.
    • Method Detail

      • run

        public void run()
        Specified by:
        run in interface Runnable
      • addEventSource

        protected Triple<Throwable,​Integer,​Long> addEventSource​(WorklistItem item)
        Adds an event source for the designated worklist item, that is the session context of the activity is retrieved by starting or resuming the item, an event source is created by the appropriate event manager and the event handler is initialised and added.
        If there is already a source for a specific worklist item, this method will just return null. In case of an exception, the exception is logged and returned. Additionally, if the activity configuration provides values for retrying to add the event source, these values will also be returned.
        Parameters:
        item - The worklist item for which to add an event source.
        Returns:
        The throwable that occurred while adding the event source and configuration values for the retry count and the retry delay if present. The retry configuration values are only required in case adding fails and we have a throwable. However, they will be null if they are not provided by the activity configuration.
        If the worklist item already has an event source, null will be returned.