A context interface to correlate a message generated by a
Source to a particular state- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddVariable(String variableName, Object value) Adds a variablebindConnection(Object connection) Associates the givenconnectiontothiscontext.voidfireOnHandle(NotificationActionDefinition<?> action, org.mule.runtime.api.metadata.TypedValue<?> data) Indicates that anExtensionNotificationshould be fired with the desired information when the runtime takes the source result to process it.<T> TReturns the connection that was bound throughbindConnection(Object).<T,A> SourceCallback<T, A> A handle to the current on-going transaction.<T> Optional<T>getVariable(String variableName) Returns the value associated to a variable of namevariableNamebooleanhasVariable(String variableName) Returns whether a variable of namevariableNamehas a value associated to it through theaddVariable(String, Object)methodvoidsetCorrelationId(String correlationId) Sets the correlationId of the event that will be passed to the flow when theSourceCallback.handle(Result, SourceCallbackContext)method is invoked.
-
Method Details
-
bindConnection
TransactionHandle bindConnection(Object connection) throws org.mule.runtime.api.connection.ConnectionException, org.mule.runtime.api.tx.TransactionException Associates the givenconnectiontothiscontext. As a result of this binding, the runtime will automatically take care of releasing theconnectiononce the source has finished processing the response and will also take care of resolving the associated transaction (if any).If the connection is a
TransactionalConnectionand the source was configured to be transactional, then this method will start such transaction.- Parameters:
connection- the connection to be bound- Returns:
- a
TransactionHandleproduced as a result of the binding - Throws:
org.mule.runtime.api.connection.ConnectionException- if the connection is not valid or cannot be usedorg.mule.runtime.api.tx.TransactionException- if a transaction was needed but couldn't be started.
-
getConnection
Returns the connection that was bound throughbindConnection(Object).If that method was not called, then it will throw
IllegalStateException- Type Parameters:
T- the generic type of the connection- Returns:
- the bound connection
- Throws:
IllegalStateException- if no connection bound
-
getTransactionHandle
TransactionHandle getTransactionHandle()A handle to the current on-going transaction. If no transaction is active, then you get a handle which represents a void transaction, but this method will never return null.This method can be used without the need for
bindConnection(Object)to had been invoked onthisinstance first. However if it has, then the result of this method will be the exact same instance thatbindConnection(Object)returned.- Returns:
- the current
TransactionHandle
-
hasVariable
Returns whether a variable of namevariableNamehas a value associated to it through theaddVariable(String, Object)method- Parameters:
variableName- the name of a variable associated to a particularSourceCallback- Returns:
trueif the parameter is present.
-
getVariable
Returns the value associated to a variable of namevariableName- Type Parameters:
T- the returned value's generic type- Parameters:
variableName- the name of a variable of aSourceCallback- Returns:
- an
Optionalof the variable's value.
-
addVariable
Adds a variable- Parameters:
variableName- the name of the variablevalue- the variable's value
-
setCorrelationId
Sets the correlationId of the event that will be passed to the flow when theSourceCallback.handle(Result, SourceCallbackContext)method is invoked.This method can only be invoked BEFORE
thisinstance has been used on aSourceCallback.handle(Result, SourceCallbackContext)operation. Otherwise, anIllegalStateExceptionwill be thrown.- Parameters:
correlationId- a correlationId- Throws:
IllegalArgumentException- if invoked oncethiscontext has already been used to push a message
-
getCorrelationId
- Returns:
- Optionally returns the correlationId set through
setCorrelationId(String)(if any).
-
getSourceCallback
- Type Parameters:
T- the generic type of the output values of the generated resultsA- the generic type of the attributes of the generated results- Returns:
- The
SourceCallbackthat generatedthiscontext
-
fireOnHandle
void fireOnHandle(NotificationActionDefinition<?> action, org.mule.runtime.api.metadata.TypedValue<?> data) Indicates that anExtensionNotificationshould be fired with the desired information when the runtime takes the source result to process it.- Parameters:
action- theNotificationActionDefinitionto use.data- theTypedValuedata to use.
-
getDistributedSourceTraceContext
- Returns:
- the
DistributedTraceContextManagerassociated to this source callback context.
-