public interface ContextManagerProvider
A provider implementation supplied by the
container, which creates and caches instances of
ContextManager per class loader,
which in turn create new instances of
ManagedExecutor.Builder and
ThreadContext.Builder.
The container must register its ContextManagerProvider
implementation via the register method, or by providing
an implementation via the standard ServiceLoader mechanism.
ContextManagerProvider implementations that wish to use
the ServiceLoader registration mechanism must include a file
of the following name and location in their jar:
META-INF/services/org.eclipse.microprofile.context.spi.ContextManagerProvider
The content of the aforementioned file must be exactly one line, specifying
the fully qualified name of a ContextManagerProvider implementation
that is provided within the JAR file.
If there is no manually registered ContextManagerProvider (via
register(ContextManagerProvider)), any call to instance() will
look up any ContextManagerProvider implementation via the aforementioned
ServiceLoader mechanism. If there are more than one such implementation
registered, the instance() method will throw an exception as documented
| Modifier and Type | Field and Description |
|---|---|
static AtomicReference<ContextManagerProvider> |
INSTANCE |
| Modifier and Type | Method and Description |
|---|---|
default ContextManager |
getContextManager()
Gets a
ContextManager for the current thread-context ClassLoader. |
ContextManager |
getContextManager(ClassLoader classloader)
Gets a
ContextManager for the given ClassLoader. |
default ContextManager.Builder |
getContextManagerBuilder()
Returns a new
ContextManager.Builder to create new ContextManager
instances. |
static ContextManagerProvider |
instance()
Obtains the
ContextManagerProvider instance that has been previously registered, or
uses ServiceLoader to load and register a ContextManagerProvider from the
current context class loader. |
static ContextManagerProviderRegistration |
register(ContextManagerProvider provider)
Allows the container to register the
ContextManagerProvider
implementation. |
default void |
registerContextManager(ContextManager manager,
ClassLoader classLoader)
Registers the given
ContextManager for the given ClassLoader, so that
further calls to getContextManager(ClassLoader) for the same ClassLoader
will return this instance instead of creating a new one. |
default void |
releaseContextManager(ContextManager manager)
Releases a
ContextManager that was previously registered with
registerContextManager(ContextManager, ClassLoader). |
static final AtomicReference<ContextManagerProvider> INSTANCE
static ContextManagerProvider instance()
ContextManagerProvider instance that has been previously registered, or
uses ServiceLoader to load and register a ContextManagerProvider from the
current context class loader.ContextManagerProvider instance.IllegalStateException - if there are no registered ContextManagerProvider and
we could not discover any via ServiceLoader, or if there are more than one
ServiceLoader results.static ContextManagerProviderRegistration register(ContextManagerProvider provider) throws IllegalStateException
ContextManagerProvider
implementation. At most one implementation can be registered at any
given point in time. In order to register a different implementation,
the container must first unregister its previous implementation.provider - the provider implementation to register.IllegalStateException - if an implementation is already registered.default ContextManager getContextManager()
ContextManager for the current thread-context ClassLoader. This
is equivalent to calling getContextManager(Thread.currentThread().getContextClassLoader()),
which is the default implementation of this method.ContextManager for the current thread-context ClassLoader.IllegalStateException - if more than one ThreadContextProvider
provides the same thread context typegetContextManager(ClassLoader)ContextManager getContextManager(ClassLoader classloader)
ContextManager for the given ClassLoader. If there is already
a ContextManager registered for the given ClassLoader or the context manager provider
uses a single fixed set of ThreadContextProvider regardless of the class loader, the existing
instance will be returned. If not, one will be created, either by provider-specific mechanisms
if ContextManager.Builder is not supported, or with a ContextManager.Builder
using the specified ClassLoader (with ContextManager.Builder.forClassLoader(ClassLoader))
and with ContextManager.Builder.addDiscoveredThreadContextProviders() called in
order to load all ThreadContextProvider discoverable from the given ClassLoader.
If created, the new ContextManager will then be registered for the given ClassLoader
with registerContextManager(ContextManager, ClassLoader).classloader - the class loader for which to obtain the context manager.ContextManager for the given ClassLoader.IllegalStateException - if more than one ThreadContextProvider
provides the same thread context typeContextManager.Builder.addDiscoveredThreadContextProviders(),
ContextManager.Builder.build(),
registerContextManager(ContextManager, ClassLoader)default ContextManager.Builder getContextManagerBuilder()
ContextManager.Builder to create new ContextManager
instances. Watch out that instances created this way will not be automatically registered
here, so you need to call registerContextManager(ContextManager, ClassLoader)
yourself if you need to.ContextManager.BuilderUnsupportedOperationException - if the ContextManagerProvider
always uses the same set of ThreadContextProvider
or is inseparable from the container.default void registerContextManager(ContextManager manager, ClassLoader classLoader)
ContextManager for the given ClassLoader, so that
further calls to getContextManager(ClassLoader) for the same ClassLoader
will return this instance instead of creating a new one.manager - The ContextManager to registerclassLoader - The ClassLoader to register it forUnsupportedOperationException - if the ContextManagerProvider
always uses the same set of ThreadContextProvider
or is inseparable from the container.getContextManager(ClassLoader),
releaseContextManager(ContextManager)default void releaseContextManager(ContextManager manager)
ContextManager that was previously registered with
registerContextManager(ContextManager, ClassLoader).manager - The ContextManager to releaseUnsupportedOperationException - if the ContextManagerProvider
always uses the same set of ThreadContextProvider
or is inseparable from the container.registerContextManager(ContextManager, ClassLoader)Copyright © 2018 ‘ 2021 Eclipse Foundation. All rights reserved.
Use is subject to license terms.