public class MessageContext extends Object implements XMessageContext
XMessageContext
APIConstructor and Description |
---|
MessageContext(XMessage message) |
Modifier and Type | Method and Description |
---|---|
<P> void |
addContextProperty(String key,
P value)
Add a message property - i.e.
|
void |
addThrowable(Throwable t)
Add a
Throwable to the throwable stack of the message context |
void |
attachForRelease(AutoCloseable closeable)
Attach an instance of
AutoCloseable to be closed at the message context release stage |
XMessageContext |
cloneMessageContextWithFullMessage(ExchangePattern exchangePattern,
CompletionType completionType)
Creates a copyOf of this message context with the enclosed
XMessage instance and its payload. |
XMessageContext |
cloneMessageContextWithoutMessage(ExchangePattern exchangePattern,
CompletionType completionType)
Creates a copyOf of this message context without the enclosed
XMessage instance. |
XMessageContext |
cloneMessageContextWithoutPayload(ExchangePattern exchangePattern,
CompletionType completionType)
Creates a copyOf of this message context with the enclosed
XMessage instance. |
void |
completeMessageFlowSuccessfully()
This method should be invoked to indicate that the message flow related to this message context is completed
successfully
|
void |
completeMessageFlowWithException(Throwable throwable)
This method should be invoked to indicate that the message flow related to this message context is completed
with a failure
|
Optional<Throwable> |
getAndRemoveLastThrowable()
Retrieves the last
Throwable associated with this message context and removes it from the stack of
occurred throwables. |
CompletableFuture<XMessageContext> |
getAsyncResponseCompletionFuture()
Returns the asynchronous response future object
|
UUID |
getContextId() |
Map<String,Object> |
getContextProperties()
Return current message properties as an unmodifiable map
|
<P> Optional<P> |
getContextProperty(String key,
Class<P> cls)
Get the message property associated with the specified key as a typed object of type P
|
Optional<XScopeContext> |
getCurrentScopeContext() |
CompletableFuture<XMessage> |
getEgressFuture() |
ExchangePattern |
getExchangePattern() |
XFlowEventNotificationContext |
getFlowEventNotificationContext()
Retrieves the
XFlowEventNotificationContext associated with this context |
Optional<XIntegrationFlowTracer> |
getIntegrationFlowTracer() |
Optional<Throwable> |
getLastThrowable()
Retrieves the last
Throwable associated with this message context. |
XMessage |
getMessage() |
XMessageView |
getMessageView(int maxPayloadSizeKbs) |
XPlatform |
getPlatform() |
String |
getReceivedConnectorId()
Retrieves the ID of the
XIngressConnectorElement through which this
message context is received |
CompletableFuture<XMessageContext> |
getResponseFuture() |
List<XScopeContext> |
getScopeContextList() |
<T> Optional<T> |
getScopeVariable(String varKey,
Class<T> type,
boolean propagateToParent)
Retrieves the scope variable with the given key
|
Optional<String> |
getStringContextProperty(String key)
Get the String message property associated with the specified key
|
TransactionContext |
getTransactionContext() |
boolean |
hasContextProperty(String key)
Checks whether the given property is present in the message properties map
|
boolean |
isFailoverEnabled() |
boolean |
isMessageContextCompleted()
Whether this message context has been completed processing
|
boolean |
isMessageFlowCompleted()
Whether the message flow (to which this message context belongs) has been completed
|
boolean |
isResponseSubmitted() |
boolean |
isTimedOut()
Checks whether this message context is flagged as timed-out
|
void |
onCompletionOfAllSubBranches(BiConsumer<XMessageContext,Throwable> function) |
void |
onCompletionOfThisBranch(BiConsumer<XMessageContext,Throwable> function) |
void |
releaseResources()
Releases resources used by the message context at the end of it's life
|
void |
removeContextProperty(String key)
Remove the message property associated with the specified key
|
void |
removeCurrentScopeContext() |
void |
removeScopeVariable(String varKey,
boolean removeFromAllScopes)
Removes the scope variable with the given key
|
XMessage |
resetEnclosedMessage()
|
void |
sendResponse(int code,
boolean completeFlow) |
void |
sendResponse(int code,
XMessage responseMessage,
boolean completeFlow) |
void |
setAsTimedOut()
Flags this message context as timed-out.
|
void |
setAsyncResponseCompletionFuture(CompletableFuture<XMessageContext> asyncResponseCompletionFuture)
Sets a
CompletableFuture for message context as the asynchronous response future. |
void |
setCurrentScopeContext(XScopeContext scopeContext) |
void |
setEgressFuture(CompletableFuture<XMessage> egressFuture) |
void |
setExchangePattern(ExchangePattern exchangePattern) |
void |
setFailoverEnabled(boolean failoverEnabled) |
void |
setFlowCompletionFuture(CompletableFuture<XMessageContext> flowCompletionFuture) |
void |
setFlowEventNotificationContext(XFlowEventNotificationContext flowEventNotificationContext)
Sets the given
XFlowEventNotificationContext to this context |
void |
setMessage(XMessage message) |
void |
setPlatform(XPlatform platform) |
void |
setReceivedConnectorId(String receivedConnectorId)
Sets the ID of the
XIngressConnectorElement through which this message
context is received |
void |
setResponseFuture(CompletableFuture<XMessageContext> responseFuture) |
<T> void |
setScopeVariable(String varKey,
T varValue)
Adds a new variable to the current scope with the given key and value
|
void |
setTransactionContext(TransactionContext transactionContext) |
public MessageContext(XMessage message)
public UUID getContextId()
getContextId
in interface XMessageContext
public XMessage getMessage()
getMessage
in interface XMessageContext
public ExchangePattern getExchangePattern()
getExchangePattern
in interface XMessageContext
public void setMessage(XMessage message)
setMessage
in interface XMessageContext
public void setExchangePattern(ExchangePattern exchangePattern)
setExchangePattern
in interface XMessageContext
public void sendResponse(int code, XMessage responseMessage, boolean completeFlow)
sendResponse
in interface XMessageContext
public void sendResponse(int code, boolean completeFlow)
sendResponse
in interface XMessageContext
public void setEgressFuture(CompletableFuture<XMessage> egressFuture)
setEgressFuture
in interface XMessageContext
public CompletableFuture<XMessage> getEgressFuture()
getEgressFuture
in interface XMessageContext
public XPlatform getPlatform()
getPlatform
in interface XMessageContext
public Optional<XIntegrationFlowTracer> getIntegrationFlowTracer()
getIntegrationFlowTracer
in interface XMessageContext
public XMessageView getMessageView(int maxPayloadSizeKbs)
getMessageView
in interface XMessageContext
public void setCurrentScopeContext(XScopeContext scopeContext)
setCurrentScopeContext
in interface XMessageContext
public Optional<XScopeContext> getCurrentScopeContext()
getCurrentScopeContext
in interface XMessageContext
public List<XScopeContext> getScopeContextList()
getScopeContextList
in interface XMessageContext
public void removeCurrentScopeContext()
removeCurrentScopeContext
in interface XMessageContext
public TransactionContext getTransactionContext()
getTransactionContext
in interface XMessageContext
public void setTransactionContext(TransactionContext transactionContext)
setTransactionContext
in interface XMessageContext
public CompletableFuture<XMessageContext> getResponseFuture()
public void setResponseFuture(CompletableFuture<XMessageContext> responseFuture)
setResponseFuture
in interface XMessageContext
public void setFlowCompletionFuture(CompletableFuture<XMessageContext> flowCompletionFuture)
public boolean isResponseSubmitted()
isResponseSubmitted
in interface XMessageContext
public void onCompletionOfThisBranch(BiConsumer<XMessageContext,Throwable> function)
onCompletionOfThisBranch
in interface XMessageContext
public void onCompletionOfAllSubBranches(BiConsumer<XMessageContext,Throwable> function)
onCompletionOfAllSubBranches
in interface XMessageContext
public boolean isFailoverEnabled()
isFailoverEnabled
in interface XMessageContext
public void setFailoverEnabled(boolean failoverEnabled)
setFailoverEnabled
in interface XMessageContext
public void setPlatform(XPlatform platform)
setPlatform
in interface XMessageContext
public XMessageContext cloneMessageContextWithFullMessage(ExchangePattern exchangePattern, CompletionType completionType)
XMessageContext
XMessage
instance and its payload.cloneMessageContextWithFullMessage
in interface XMessageContext
exchangePattern
- ExchangePattern
to be set for the new message context. If this is null, the
exchange pattern of the original context will be inheritedcompletionType
- CompletionType
to be used for this cloningpublic XMessageContext cloneMessageContextWithoutPayload(ExchangePattern exchangePattern, CompletionType completionType)
XMessageContext
XMessage
instance. But the payload of that
XMessage
will not be cloned.cloneMessageContextWithoutPayload
in interface XMessageContext
exchangePattern
- ExchangePattern
to be set for the new message context. If this is null, the
exchange pattern of the original context will be inheritedcompletionType
- CompletionType
to be used for this cloningpublic XMessageContext cloneMessageContextWithoutMessage(ExchangePattern exchangePattern, CompletionType completionType)
XMessageContext
XMessage
instance.
A call to this method may follow invoking of XMessageContext.resetEnclosedMessage()
method to assign a new instance of
XMessage
as the context's messagecloneMessageContextWithoutMessage
in interface XMessageContext
exchangePattern
- ExchangePattern
to be set for the new message context. If this is null, the
exchange pattern of the original context will be inheritedcompletionType
- CompletionType
to be used for this cloningXMessageContext.resetEnclosedMessage()
public void setAsyncResponseCompletionFuture(CompletableFuture<XMessageContext> asyncResponseCompletionFuture)
XMessageContext
CompletableFuture
for message context as the asynchronous response future. An asyncResponseCompletionFuture
can be used to mark the completion of a response when the response future (which is set using
XMessageContext.setResponseFuture(CompletableFuture)
) is completed at the start point of the asynchronous response process.setAsyncResponseCompletionFuture
in interface XMessageContext
asyncResponseCompletionFuture
- asynchronous response futurepublic CompletableFuture<XMessageContext> getAsyncResponseCompletionFuture()
XMessageContext
getAsyncResponseCompletionFuture
in interface XMessageContext
null
else.public void releaseResources()
XMessageContext
releaseResources
in interface XMessageContext
public <T> void setScopeVariable(String varKey, T varValue)
XMessageContext
setScopeVariable
in interface XMessageContext
T
- type of the variable valuevarKey
- String
key of the variablevarValue
- value of the variablepublic <T> Optional<T> getScopeVariable(String varKey, Class<T> type, boolean propagateToParent)
XMessageContext
getScopeVariable
in interface XMessageContext
T
- type of the variablevarKey
- key of the variabletype
- expected type of the variablepropagateToParent
- whether to propagate the search for the parent scopes, if a variable with the given key
is not found in the current scopeOptional
of type T
containing the variable if a variable with the given key is found and
value for that key is not null, Optional.EMPTY
otherwisepublic void removeScopeVariable(String varKey, boolean removeFromAllScopes)
XMessageContext
removeScopeVariable
in interface XMessageContext
varKey
- key of the variableremoveFromAllScopes
- whether to remove the variables with the given key from all scopespublic void completeMessageFlowSuccessfully()
XMessageContext
completeMessageFlowSuccessfully
in interface XMessageContext
public void completeMessageFlowWithException(Throwable throwable)
XMessageContext
completeMessageFlowWithException
in interface XMessageContext
throwable
- Throwable
related to the failure of this message flowpublic XFlowEventNotificationContext getFlowEventNotificationContext()
XMessageContext
XFlowEventNotificationContext
associated with this contextgetFlowEventNotificationContext
in interface XMessageContext
XFlowEventNotificationContext
public void setFlowEventNotificationContext(XFlowEventNotificationContext flowEventNotificationContext)
XMessageContext
XFlowEventNotificationContext
to this contextsetFlowEventNotificationContext
in interface XMessageContext
flowEventNotificationContext
- XFlowEventNotificationContext
instance to be setpublic boolean isTimedOut()
XMessageContext
isTimedOut
in interface XMessageContext
public void setAsTimedOut()
XMessageContext
setAsTimedOut
in interface XMessageContext
public <P> void addContextProperty(String key, P value)
XMessageContext
addContextProperty
in interface XMessageContext
P
- the type of the property value to be addedkey
- property keyvalue
- property valuepublic <P> Optional<P> getContextProperty(String key, Class<P> cls)
XMessageContext
getContextProperty
in interface XMessageContext
P
- the type of the propertykey
- the property keycls
- the class of the property typepublic Optional<String> getStringContextProperty(String key)
XMessageContext
getStringContextProperty
in interface XMessageContext
key
- property keypublic void removeContextProperty(String key)
XMessageContext
removeContextProperty
in interface XMessageContext
key
- property keypublic boolean hasContextProperty(String key)
XMessageContext
hasContextProperty
in interface XMessageContext
key
- the key to be checked for existencepublic Map<String,Object> getContextProperties()
XMessageContext
getContextProperties
in interface XMessageContext
public void setReceivedConnectorId(String receivedConnectorId)
XMessageContext
XIngressConnectorElement
through which this message
context is receivedsetReceivedConnectorId
in interface XMessageContext
receivedConnectorId
- ID of the received ingress connectorpublic String getReceivedConnectorId()
XMessageContext
XIngressConnectorElement
through which this
message context is receivedgetReceivedConnectorId
in interface XMessageContext
public void addThrowable(Throwable t)
XMessageContext
Throwable
to the throwable stack of the message contextaddThrowable
in interface XMessageContext
t
- instance of Throwable
public Optional<Throwable> getLastThrowable()
XMessageContext
Throwable
associated with this message context.
But it should be noted that this method will not remove the throwable from the stack of occurred throwables. To
remove the throwable after the retrieval, XMessageContext.getAndRemoveLastThrowable()
method should be used.
getLastThrowable
in interface XMessageContext
Optional
containing the last occurred Throwable
if exists, or Optional.EMPTY
otherwisepublic Optional<Throwable> getAndRemoveLastThrowable()
XMessageContext
Throwable
associated with this message context and removes it from the stack of
occurred throwables.
To keep the last throwable on the stack of occurred throwables even after the retrieval,
XMessageContext.getLastThrowable()
method should be used.
getAndRemoveLastThrowable
in interface XMessageContext
Optional
containing the last occurred Throwable
if exists, or Optional.EMPTY
otherwisepublic void attachForRelease(AutoCloseable closeable)
XMessageContext
AutoCloseable
to be closed at the message context release stageattachForRelease
in interface XMessageContext
closeable
- instance of AutoCloseable
to be closedpublic boolean isMessageContextCompleted()
XMessageContext
isMessageContextCompleted
in interface XMessageContext
true
if completed, false
otherwisepublic boolean isMessageFlowCompleted()
XMessageContext
isMessageFlowCompleted
in interface XMessageContext
true
if completed, false
otherwisepublic XMessage resetEnclosedMessage()
XMessageContext
resetEnclosedMessage
in interface XMessageContext
Copyright © 2016–2019 AdroitLogic. All rights reserved.