Top Description Inners Fields Constructors Methods
io.opentelemetry.context

pack-priv final Class StrictContextStorage

extends Object
implements ContextStorage, AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable, io.opentelemetry.context.ContextStorage
Static Imports
java.lang.Thread.currentThread

A ContextStorage which keeps track of opened and closed Scopes, reporting caller information if a Scope is closed incorrectly or not at all.

Calling StrictContextStorage#close() will check at the moment it's called whether there are any scopes that have been opened but not closed yet. This could be called at the end of a unit test to ensure the tested code cleaned up scopes correctly.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class
pack-priv class

Field Summary

Modifier and TypeField and Description
private final ContextStorage
private static final Logger
private final StrictContextStorage.PendingScopes

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Scope
attach(Context context)

Implements io.opentelemetry.context.ContextStorage.attach.

Sets the specified Context as the current Context and returns a Scope representing the scope of execution.

pack-priv static AssertionError
public void
close()

Implements java.lang.AutoCloseable.close.

Ensures all scopes that have been created by this storage have been closed.

pack-priv static StrictContextStorage
create(ContextStorage delegate)

Returns a new StrictContextStorage which delegates to the provided ContextStorage, wrapping created scopes to track their usage.

public Context
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

delegateback to summary
private final ContextStorage delegate
loggerback to summary
private static final Logger logger
pendingScopesback to summary
private final StrictContextStorage.PendingScopes pendingScopes

Constructor Detail

StrictContextStorageback to summary
private StrictContextStorage(ContextStorage delegate)

Method Detail

attachback to summary
public Scope attach(Context context)

Implements io.opentelemetry.context.ContextStorage.attach.

Doc from io.opentelemetry.context.ContextStorage.attach.

Sets the specified Context as the current Context and returns a Scope representing the scope of execution. Scope#close() must be called when the current Context should be restored to what it was before attaching toAttach.

Annotations
@Override
callerErrorback to summary
pack-priv static AssertionError callerError(StrictContextStorage.CallerStackTrace caller)
closeback to summary
public void close()

Implements java.lang.AutoCloseable.close.

Ensures all scopes that have been created by this storage have been closed. This can be useful to call at the end of a test to make sure everything has been cleaned up.

Note

It is important to close all resources prior to calling this, so that in-flight operations are not mistaken as scope leaks. If this raises an error, consider if a Context#wrap(Executor) wrapped executor} is still running.

Annotations
@Override
Exceptions
AssertionError:
if any scopes were left unclosed.
createback to summary
pack-priv static StrictContextStorage create(ContextStorage delegate)

Returns a new StrictContextStorage which delegates to the provided ContextStorage, wrapping created scopes to track their usage.

currentback to summary
public Context current()

Implements io.opentelemetry.context.ContextStorage.current.

Doc from io.opentelemetry.context.ContextStorage.current.

Returns the current Context. If no Context has been attached yet, this will return null.

Annotations
@Override
@Nullable
io.opentelemetry.context back to summary

pack-priv Class StrictContextStorage.CallerStackTrace

extends Throwable
Class Inheritance
Annotations
@SuppressWarnings:serial

Field Summary

Modifier and TypeField and Description
pack-priv volatile boolean
pack-priv final Context
pack-priv final long
pack-priv final String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Throwable:
addSuppressedfillInStackTracegetCausegetLocalizedMessagegetMessagegetStackTracegetSuppressedinitCauseprintStackTraceprintStackTraceprintStackTracesetStackTracetoString

Field Detail

closedback to summary
pack-priv volatile boolean closed
contextback to summary
pack-priv final Context context
threadIdback to summary
pack-priv final long threadId
threadNameback to summary
pack-priv final String threadName

Constructor Detail

CallerStackTraceback to summary
pack-priv CallerStackTrace(Context context)
io.opentelemetry.context back to summary

pack-priv Class StrictContextStorage.PendingScopes

extends WeakConcurrentMap<Scope, StrictContextStorage.CallerStackTrace>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final ConcurrentHashMap<AbstractWeakConcurrentMap.WeakKey<Scope>, StrictContextStorage.CallerStackTrace>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static StrictContextStorage.PendingScopes
pack-priv List<StrictContextStorage.CallerStackTrace>
public void
Inherited from io.opentelemetry.context.internal.shaded.WeakConcurrentMap:
getCleanerThreadgetLookupKeyresetLookupKey

Field Detail

mapback to summary
private final ConcurrentHashMap<AbstractWeakConcurrentMap.WeakKey<Scope>, StrictContextStorage.CallerStackTrace> map

Constructor Detail

PendingScopesback to summary
pack-priv PendingScopes(ConcurrentHashMap<AbstractWeakConcurrentMap.WeakKey<Scope>, StrictContextStorage.CallerStackTrace> map)
Annotations
@SuppressWarnings:ThreadPriorityCheck

Method Detail

createback to summary
pack-priv static StrictContextStorage.PendingScopes create()
drainPendingCallersback to summary
pack-priv List<StrictContextStorage.CallerStackTrace> drainPendingCallers()
runback to summary
public void run()

Overrides io.opentelemetry.context.internal.shaded.AbstractWeakConcurrentMap.run.

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
io.opentelemetry.context back to summary

pack-priv final Class StrictContextStorage.StrictScope

extends Object
implements Scope
Class Inheritance
All Implemented Interfaces
io.opentelemetry.context.Scope, java.lang.AutoCloseable

Field Summary

Modifier and TypeField and Description
pack-priv final StrictContextStorage.CallerStackTrace
pack-priv final Scope

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements io.opentelemetry.context.Scope.close.

Closes this resource, relinquishing any underlying resources.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

callerback to summary
pack-priv final StrictContextStorage.CallerStackTrace caller
delegateback to summary
pack-priv final Scope delegate

Constructor Detail

StrictScopeback to summary
pack-priv StrictScope(Scope delegate, StrictContextStorage.CallerStackTrace caller)

Method Detail

closeback to summary
public void close()

Implements io.opentelemetry.context.Scope.close.

Doc from java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override