public class ContextsContainerImpl extends java.lang.Object implements ContextsContainer
ContextsContainer| Constructor and Description |
|---|
ContextsContainerImpl(ContextKeySupplier keySupplier) |
| 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
ContextsContainer.addContext(String, String) or ContextsContainer.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
ContextsContainer.addContext(String, String) or ContextsContainer.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
ContextsContainer.addContext(String, String) or ContextsContainer.addContext(String, Object, ContextSerializer)
The context could have been set in a different service and transferred here on the wire. |
public ContextsContainerImpl(ContextKeySupplier keySupplier)
public <T> void addContext(java.lang.String contextName,
T context,
ContextSerializer<T> serializer)
ContextsContainerserializer.
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 ContextsContainer.getContext(String) for the same context name.
This method overwrites any existing value with the passed context name.
Object.equals(Object)ContextsContainer.getModifiedBidirectionalContexts() will also
include this context.addContext in interface ContextsContainerT - Type of the context.contextName - Name of the context.context - Context instance.serializer - Serializer for the context.public void addContext(java.lang.String contextName,
java.lang.String context)
ContextsContainerString context to this request scope. ContextsContainer.addContext(String, Object, ContextSerializer) with the
serializer as StringSerializeraddContext in interface ContextsContainercontextName - Name of the context.context - Context instance.public boolean removeContext(java.lang.String contextName)
ContextsContainercontextName added previously in this request scope via
ContextsContainer.addContext(String, String) or ContextsContainer.addContext(String, Object, ContextSerializer)
The context could have been set in a different service and transferred here on the wire.removeContext in interface ContextsContainercontextName - Name of the context to remove.true if the context existed and was removed. false if the context did not exist.public <T> T getContext(java.lang.String contextName)
throws ContextSerializationException
ContextsContainerContextsContainer.addContext(String, String) or ContextsContainer.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
ContextsContainer.addContext(String, Object, ContextSerializer). Also, the serializer instance will be
cached once created.getContext in interface ContextsContainercontextName - Name of the context.ContextSerializationExceptionpublic <T> T getContext(java.lang.String contextName,
ContextSerializer<T> serializer)
throws ContextSerializationException
ContextsContainerContextsContainer.addContext(String, String) or ContextsContainer.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
ContextsContainer.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 ContextsContainer.getContext(String)
All values of the context after de-serialization are cached, unless overwritten by a corresponding
ContextsContainer.addContext(String, Object, ContextSerializer). Also, the serializer instance will be
cached once created.getContext in interface ContextsContainercontextName - Name of the context.serializer - The serializer instance to use if the context is required to be de-serialized.ContextSerializationExceptionpublic java.util.Map<java.lang.String,java.lang.String> getSerializedContexts()
throws ContextSerializationException
ContextsContainergetSerializedContexts in interface ContextsContainerContextSerializationException - If the serialization fails.public java.util.Map<java.lang.String,java.lang.String> getModifiedBidirectionalContexts()
throws ContextSerializationException
ContextsContainerBiDirectional for details. getModifiedBidirectionalContexts in interface ContextsContainerContextSerializationException - If the serialization fails.public void consumeBidirectionalContextsFromResponse(ContextKeySupplier contextKeySupplier) throws ContextSerializationException
ContextsContainerContextsContainer with those
contexts.consumeBidirectionalContextsFromResponse in interface ContextsContainercontextKeySupplier - The ContextKeySupplier for the response.ContextSerializationException - If the de-serialization of the bidrectional context fails.