Class MarshalerContext
- java.lang.Object
-
- io.opentelemetry.exporter.internal.marshal.MarshalerContext
-
public final class MarshalerContext extends java.lang.Object
Class for keeping marshaling state. The state consists of integers, that we call sizes, and objects, that we call data. Both integers and objects can be read from the state in the order they were added (first in, first out). Additionally, this class provides various pools and caches for objects that can be reused between marshalling attempts.This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
MarshalerContext.IdPool
static class
MarshalerContext.Key
This class is internal and is hence not for public use.private static class
MarshalerContext.Pool<T>
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object[]
data
private int
dataReadIndex
private int
dataWriteIndex
private java.lang.Object[]
instances
private static java.util.concurrent.atomic.AtomicInteger
KEY_INDEX
private MarshalerContext.Pool<java.util.List<?>>
listPool
private MarshalerContext.Pool<java.util.Map<?,?>>
mapPool
private boolean
marshalStringNoAllocation
private boolean
marshalStringUnsafe
private int
sizeReadIndex
private int[]
sizes
private int
sizeWriteIndex
private MarshalerContext.IdPool
spanIdPool
private MarshalerContext.IdPool
traceIdPool
-
Constructor Summary
Constructors Constructor Description MarshalerContext()
MarshalerContext(boolean marshalStringNoAllocation, boolean marshalStringUnsafe)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addData(java.lang.Object o)
int
addSize()
void
addSize(int size)
<T> T
getData(java.lang.Class<T> type)
<K,V>
java.util.Map<K,V>getIdentityMap()
Returns a pooled identity map.<T> T
getInstance(MarshalerContext.Key key, java.util.function.Supplier<T> supplier)
<T> java.util.List<T>
getList()
Returns a pooled list.int
getSize()
byte[]
getSpanIdBuffer()
Returns a buffer that can be used to hold a span id.byte[]
getTraceIdBuffer()
Returns a buffer that can be used to hold a trace id.private void
growDataIfNeeded()
private void
growSizeIfNeeded()
static MarshalerContext.Key
key()
boolean
marshalStringNoAllocation()
boolean
marshalStringUnsafe()
void
reset()
Reset context so that it could be reused.void
resetReadIndex()
Reset context so that serialization could be re-run.void
setSize(int index, int size)
-
-
-
Field Detail
-
marshalStringNoAllocation
private final boolean marshalStringNoAllocation
-
marshalStringUnsafe
private final boolean marshalStringUnsafe
-
sizes
private int[] sizes
-
sizeReadIndex
private int sizeReadIndex
-
sizeWriteIndex
private int sizeWriteIndex
-
data
private java.lang.Object[] data
-
dataReadIndex
private int dataReadIndex
-
dataWriteIndex
private int dataWriteIndex
-
traceIdPool
private final MarshalerContext.IdPool traceIdPool
-
spanIdPool
private final MarshalerContext.IdPool spanIdPool
-
mapPool
private final MarshalerContext.Pool<java.util.Map<?,?>> mapPool
-
listPool
private final MarshalerContext.Pool<java.util.List<?>> listPool
-
KEY_INDEX
private static final java.util.concurrent.atomic.AtomicInteger KEY_INDEX
-
instances
private java.lang.Object[] instances
-
-
Method Detail
-
marshalStringNoAllocation
public boolean marshalStringNoAllocation()
-
marshalStringUnsafe
public boolean marshalStringUnsafe()
-
addSize
public void addSize(int size)
-
addSize
public int addSize()
-
growSizeIfNeeded
private void growSizeIfNeeded()
-
setSize
public void setSize(int index, int size)
-
getSize
public int getSize()
-
addData
public void addData(@Nullable java.lang.Object o)
-
growDataIfNeeded
private void growDataIfNeeded()
-
getData
public <T> T getData(java.lang.Class<T> type)
-
getTraceIdBuffer
public byte[] getTraceIdBuffer()
Returns a buffer that can be used to hold a trace id.
-
getSpanIdBuffer
public byte[] getSpanIdBuffer()
Returns a buffer that can be used to hold a span id.
-
getIdentityMap
public <K,V> java.util.Map<K,V> getIdentityMap()
Returns a pooled identity map.
-
getList
public <T> java.util.List<T> getList()
Returns a pooled list.
-
resetReadIndex
public void resetReadIndex()
Reset context so that serialization could be re-run.
-
reset
public void reset()
Reset context so that it could be reused.
-
key
public static MarshalerContext.Key key()
-
getInstance
public <T> T getInstance(MarshalerContext.Key key, java.util.function.Supplier<T> supplier)
-
-