Class AbstractLongRunningListener

  • All Implemented Interfaces:
    PostCommitEventListener, PostCommitFilteringEventListener

    public abstract class AbstractLongRunningListener
    extends Object
    implements PostCommitFilteringEventListener
    Abstract class that helps building an Asynchronous listeners that will handle a long running process.

    By default, PostCommitEventListener are executed in a Work that will take care of starting/comitting the transaction.

    If the listener requires a long processing this will create long transactions that are not good. To avoid this behavior, this base class split the processing in 3 steps :

    • pre processing : transactional first step
    • long running : long running processing that should not require transactional resources
    • post processing : transactional final step

    To manage sharing between the 3 steps, a simple Map is provided.

    Since:
    5.7.2
    Author:
    Tiry
    • Field Detail

      • log

        protected static final Log log
    • Method Detail

      • handleEventPreprocessing

        protected abstract boolean handleEventPreprocessing​(EventBundle events,
                                                            Map<String,​Object> data)
        Handles first step of processing in a normal transactional way.
        Parameters:
        events - EventBundle received
        data - an empty map to store data to share data between steps.
        Returns:
        true of processing should continue, false otherwise
      • handleEventLongRunning

        protected abstract boolean handleEventLongRunning​(List<String> eventNames,
                                                          Map<String,​Object> data)
        Will be executed in a non transactional context

        Any access to a CoreSession will generate WARN in the the logs.

        Documents passed with data should not be connected.

        Parameters:
        eventNames - list of event names
        data - an map that may have been filled by handleEventPreprocessing
        Returns:
        true of processing should continue, false otherwise
      • handleEventPostprocessing

        protected abstract void handleEventPostprocessing​(EventBundle events,
                                                          Map<String,​Object> data)
        Finish processing in a dedicated Transaction
        Parameters:
        events - EventBundle received
        data - an map that may have been filled by handleEventPreprocessing and handleEventLongRunning