Class ProcessingContext<T>

  • Type Parameters:
    T - the type of the processing Channel

    public final class ProcessingContext<T>
    extends Object
    Message specific root object for all information related to the processing of a message.

    Each ProcessingContext envelopes the sent message. The message can be accesses with the getPayload() and #setPayload(T) setPayload() methods. All Actions and Filter get access to the ProcessingContext object. This allows them to share data using the ProcessingContext's context meta date object. It is a Map<Object, Object, that can be accessed with getContextMetaData().

    In case several Channels are chained together, a message traverses different channel in a specific order. The transitions are handled via Actions. Given such a chained Channel scenario, the history can be of interest. The history is represented in form of a linked list of ChannelProcessingFrames. For each traversed Channel, a new ChannelProcessingFrame is added at the end of the list. Once the final Action is reached, it is also saved in the frame. The ProcessingContext object gives access to the initial ChannelProcessingFrame with getInitialProcessingFrame(). The frame of the current Channel ( or last if outside of one), can be accessed with getCurrentProcessingFrame(). An exception is the Call Action. This Action is always executed once it was created and will never be the final action of a Channel. In case a Call is executed, an extra ChannelProcessingFrame is added with the Call Action, to represent the branching of the flow. All subsequent Channel will be contained normally in the list of frames.

    See Also:
    EventMaid Documentation
    • Method Detail

      • processingContext

        public static <T> ProcessingContext<T> processingContext​(EventType eventType,
                                                                 T payload)
        Factory method to create a new ProcessingContext.
        Type Parameters:
        T - the type of the message
        Parameters:
        eventType - the event type of the message
        payload - the message itself
        Returns:
        the newly created ProcessingContext
      • processingContext

        public static <T> ProcessingContext<T> processingContext​(EventType eventType,
                                                                 MessageId messageId,
                                                                 T payload)
        Factory method to create a new ProcessingContext.
        Type Parameters:
        T - the type of the message
        Parameters:
        eventType - the event type of the message
        messageId - the unique MessageId of the message
        payload - the message itself
        Returns:
        the newly created ProcessingContext
      • processingContext

        public static <T> ProcessingContext<T> processingContext​(EventType eventType,
                                                                 T payload,
                                                                 CorrelationId correlationId)
        Factory method to create a new ProcessingContext.
        Type Parameters:
        T - the type of the message
        Parameters:
        eventType - the event type of the message
        payload - the message itself
        correlationId - the CorrelationId identifying related messages
        Returns:
        the newly created ProcessingContext
      • processingContext

        public static <T> ProcessingContext<T> processingContext​(EventType eventType,
                                                                 MessageId messageId,
                                                                 CorrelationId correlationId,
                                                                 T payload,
                                                                 Object errorPayload)
        Factory method to create a new ProcessingContext.
        Type Parameters:
        T - the type of the message
        Parameters:
        eventType - the event type of the message
        messageId - the unique MessageId of the message
        correlationId - the CorrelationId identifying related messages
        payload - the message itself
        errorPayload - an additional error message
        Returns:
        the newly created ProcessingContext
      • processingContext

        public static <T> ProcessingContext<T> processingContext​(EventType eventType,
                                                                 MessageId messageId,
                                                                 CorrelationId correlationId,
                                                                 T payload,
                                                                 Object errorPayload,
                                                                 Map<Object,​Object> contextMetaData,
                                                                 ChannelProcessingFrame<T> initialProcessingFrame,
                                                                 ChannelProcessingFrame<T> currentProcessingFrame)
        Factory method to create a new ProcessingContext.
        Type Parameters:
        T - the type of the message
        Parameters:
        eventType - the event type of the message
        messageId - the unique MessageId of the message
        correlationId - the CorrelationId identifying related messages
        payload - the message itself
        errorPayload - an additional error message
        contextMetaData - a Map containing additional data of the messages's processing
        initialProcessingFrame - the ChannelProcessingFrame identifying the first Channel
        currentProcessingFrame - the ChannelProcessingFrame identifying the current Channel
        Returns:
        the newly created ProcessingContext
      • processingContextForError

        public static <T> ProcessingContext<T> processingContextForError​(EventType eventType,
                                                                         Object errorPayload)
        Factory method to create a new ProcessingContext.
        Type Parameters:
        T - the type of the message
        Parameters:
        eventType - the event type of the message
        errorPayload - an additional error message
        Returns:
        the newly created ProcessingContext
      • processingContextForPayloadAndError

        public static <T> ProcessingContext<T> processingContextForPayloadAndError​(EventType eventType,
                                                                                   T payload,
                                                                                   Object errorPayload)
        Factory method to create a new ProcessingContext.
        Type Parameters:
        T - the type of the message
        Parameters:
        eventType - the event type of the message
        payload - the message itself
        errorPayload - an additional error message
        Returns:
        the newly created ProcessingContext
      • processingContextForPayloadAndError

        public static <T> ProcessingContext<T> processingContextForPayloadAndError​(EventType eventType,
                                                                                   CorrelationId correlationId,
                                                                                   T payload,
                                                                                   Object errorPayload)
        Factory method to create a new ProcessingContext.
        Type Parameters:
        T - the type of the message
        Parameters:
        eventType - the event type of the message
        correlationId - the CorrelationId identifying related messages
        payload - the message itself
        errorPayload - an additional error message
        Returns:
        the newly created ProcessingContext
      • actionWasChanged

        public boolean actionWasChanged()
        Returns, whether the default Action was overwritten for the current Channel
        Returns:
        true if the Action was changed and false otherwise
      • getAction

        public Action<T> getAction()
        Returns the Action, that overwrites the default one, if existing.
        Returns:
        the changed Action or null of no new Action was set
      • changeAction

        public void changeAction​(Action<T> action)
        Overwrites the Channel's default Action.

        At the end of the current Channel not the default Action is executed anymore. Instead the overwriting Action is executed.

        Parameters:
        action - the new Action
      • generateCorrelationIdForAnswer

        public CorrelationId generateCorrelationIdForAnswer()
        Creates a CorrelationId matching the current ProcessingContext'sMessageId.
        Returns:
        a new, related CorrelationId
      • getEventType

        public EventType getEventType()
      • getMessageId

        public MessageId getMessageId()
      • setCorrelationId

        public void setCorrelationId​(CorrelationId correlationId)
      • getPayload

        public T getPayload()
      • setPayload

        public void setPayload​(T payload)
      • getErrorPayload

        public Object getErrorPayload()
      • setErrorPayload

        public void setErrorPayload​(Object errorPayload)
      • setInitialProcessingFrame

        public void setInitialProcessingFrame​(ChannelProcessingFrame<T> initialProcessingFrame)
      • setCurrentProcessingFrame

        public void setCurrentProcessingFrame​(ChannelProcessingFrame<T> currentProcessingFrame)