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
AContextStorage
which keeps track of opened and closedScope
s, reporting caller information if aScope
is 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 class
StrictContextStorage.CallerStackTrace
(package private) static class
StrictContextStorage.PendingScopes
(package private) class
StrictContextStorage.StrictScope
-
Field Summary
Fields Modifier and Type Field Description private ContextStorage
delegate
private static java.util.logging.Logger
logger
private StrictContextStorage.PendingScopes
pendingScopes
-
Constructor Summary
Constructors Modifier Constructor Description private
StrictContextStorage(ContextStorage delegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Scope
attach(Context context)
(package private) static java.lang.AssertionError
callerError(StrictContextStorage.CallerStackTrace caller)
void
close()
Ensures all scopes that have been created by this storage have been closed.(package private) static StrictContextStorage
create(ContextStorage delegate)
Returns a newStrictContextStorage
which delegates to the providedContextStorage
, wrapping created scopes to track their usage.Context
current()
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 newStrictContextStorage
which delegates to the providedContextStorage
, wrapping created scopes to track their usage.
-
attach
public Scope attach(Context context)
Description copied from interface:ContextStorage
Sets the specifiedContext
as the currentContext
and returns aScope
representing the scope of execution.Scope.close()
must be called when the currentContext
should be restored to what it was before attachingtoAttach
.- Specified by:
attach
in interfaceContextStorage
-
current
@Nullable public Context current()
Description copied from interface:ContextStorage
- Specified by:
current
in 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:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.lang.AssertionError
- if any scopes were left unclosed.
-
callerError
static java.lang.AssertionError callerError(StrictContextStorage.CallerStackTrace caller)
-
-