public class BDLContextProvider extends java.lang.Object implements BaggageProvider<BDLContext>
BaggageProvider for BDLContext, which extends NestedBaggageContext to provide object
representations for a range of data types, and to convert to and from those object representations using
BDL-generated classes.
BDLContextProvider has several static API methods for getting and setting objects within
BaggageContext instances. In general, you should not need to use these methods directly; instead, they are
used by the BDL-generated accessors.
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(BaggageListener.BranchListener<BDLContext> listener)
Registers a
BaggageListener.BranchListener that will be invoked any time branch(BDLContext) is
invoked. |
void |
addListener(BaggageListener.JoinListener<BDLContext> listener)
Registers a
BaggageListener.JoinListener that will be invoked any time
join(BDLContext, BDLContext) is invoked. |
BDLContext |
branch(BDLContext from)
Create and return a copy of
from. |
BDLContext |
compact(BDLContext left,
BDLContext right)
Additional operation provided by
BDLContext to compact a context. |
BDLContext |
deserialize(byte[] serialized,
int offset,
int length)
Deserialize the provided serialized baggage representation.
|
BDLContext |
deserialize(java.nio.ByteBuffer buf)
Deserialize the provided serialized baggage representation.
|
void |
discard(BDLContext baggage)
Discards
baggage. |
static Bag |
get(BaggageContext baggage,
BagKey key)
This method fetches the object stored in the provided
BaggageContext under the specified key, or returns
null if there is no object present. |
boolean |
isValid(BaggageContext baggage) |
BDLContext |
join(BDLContext left,
BDLContext right)
Merge the contents of
left and right and return as baggage. |
BDLContext |
newInstance() |
byte[] |
serialize(BDLContext baggage)
Serialize the provided baggage instance to its byte representation.
|
byte[] |
serialize(BDLContext baggage,
int maximumSerializedSize)
Serialize the provided baggage instance to its byte representation and trim the baggage so that its serialized
size is
<= maximumSerializedSize. |
static BaggageContext |
set(BaggageContext baggage,
BagKey key,
Bag value)
Maps the specified key to the provided bag value.
|
public boolean isValid(BaggageContext baggage)
isValid in interface BaggageProvider<BDLContext>baggage - a BaggageContext to testbaggage is an instance of B or if baggage is null.public BDLContext newInstance()
newInstance in interface BaggageProvider<BDLContext>B, which may be null to indicate an empty baggagepublic void discard(BDLContext baggage)
BaggageProviderbaggage. If this TransitLayer performs anything like reference counting, then this method
is where decrementing reference counts would happen.discard in interface BaggageProvider<BDLContext>baggage - a baggage instancepublic BDLContext branch(BDLContext from)
BaggageProviderfrom. If this TransitLayer performs anything like reference counting,
then this method might just return from while incrementing reference counts.
This method might create a new instance of B and might even modify the contents of frombranch in interface BaggageProvider<BDLContext>from - a baggage instance, possibly nullfrom, possibly nullpublic void addListener(BaggageListener.BranchListener<BDLContext> listener)
BaggageListener.BranchListener that will be invoked any time branch(BDLContext) is
invoked.listener - a BaggageListener.BranchListenerpublic BDLContext join(BDLContext left, BDLContext right)
BaggageProviderleft and right and return as baggage. left and
right should be treated as discarded (or reused) after this method call.join in interface BaggageProvider<BDLContext>left - a baggage instance, possibly nullright - a baggage instance, possibly nullleft and rightpublic BDLContext compact(BDLContext left, BDLContext right)
BDLContext to compact a context. This is a prototype, its behavior is
datatype-dependent and generally should not be used. Its implementation is kinda hacky since I'm not sure if this
should be incorporated into the main API yet. Currently only CounterImpl actually implements compaction.public void addListener(BaggageListener.JoinListener<BDLContext> listener)
BaggageListener.JoinListener that will be invoked any time
join(BDLContext, BDLContext) is invoked.listener - a BaggageListener.JoinListenerpublic BDLContext deserialize(byte[] serialized, int offset, int length)
BaggageProviderdeserialize in interface BaggageProvider<BDLContext>serialized - a serialized baggageoffset - offset into the array where the baggage bytes beginlength - lenft of the baggage bytespublic BDLContext deserialize(java.nio.ByteBuffer buf)
BaggageProviderdeserialize in interface BaggageProvider<BDLContext>buf - a serialized baggagepublic byte[] serialize(BDLContext baggage)
BaggageProvider#branch(Baggage) is also being called prior to serialization.serialize in interface BaggageProvider<BDLContext>baggage - a baggage instance to serialize, possibly nullbaggage, which might be null or an empty byte arraypublic byte[] serialize(BDLContext baggage, int maximumSerializedSize)
BaggageProvider<= maximumSerializedSize. This method should behave as though #branch(Baggage) is also
being called prior to serialization.serialize in interface BaggageProvider<BDLContext>baggage - a baggage instance to serialize, possibly nullmaximumSerializedSize - the maximum size in bytes of the serialized baggage.baggage, which might be null or an empty byte arraypublic static Bag get(BaggageContext baggage, BagKey key)
This method fetches the object stored in the provided BaggageContext under the specified key, or returns
null if there is no object present.
This method is typically invoked by BDL-generated classes when calling the getFrom(BaggageContext)
method. For example, if we generated a bag called XTraceBaggage and registered it to
BagKey.indexed(7), then a call to get(BaggageContext, BagKey.indexed(7)) would return
either null (if there is no XTraceBaggage instance present), or an instance of
XTraceBaggage.
baggage - a BaggageContext instance, expected to be an instance of BDLContextkey - the key to look upbaggage is an instance of BDLContext, returns the object mapped to
key if there is one. Otherwise, returns null.public static BaggageContext set(BaggageContext baggage, BagKey key, Bag value)
Maps the specified key to the provided bag value. This method possibly modifies the provided baggage
instance, or might return a new instance depending on whether baggage is modifiable.
To construct a new BaggageContext with the specified mapping, simply pass null for
baggage.
baggage - the baggage to modify, which may be null, indicating the empty baggage.key - the key to updatebag - the new bag to map to this key