Package org.wildfly.common.context
Class ContextManager<C extends Contextual<C>>
java.lang.Object
org.wildfly.common.context.ContextManager<C>
- Type Parameters:
C- the public type of the contextual object
- All Implemented Interfaces:
Supplier<C>
A context manager for a
Contextual type.- Author:
- David M. Lloyd
-
Constructor Summary
ConstructorsConstructorDescriptionContextManager(Class<C> type) Construct a new instance, with a name matching the class name of the giventype.ContextManager(Class<C> type, String name) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionget()Get the currently active context, possibly examining the per-thread or global defaults.getClassLoaderDefault(ClassLoader classLoader) Get the class loader default instance.getClassLoaderDefaultSupplier(ClassLoader classLoader) Get the class loader default supplier.\Get the global default context instance.Get the global default supplier instance.Get a privileged supplier for this context manager which returns the currently active context without a permission check.Get the per-thread default context instance.Get the per-thread default context instance.voidsetClassLoaderDefault(ClassLoader classLoader, C classLoaderDefault) Set the per-class loader default instance supplier.voidsetClassLoaderDefaultSupplier(ClassLoader classLoader, Supplier<C> supplier) Set the per-class loader default instance supplier.voidsetGlobalDefault(C globalDefault) Set the global default instance.voidsetGlobalDefaultSupplier(Supplier<C> supplier) Set the global default instance supplier.booleansetGlobalDefaultSupplierIfNotSet(Supplier<Supplier<C>> supplierSupplier) Set the global default instance supplier, but only if it was not already set.voidsetThreadDefault(C threadDefault) Set the per-thread default instance.voidsetThreadDefaultSupplier(Supplier<C> supplier) Set the per-thread default instance supplier.
-
Constructor Details
-
ContextManager
Construct a new instance, with a name matching the class name of the giventype.- Parameters:
type- the type class of the context object (must not benull)
-
ContextManager
Construct a new instance.- Parameters:
type- the type class of the context object (must not benull)name- the name to use for permission checks (must not benullor empty)
-
-
Method Details
-
getGlobalDefault
Get the global default context instance. Note that the global default is determined by way of aSupplierso the returned value may vary from call to call, depending on the policy of thatSupplier.- Returns:
- the global default, or
nullif none is installed or available
-
getGlobalDefaultSupplier
Get the global default supplier instance.- Returns:
- the global default supplier, or
nullif none is installed or available
-
setGlobalDefaultSupplier
Set the global default instance supplier. The supplier, if one is given, should have a reasonable policy such that callers ofgetGlobalDefault()will obtain results consistent with a general expectation of stability.- Parameters:
supplier- the supplier, ornullto remove the global default
-
setGlobalDefaultSupplierIfNotSet
Set the global default instance supplier, but only if it was not already set. If no supplier is set, the given supplier supplier is queried to get the new value to set.- Parameters:
supplierSupplier- the supplier supplier (must not benull)- Returns:
trueif the supplier was set,falseif it was already set to something else- See Also:
-
setGlobalDefault
Set the global default instance. This instance will be returned from all subsequent calls togetGlobalDefault(), replacing any previous instance or supplier that was set.- Parameters:
globalDefault- the global default value, ornullto remove the global default
-
getClassLoaderDefault
Get the class loader default instance. Note that the class loader default is determined by way of aSupplierso the returned value may vary from call to call, depending on the policy of thatSupplier.- Parameters:
classLoader- the class loader- Returns:
- the global default, or
nullif none is installed or available
-
getClassLoaderDefaultSupplier
Get the class loader default supplier.\- Parameters:
classLoader- the class loader- Returns:
- the global default, or
nullif none is installed or available
-
setClassLoaderDefaultSupplier
Set the per-class loader default instance supplier. The supplier, if one is given, should have a reasonable policy such that callers ofgetClassLoaderDefault(ClassLoader)will obtain results consistent with a general expectation of stability.- Parameters:
classLoader- the class loader (must not benull)supplier- the supplier, ornullto remove the default for this class loader
-
setClassLoaderDefault
Set the per-class loader default instance supplier. The supplier, if one is given, should have a reasonable policy such that callers ofgetClassLoaderDefault(ClassLoader)will obtain results consistent with a general expectation of stability.- Parameters:
classLoader- the class loader (must not benull)classLoaderDefault- the class loader default value, ornullto remove the default
-
getThreadDefault
Get the per-thread default context instance. Note that the per-thread default is determined by way of aSupplierso the returned value may vary from call to call, depending on the policy of thatSupplier.- Returns:
- the per-thread default, or
nullif none is installed or available
-
getThreadDefaultSupplier
Get the per-thread default context instance.- Returns:
- the per-thread default supplier, or
nullif none is installed or available
-
setThreadDefaultSupplier
Set the per-thread default instance supplier. The supplier, if one is given, should have a reasonable policy such that callers ofgetThreadDefault()will obtain results consistent with a general expectation of stability.- Parameters:
supplier- the supplier, ornullto remove the per-thread default
-
setThreadDefault
Set the per-thread default instance. This instance will be returned from all subsequent calls togetThreadDefault(), replacing any previous instance or supplier that was set.- Parameters:
threadDefault- the per-thread default value, ornullto remove the per-thread default
-
get
Get the currently active context, possibly examining the per-thread or global defaults.- Specified by:
getin interfaceSupplier<C extends Contextual<C>>- Returns:
- the current context, or
nullif none is active
-
getPrivilegedSupplier
Get a privileged supplier for this context manager which returns the currently active context without a permission check.- Returns:
- the privileged supplier
-