Class ProcessingContext<T>
- java.lang.Object
-
- de.quantummaid.eventmaid.processingcontext.ProcessingContext<T>
-
- Type Parameters:
T- the type of the processingChannel
public final class ProcessingContext<T> extends Object
Message specific root object for all information related to the processing of a message.Each
ProcessingContextenvelopes the sent message. The message can be accesses with thegetPayload()and#setPayload(T) setPayload()methods. AllActionsandFilterget access to theProcessingContextobject. This allows them to share data using theProcessingContext'scontext meta date object. It is aMap<Object, Object, that can be accessed withgetContextMetaData().In case several
Channelsare chained together, a message traverses different channel in a specific order. The transitions are handled viaActions. Given such a chainedChannelscenario, the history can be of interest. The history is represented in form of a linked list ofChannelProcessingFrames. For each traversedChannel, a newChannelProcessingFrameis added at the end of the list. Once the finalActionis reached, it is also saved in the frame. TheProcessingContextobject gives access to the initialChannelProcessingFramewithgetInitialProcessingFrame(). The frame of the currentChannel( or last if outside of one), can be accessed withgetCurrentProcessingFrame(). An exception is theCallAction. ThisActionis always executed once it was created and will never be the final action of aChannel. In case aCallis executed, an extraChannelProcessingFrameis added with theCallAction, to represent the branching of the flow. All subsequentChannelwill be contained normally in the list of frames.- See Also:
- EventMaid Documentation
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanactionWasChanged()Returns, whether the defaultActionwas overwritten for the currentChannelvoidchangeAction(Action<T> action)Overwrites theChannel'sdefaultAction.CorrelationIdgenerateCorrelationIdForAnswer()Creates aCorrelationIdmatching the currentProcessingContext'sMessageId.Action<T>getAction()Returns theAction, that overwrites the default one, if existing.Map<Object,Object>getContextMetaData()CorrelationIdgetCorrelationId()ChannelProcessingFrame<T>getCurrentProcessingFrame()ObjectgetErrorPayload()EventTypegetEventType()ChannelProcessingFrame<T>getInitialProcessingFrame()MessageIdgetMessageId()TgetPayload()static <T> ProcessingContext<T>processingContext(EventType eventType, MessageId messageId, CorrelationId correlationId, T payload, Object errorPayload)Factory method to create a newProcessingContext.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 newProcessingContext.static <T> ProcessingContext<T>processingContext(EventType eventType, MessageId messageId, T payload)Factory method to create a newProcessingContext.static <T> ProcessingContext<T>processingContext(EventType eventType, T payload)Factory method to create a newProcessingContext.static <T> ProcessingContext<T>processingContext(EventType eventType, T payload, CorrelationId correlationId)Factory method to create a newProcessingContext.static <T> ProcessingContext<T>processingContextForError(EventType eventType, Object errorPayload)Factory method to create a newProcessingContext.static <T> ProcessingContext<T>processingContextForPayloadAndError(EventType eventType, CorrelationId correlationId, T payload, Object errorPayload)Factory method to create a newProcessingContext.static <T> ProcessingContext<T>processingContextForPayloadAndError(EventType eventType, T payload, Object errorPayload)Factory method to create a newProcessingContext.voidsetCorrelationId(CorrelationId correlationId)voidsetCurrentProcessingFrame(ChannelProcessingFrame<T> currentProcessingFrame)voidsetErrorPayload(Object errorPayload)voidsetInitialProcessingFrame(ChannelProcessingFrame<T> initialProcessingFrame)voidsetPayload(T payload)
-
-
-
Method Detail
-
processingContext
public static <T> ProcessingContext<T> processingContext(EventType eventType, T payload)
Factory method to create a newProcessingContext.- Type Parameters:
T- the type of the message- Parameters:
eventType- the event type of the messagepayload- 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 newProcessingContext.- Type Parameters:
T- the type of the message- Parameters:
eventType- the event type of the messagemessageId- the uniqueMessageIdof the messagepayload- 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 newProcessingContext.- Type Parameters:
T- the type of the message- Parameters:
eventType- the event type of the messagepayload- the message itselfcorrelationId- theCorrelationIdidentifying 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 newProcessingContext.- Type Parameters:
T- the type of the message- Parameters:
eventType- the event type of the messagemessageId- the uniqueMessageIdof the messagecorrelationId- theCorrelationIdidentifying related messagespayload- the message itselferrorPayload- 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 newProcessingContext.- Type Parameters:
T- the type of the message- Parameters:
eventType- the event type of the messagemessageId- the uniqueMessageIdof the messagecorrelationId- theCorrelationIdidentifying related messagespayload- the message itselferrorPayload- an additional error messagecontextMetaData- aMapcontaining additional data of the messages's processinginitialProcessingFrame- theChannelProcessingFrameidentifying the firstChannelcurrentProcessingFrame- theChannelProcessingFrameidentifying the currentChannel- Returns:
- the newly created
ProcessingContext
-
processingContextForError
public static <T> ProcessingContext<T> processingContextForError(EventType eventType, Object errorPayload)
Factory method to create a newProcessingContext.- Type Parameters:
T- the type of the message- Parameters:
eventType- the event type of the messageerrorPayload- 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 newProcessingContext.- Type Parameters:
T- the type of the message- Parameters:
eventType- the event type of the messagepayload- the message itselferrorPayload- 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 newProcessingContext.- Type Parameters:
T- the type of the message- Parameters:
eventType- the event type of the messagecorrelationId- theCorrelationIdidentifying related messagespayload- the message itselferrorPayload- an additional error message- Returns:
- the newly created
ProcessingContext
-
actionWasChanged
public boolean actionWasChanged()
Returns, whether the defaultActionwas overwritten for the currentChannel- Returns:
trueif theActionwas changed andfalseotherwise
-
getAction
public Action<T> getAction()
Returns theAction, that overwrites the default one, if existing.- Returns:
- the changed
Actionor null of no newActionwas set
-
changeAction
public void changeAction(Action<T> action)
Overwrites theChannel'sdefaultAction.At the end of the current
Channelnot the defaultActionis executed anymore. Instead the overwritingActionis executed.- Parameters:
action- the newAction
-
generateCorrelationIdForAnswer
public CorrelationId generateCorrelationIdForAnswer()
Creates aCorrelationIdmatching the currentProcessingContext'sMessageId.- Returns:
- a new, related
CorrelationId
-
getEventType
public EventType getEventType()
-
getMessageId
public MessageId getMessageId()
-
getCorrelationId
public CorrelationId getCorrelationId()
-
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)
-
getInitialProcessingFrame
public ChannelProcessingFrame<T> getInitialProcessingFrame()
-
setInitialProcessingFrame
public void setInitialProcessingFrame(ChannelProcessingFrame<T> initialProcessingFrame)
-
getCurrentProcessingFrame
public ChannelProcessingFrame<T> getCurrentProcessingFrame()
-
setCurrentProcessingFrame
public void setCurrentProcessingFrame(ChannelProcessingFrame<T> currentProcessingFrame)
-
-