public class ThreadLocalTransitLayer extends java.lang.Object implements TransitLayer
A straightforward TransitLayer
implementation based on thread-local storage. This is the out-of-the-box
transit layer implementation provided by the Tracing Plane.
It is unlikely that you will need to manually configure the Tracing Plane to use this class -- depending on the distribution you are using, it is likely to be configured by default.
Otherwise, to manually configure the ThreadLocalTransitLayer
, you must configure it using the
baggage.transit
property to use ThreadLocalTransitLayerFactory
, e.g.:
-Dbaggage.transit=brown.tracingplane.impl.ThreadLocalTransitLayerFactoryIt can alternatively be configured in your typesafe config's
application.conf
, e.g.:
baggage.transit = "brown.tracingplane.impl.ThreadLocalTransitLayerFactory"
Constructor and Description |
---|
ThreadLocalTransitLayer(BaggageProvider<BaggageContext> provider) |
Modifier and Type | Method and Description |
---|---|
BaggageContext |
branch()
Create and return a branched copy of the currently active baggage context.
|
byte[] |
branchBytes()
Create and return a branched, serialized copy of the currently active baggage context.
|
void |
discard()
Discard the currently active
BaggageContext . |
void |
join(BaggageContext otherContext)
Merges the contents of
otherContext into the currently active context. |
void |
join(byte[] serialized,
int offset,
int length)
Deserializes the provided context and merges it into the currently active context.
|
void |
join(java.nio.ByteBuffer serializedContext)
Deserializes the provided context and merges it into the currently active context.
|
BaggageContext |
peek()
Gets the currently active
BaggageContext . |
void |
set(BaggageContext baggage)
Discards the currently active
BaggageContext , then activates the provided baggage . |
void |
set(byte[] serialized,
int offset,
int length)
Deserializes the provided context and merges it into the currently active context.
|
void |
set(java.nio.ByteBuffer serializedContext)
Deserializes the provided context, discards any currently active context, and replaces it with the deserialized
context.
|
BaggageContext |
take()
Gets and removes the currently active
BaggageContext . |
byte[] |
takeBytes()
Gets, removes, and serializes the currently active
BaggageContext . |
void |
update(BaggageContext baggage)
Sets the currently active
BaggageContext . |
public ThreadLocalTransitLayer(BaggageProvider<BaggageContext> provider)
provider
- the implementation of BaggageProvider
in use by this transit layerpublic void discard()
TransitLayer
BaggageContext
.discard
in interface TransitLayer
public BaggageContext branch()
TransitLayer
branch
in interface TransitLayer
public byte[] branchBytes()
TransitLayer
branchBytes
in interface TransitLayer
public void join(BaggageContext otherContext)
TransitLayer
otherContext
into the currently active context. otherContext
should not be reused after calling this method, and should be treated as discarded.join
in interface TransitLayer
otherContext
- another baggage context, possibly nullpublic void join(java.nio.ByteBuffer serializedContext)
TransitLayer
join
in interface TransitLayer
serializedContext
- a serialized baggage context, possibly nullpublic void join(byte[] serialized, int offset, int length)
TransitLayer
join
in interface TransitLayer
public void set(BaggageContext baggage)
TransitLayer
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 TransitLayer.update(BaggageContext)
method instead.set
in interface TransitLayer
baggage
- The new baggage context to activate.public void set(java.nio.ByteBuffer serializedContext)
TransitLayer
set
in interface TransitLayer
serializedContext
- a serialized baggage context, possibly nullpublic void set(byte[] serialized, int offset, int length)
TransitLayer
set
in interface TransitLayer
serialized
- a serialized baggage context, possibly nulloffset
- offset into the byte arraylength
- length of serialized bytespublic BaggageContext take()
TransitLayer
BaggageContext
. After calling this method, there will be no active
BaggageContext
.take
in interface TransitLayer
BaggageContext
.public byte[] takeBytes()
TransitLayer
BaggageContext
. After calling this method, there will
be no active BaggageContext
.takeBytes
in interface TransitLayer
BaggageContext
.public BaggageContext peek()
TransitLayer
BaggageContext
. The BaggageContext
instance remains active after
calling this method. Use TransitLayer.take()
to if you wish to get and remove the currently active context.peek
in interface TransitLayer
BaggageContext
public void update(BaggageContext baggage)
TransitLayer
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
TransitLayer.set(BaggageContext)
method.update
in interface TransitLayer