Class VirtualField<T,F>
- java.lang.Object
-
- io.opentelemetry.instrumentation.api.field.VirtualField<T,F>
-
- Type Parameters:
T- The type that will contain the new virtual field.F- The field type that'll be added toT.
public abstract class VirtualField<T,F> extends Object
Represents a "virtual" field of typeFthat is added to typeTin the runtime.A virtual field has similar semantics to a weak-keys strong-values map: the value will be garbage collected when their owner instance is collected. It is discouraged to use a virtual field for keeping values that might reference their key, as it may cause memory leaks.
-
-
Constructor Summary
Constructors Constructor Description VirtualField()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <U extends T,V extends F,T,F>
VirtualField<U,V>find(Class<T> type, Class<F> fieldType)abstract Fget(T object)Gets the value of this virtual field.abstract voidset(T object, F fieldValue)Sets the new value of this virtual field.
-
-
-
Method Detail
-
find
public static <U extends T,V extends F,T,F> VirtualField<U,V> find(Class<T> type, Class<F> fieldType)
Finds aVirtualFieldinstance for giventypeandfieldType.Conceptually this can be thought of as a map lookup to fetch a second level map given
type.In runtime, when using the javaagent, the calls to this method are rewritten to something more performant while injecting advice into a method.
When using this method outside of Advice method, the
VirtualFieldshould be looked up once and stored in a field to avoid repeatedly calling this method.- Parameters:
type- The type that will contain the new virtual field.fieldType- The field type that will be added totype.
-
-