Package io.opentelemetry.context
Class StrictContextStorage
- java.lang.Object
-
- io.opentelemetry.context.StrictContextStorage
-
- All Implemented Interfaces:
ContextStorage,java.lang.AutoCloseable
final class StrictContextStorage extends java.lang.Object implements ContextStorage, java.lang.AutoCloseable
AContextStoragewhich keeps track of opened and closedScopes, reporting caller information if aScopeis closed incorrectly or not at all.Calling
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 Class Summary
Nested Classes Modifier and Type Class Description (package private) static classStrictContextStorage.CallerStackTrace(package private) static classStrictContextStorage.PendingScopes(package private) classStrictContextStorage.StrictScope
-
Field Summary
Fields Modifier and Type Field Description private ContextStoragedelegateprivate static java.util.logging.Loggerloggerprivate StrictContextStorage.PendingScopespendingScopes
-
Constructor Summary
Constructors Modifier Constructor Description privateStrictContextStorage(ContextStorage delegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Scopeattach(Context context)(package private) static java.lang.AssertionErrorcallerError(StrictContextStorage.CallerStackTrace caller)voidclose()Ensures all scopes that have been created by this storage have been closed.(package private) static StrictContextStoragecreate(ContextStorage delegate)Returns a newStrictContextStoragewhich delegates to the providedContextStorage, wrapping created scopes to track their usage.Contextcurrent()Returns the currentContext.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.opentelemetry.context.ContextStorage
root
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
delegate
private final ContextStorage delegate
-
pendingScopes
private final StrictContextStorage.PendingScopes pendingScopes
-
-
Constructor Detail
-
StrictContextStorage
private StrictContextStorage(ContextStorage delegate)
-
-
Method Detail
-
create
static StrictContextStorage create(ContextStorage delegate)
Returns a newStrictContextStoragewhich delegates to the providedContextStorage, wrapping created scopes to track their usage.
-
attach
public Scope attach(Context context)
Description copied from interface:ContextStorageSets the specifiedContextas the currentContextand returns aScoperepresenting the scope of execution.Scope.close()must be called when the currentContextshould be restored to what it was before attachingtoAttach.- Specified by:
attachin interfaceContextStorage
-
current
@Nullable public Context current()
Description copied from interface:ContextStorage- Specified by:
currentin interfaceContextStorage
-
close
public void 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.
- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.lang.AssertionError- if any scopes were left unclosed.
-
callerError
static java.lang.AssertionError callerError(StrictContextStorage.CallerStackTrace caller)
-
-