AutoCloseable, Closeable, nl.talsmasoftware.context.Context<T>AbstractThreadLocalContext, LegacyContextnl.talsmasoftware.context.Contextpublic interface Context<T>
extends nl.talsmasoftware.context.Context<T>
Implementations are typically maintained within a static ThreadLocal variable. A context has a very simple
life-cycle: they can be created and closed.
A well-behaved Context implementation will make sure that things are restored the way they were when
the context gets closed.
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
Deprecated.
Closes this context and restores any context changes made by this object to the way things were before it
got created.
|
T |
getValue() |
Deprecated.
Returns the value associated with this context.
|
T getValue()
Implementors should explicitly document the behaviour of this method after close() was called.
For example, it may be useful to always return null after a Context has been
closed.
Contrary, it may in some cases be useful to retain the existing value after the context is closed,
so clients that have kept a reference can still have access to it.
Normally, for security-related contexts, it is wise to always return null from closed contexts.
getValue in interface nl.talsmasoftware.context.Context<T>void close()
It must be possible to call this method multiple times.
It is the responsibility of the implementor of this context to make sure that closing an already-closed context
has no unwanted side-effects.
A simple way to achieve this is by using an AtomicBoolean to make sure the
'closing' transition is executed only once.
close in interface AutoCloseableclose in interface Closeableclose in interface nl.talsmasoftware.context.Context<T>RuntimeException - if an error occurs while restoring the context.Copyright © 2016–2018 Talsma ICT. All rights reserved.