public class ActiveBaggage
extends java.lang.Object
Extends the static Baggage API with further methods for saving, retrieving, and interacting with
BaggageContext instances using the default TransitLayer.
Unlike the Baggage interface, ActiveBaggage implicitly accesses the
currently-active BaggageContext that is being managed by the TransitLayer. Unless it has been
configured otherwise, this entails looking up the BaggageContext in thread-local storage.
This class also provides static methods to get and set the currently active baggage. These methods proxy to the
configured TransitLayer, which is responsible for maintaining active baggage (e.g., in thread-local storage).
If you wish to manipulate BaggageContext instances without affecting the currently active baggage context,
use the static methods on the Baggage class.
Using this class requires that a BaggageProvider has been registered (e.g., using the
baggage.provider property). By default, the TransitLayer used will be
ThreadLocalTransitLayer; this can be overridden using baggage.transit.
| Modifier and Type | Method and Description |
|---|---|
static BaggageContext |
branch()
Create and return a branched copy of the currently active baggage context.
|
static byte[] |
branchBytes()
Create and return a branched, serialized copy of the currently active baggage context.
|
static void |
discard()
Discard the currently active
BaggageContext. |
static void |
join(BaggageContext otherContext)
Merges the contents of
otherContext into the currently active context. |
static void |
join(byte[] serialized,
int offset,
int length)
Deserializes the provided context and merges it into the currently active context.
|
static void |
join(java.nio.ByteBuffer serializedContext)
Deserializes the provided context and merges it into the currently active context.
|
static BaggageContext |
peek()
Gets the currently active
BaggageContext. |
static void |
set(BaggageContext baggage)
Discards the currently active
BaggageContext, then activates the provided baggage. |
static void |
set(byte[] serialized,
int offset,
int length)
Deserializes the provided context and merges it into the currently active context.
|
static void |
set(java.nio.ByteBuffer serializedContext)
Deserializes the provided context, discards any currently active context, and replaces it with the deserialized
context.
|
static BaggageContext |
take()
Gets and removes the currently active
BaggageContext. |
static byte[] |
takeBytes()
Gets, removes, and serializes the currently active
BaggageContext. |
static void |
update(BaggageContext baggage)
Sets the currently active
BaggageContext. |
public static void discard()
BaggageContext.public static BaggageContext branch()
public static byte[] branchBytes()
public static void join(BaggageContext otherContext)
otherContext into the currently active context. otherContext
should not be reused after calling this method, and should be treated as discarded.otherContext - another baggage context, possibly nullpublic static void join(java.nio.ByteBuffer serializedContext)
serializedContext - a serialized baggage context, possibly nullpublic static void join(byte[] serialized,
int offset,
int length)
serialized - a serialized baggage context, possibly nulloffset - offset into byte arraylength - length of bytes to usepublic static void set(BaggageContext baggage)
BaggageContext, then activates the provided baggage. If
baggage is just a modified version of the currently active BaggageContext, then it is better to use
the update(BaggageContext) method instead.baggage - The new baggage context to activate.public static void set(java.nio.ByteBuffer serializedContext)
serializedContext - a serialized baggage context, possibly nullpublic static void set(byte[] serialized,
int offset,
int length)
serialized - a serialized baggage context, possibly nulloffset - offset into the byte arraylength - length of serialized bytespublic static BaggageContext take()
BaggageContext. After calling this method, there will be no active
BaggageContext.BaggageContext.public static byte[] takeBytes()
BaggageContext. After calling this method, there will
be no active BaggageContext.BaggageContext.public static BaggageContext peek()
BaggageContext. The BaggageContext instance remains active after
calling this method. Use take() to if you wish to get and remove the currently active context.BaggageContextpublic static void update(BaggageContext baggage)
BaggageContext. A call to this method implies that the provided
context argument is an updated version of the active context. Conversely, if you intend to replace
the currently active context (e.g., because a different execution is beginning), use the
set(BaggageContext) method.context - an updated version of the currently active baggage context.