public interface ContextsContainer
| Modifier and Type | Method and Description |
|---|---|
void |
addContext(java.lang.String contextName,
java.lang.String context)
Adds a custom
String context to this request scope. |
<T> void |
addContext(java.lang.String contextName,
T context,
ContextSerializer<T> serializer)
Adds a custom context (arbitrary object) to this container.
|
void |
consumeBidirectionalContextsFromResponse(ContextKeySupplier contextKeySupplier)
Reads the bi-directional contexts from the HTTP response and updates this
ContextsContainer with those
contexts. |
<T> T |
getContext(java.lang.String contextName)
Retrieves the value of the context added previously in this request scope via
addContext(String, String) or addContext(String, Object, ContextSerializer)
The context could have been set in a different service and transferred here on the wire. |
<T> T |
getContext(java.lang.String contextName,
ContextSerializer<T> serializer)
Retrieves the value of the context added previously in this request scope via
addContext(String, String) or addContext(String, Object, ContextSerializer)
The context could have been set in a different service and transferred here on the wire. |
java.util.Map<java.lang.String,java.lang.String> |
getModifiedBidirectionalContexts()
Map of bi-directional context names and values (serialized form) that were modified
within the current application.
|
java.util.Map<java.lang.String,java.lang.String> |
getSerializedContexts()
Map of context names and values (serialized form) associated with this request.
|
boolean |
removeContext(java.lang.String contextName)
Removes a context with name
contextName added previously in this request scope via
addContext(String, String) or addContext(String, Object, ContextSerializer)
The context could have been set in a different service and transferred here on the wire. |
<T> void addContext(java.lang.String contextName,
T context,
ContextSerializer<T> serializer)
serializer.
Serialization will be done when an outbound service call is made, to send this context on the wire.
De-serialization will be done in the outbound service for the above call, if and only if, a client
invokes getContext(String) for the same context name.
This method overwrites any existing value with the passed context name.
Object.equals(Object)getModifiedBidirectionalContexts() will also
include this context.T - Type of the context.contextName - Name of the context.context - Context instance.serializer - Serializer for the context.java.lang.IllegalArgumentException - If any of the arguments are null.java.util.Map<java.lang.String,java.lang.String> getModifiedBidirectionalContexts()
throws ContextSerializationException
BiDirectional for details. ContextSerializationException - If the serialization fails.void consumeBidirectionalContextsFromResponse(ContextKeySupplier contextKeySupplier) throws ContextSerializationException
ContextsContainer with those
contexts.contextKeySupplier - The ContextKeySupplier for the response.ContextSerializationException - If the de-serialization of the bidrectional context fails.void addContext(java.lang.String contextName,
java.lang.String context)
String context to this request scope. addContext(String, Object, ContextSerializer) with the
serializer as StringSerializercontextName - Name of the context.context - Context instance.java.lang.IllegalArgumentException - If any of the arguments are null.boolean removeContext(java.lang.String contextName)
contextName added previously in this request scope via
addContext(String, String) or addContext(String, Object, ContextSerializer)
The context could have been set in a different service and transferred here on the wire.contextName - Name of the context to remove.true if the context existed and was removed. false if the context did not exist.<T> T getContext(java.lang.String contextName)
throws ContextSerializationException
addContext(String, String) or addContext(String, Object, ContextSerializer)
The context could have been set in a different service and transferred here on the wire. In such a case, the
serializer passed during addition of the context will be used for de-serialization.
All values of the context after de-serialization are cached, unless overwritten by a corresponding
addContext(String, Object, ContextSerializer). Also, the serializer instance will be
cached once created.contextName - Name of the context.ContextSerializationException<T> T getContext(java.lang.String contextName,
ContextSerializer<T> serializer)
throws ContextSerializationException
addContext(String, String) or addContext(String, Object, ContextSerializer)
The context could have been set in a different service and transferred here on the wire. In such a case, the
serializer passed will be used for de-serialization and the serializer passed during context addition will be
ignored.
Word of caution: If the value is cached as a result of a prior invocation of this method or
getContext(String), the passed serializer will not be used.
This method should only be used if your serializer is stateful or requires custom initializations. Otherwise, the
serializer associated with this context must be used i.e. by calling getContext(String)
All values of the context after de-serialization are cached, unless overwritten by a corresponding
addContext(String, Object, ContextSerializer). Also, the serializer instance will be
cached once created.contextName - Name of the context.serializer - The serializer instance to use if the context is required to be de-serialized.ContextSerializationExceptionjava.util.Map<java.lang.String,java.lang.String> getSerializedContexts()
throws ContextSerializationException
ContextSerializationException - If the serialization fails.