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
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault ContextManagerGets aContextManagerfor the current thread-contextClassLoader.getContextManager(ClassLoader classloader) Gets aContextManagerfor the givenClassLoader.default ContextManager.BuilderReturns a newContextManager.Builderto create newContextManagerinstances.static ContextManagerProviderinstance()Obtains theContextManagerProviderinstance that has been previously registered, or usesServiceLoaderto load and register aContextManagerProviderfrom the current context class loader.register(ContextManagerProvider provider) Allows the container to register theContextManagerProviderimplementation.default voidregisterContextManager(ContextManager manager, ClassLoader classLoader) Registers the givenContextManagerfor the givenClassLoader, so that further calls togetContextManager(ClassLoader)for the sameClassLoaderwill return this instance instead of creating a new one.default voidreleaseContextManager(ContextManager manager) Releases aContextManagerthat was previously registered withregisterContextManager(ContextManager, ClassLoader).
-
Field Details
-
INSTANCE
-
-
Method Details
-
instance
Obtains theContextManagerProviderinstance that has been previously registered, or usesServiceLoaderto load and register aContextManagerProviderfrom the current context class loader.- Returns:
- the registered
ContextManagerProviderinstance. - Throws:
IllegalStateException- if there are no registeredContextManagerProviderand we could not discover any viaServiceLoader, or if there are more than oneServiceLoaderresults.
-
register
static ContextManagerProviderRegistration register(ContextManagerProvider provider) throws IllegalStateException Allows the container to register theContextManagerProviderimplementation. 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.- Parameters:
provider- the provider implementation to register.- Returns:
- registration instance that gives the caller control over unregistering.
- Throws:
IllegalStateException- if an implementation is already registered.
-
getContextManager
Gets aContextManagerfor the current thread-contextClassLoader. This is equivalent to callinggetContextManager(Thread.currentThread().getContextClassLoader()), which is the default implementation of this method.- Returns:
- a
ContextManagerfor the current thread-contextClassLoader. - Throws:
IllegalStateException- if more than oneThreadContextProviderprovides the same thread contexttype- See Also:
-
getContextManager
Gets aContextManagerfor the givenClassLoader. If there is already aContextManagerregistered for the givenClassLoaderor the context manager provider uses a single fixed set ofThreadContextProviderregardless of the class loader, the existing instance will be returned. If not, one will be created, either by provider-specific mechanisms ifContextManager.Builderis not supported, or with aContextManager.Builderusing the specifiedClassLoader(withContextManager.Builder.forClassLoader(ClassLoader)) and withContextManager.Builder.addDiscoveredThreadContextProviders()called in order to load allThreadContextProviderdiscoverable from the givenClassLoader. If created, the newContextManagerwill then be registered for the givenClassLoaderwithregisterContextManager(ContextManager, ClassLoader).- Parameters:
classloader- the class loader for which to obtain the context manager.- Returns:
- a
ContextManagerfor the givenClassLoader. - Throws:
IllegalStateException- if more than oneThreadContextProviderprovides the same thread contexttype- See Also:
-
getContextManagerBuilder
Returns a newContextManager.Builderto create newContextManagerinstances. Watch out that instances created this way will not be automatically registered here, so you need to callregisterContextManager(ContextManager, ClassLoader)yourself if you need to.- Returns:
- a new
ContextManager.Builder - Throws:
UnsupportedOperationException- if theContextManagerProvideralways uses the same set ofThreadContextProvideror is inseparable from the container.
-
registerContextManager
Registers the givenContextManagerfor the givenClassLoader, so that further calls togetContextManager(ClassLoader)for the sameClassLoaderwill return this instance instead of creating a new one.- Parameters:
manager- TheContextManagerto registerclassLoader- TheClassLoaderto register it for- Throws:
UnsupportedOperationException- if theContextManagerProvideralways uses the same set ofThreadContextProvideror is inseparable from the container.- See Also:
-
releaseContextManager
Releases aContextManagerthat was previously registered withregisterContextManager(ContextManager, ClassLoader).- Parameters:
manager- TheContextManagerto release- Throws:
UnsupportedOperationException- if theContextManagerProvideralways uses the same set ofThreadContextProvideror is inseparable from the container.- See Also:
-