public class BDLContext extends java.lang.Object implements BaggageContext
The full-featured BaggageContext
implementation used by the tracing plane using atoms and the baggage
protocol, intended for use in conjunction with BDL-compiled accessor classes.
The typical way to store and manipulate data within BDLContext
instances is to compile a BDL delcaration
using the BDL compiler. The generated objects will provide accessor methods for getting data out of
BDLContext
instances.
Note: BDL-compiled objects must be registered with a static bag number in order to be used. In concept, this is similar to how protocols get mapped to ports (e.g., SSH maps to port 22, etc.). To register a bag, either specify it as a command line configuration value:
-Dbag.22=my.compiled.object.MyObjector in your
application.conf
:
bag.22 = "my.compiled.object.MyObject"or statically in code:
BaggageHandlerRegistry.add(BagKey.indexed(22), my.compiled.object.MyObject.Handler.instance);
If you don't register a handler to a bag number, then any data found within a BDLContext
will be kept in
atom-form. It will be correctly propagated, however, it will not be accessible within this process in object form.
All data within a BDLContext
has an underlying atom-based representation, and the serialization methods in
BDLContextProvider
transform contexts to and from this atom-based representation. In memory,
BDLContext
data is maintained in object representation.
This class provides some static methods for registering BaggageListener
instances.
This class also provides some utility methods for attaching objects to BDLContext
instances. Attached objects
do not propagate across network communication; it is purely to piggyback additional state
Constructor and Description |
---|
BDLContext() |
Modifier and Type | Method and Description |
---|---|
BDLContext |
attach(java.lang.Object key,
java.lang.Object value)
Maps the provided key to the provided value.
|
void |
clearAttachments()
Removes all attachments from this
BDLContext . |
BDLContext |
detach(java.lang.Object key)
Removes the object mapped to the specified key.
|
Bag |
get(BagKey key)
Get the value mapped to a key, or null if no mapping
|
java.lang.Object |
getAttachment(java.lang.Object key)
Gets the attachment mapped to the specified key, if there is one; returns null otherwise.
|
BDLContext |
put(BagKey key,
Bag value)
Set the value for a key.
|
BDLContext |
remove(BagKey key)
Remove the mapping for the specified key.
|
java.lang.String |
toString() |
public BDLContext remove(BagKey key)
public BDLContext put(BagKey key, Bag value)
public java.lang.Object getAttachment(java.lang.Object key)
public BDLContext detach(java.lang.Object key)
BDLContexts
, that are not included with
the context during serialization.public BDLContext attach(java.lang.Object key, java.lang.Object value)
BDLContext
while
it is propagated within the current process. The k-v pair will not be included when the BDLContext
is
serialized. Attachments are not to be confused with bags; attachments are just additional application-level
objects that can be attached to BDLContexts
, that are not included with the context during serialization.public void clearAttachments()
BDLContext
.public java.lang.String toString()
toString
in class java.lang.Object