C - the public type of the contextual objectjava.util.function.Supplier<C>public final class ContextManager<C extends Contextual<C>>
extends java.lang.Object
implements java.util.function.Supplier<C>
Contextual type.| Constructor | Description |
|---|---|
ContextManager(java.lang.Class<C> type) |
Construct a new instance, with a name matching the class name of the given
type. |
ContextManager(java.lang.Class<C> type,
java.lang.String name) |
Construct a new instance.
|
| Modifier and Type | Method | Description |
|---|---|---|
C |
get() |
Get the currently active context, possibly examining the per-thread or global defaults.
|
C |
getClassLoaderDefault(java.lang.ClassLoader classLoader) |
Get the class loader default instance.
|
C |
getGlobalDefault() |
Get the global default context instance.
|
java.util.function.Supplier<C> |
getPrivilegedSupplier() |
Get a privileged supplier for this context manager which returns the currently active context without a permission
check.
|
C |
getThreadDefault() |
Get the per-thread default context instance.
|
void |
setClassLoaderDefault(java.lang.ClassLoader classLoader,
C classLoaderDefault) |
Set the per-class loader default instance supplier.
|
void |
setClassLoaderDefaultSupplier(java.lang.ClassLoader classLoader,
java.util.function.Supplier<C> supplier) |
Set the per-class loader default instance supplier.
|
void |
setGlobalDefault(C globalDefault) |
Set the global default instance.
|
void |
setGlobalDefaultSupplier(java.util.function.Supplier<C> supplier) |
Set the global default instance supplier.
|
boolean |
setGlobalDefaultSupplierIfNotSet(java.util.function.Supplier<java.util.function.Supplier<C>> supplierSupplier) |
Set the global default instance supplier, but only if it was not already set.
|
void |
setThreadDefault(C threadDefault) |
Set the per-thread default instance.
|
void |
setThreadDefaultSupplier(java.util.function.Supplier<C> supplier) |
Set the per-thread default instance supplier.
|
public ContextManager(java.lang.Class<C> type)
type.type - the type class of the context object (must not be null)public ContextManager(java.lang.Class<C> type, java.lang.String name)
type - the type class of the context object (must not be null)name - the name to use for permission checks (must not be null or empty)public C getGlobalDefault()
Supplier so
the returned value may vary from call to call, depending on the policy of that Supplier.null if none is installed or availablepublic void setGlobalDefaultSupplier(java.util.function.Supplier<C> supplier)
getGlobalDefault() will obtain results consistent with a general expectation of stability.supplier - the supplier, or null to remove the global defaultpublic boolean setGlobalDefaultSupplierIfNotSet(java.util.function.Supplier<java.util.function.Supplier<C>> supplierSupplier)
supplierSupplier - the supplier supplier (must not be null)true if the supplier was set, false if it was already set to something elsesetGlobalDefaultSupplier(Supplier)public void setGlobalDefault(C globalDefault)
getGlobalDefault(),
replacing any previous instance or supplier that was set.globalDefault - the global default value, or null to remove the global defaultpublic C getClassLoaderDefault(java.lang.ClassLoader classLoader)
Supplier so
the returned value may vary from call to call, depending on the policy of that Supplier.classLoader - the class loadernull if none is installed or availablepublic void setClassLoaderDefaultSupplier(java.lang.ClassLoader classLoader,
java.util.function.Supplier<C> supplier)
getClassLoaderDefault(ClassLoader) will obtain results consistent with a general expectation of stability.classLoader - the class loader (must not be null)supplier - the supplier, or null to remove the default for this class loaderpublic void setClassLoaderDefault(java.lang.ClassLoader classLoader,
C classLoaderDefault)
getClassLoaderDefault(ClassLoader) will obtain results consistent with a general expectation of stability.classLoader - the class loader (must not be null)classLoaderDefault - the class loader default value, or null to remove the defaultpublic C getThreadDefault()
Supplier so
the returned value may vary from call to call, depending on the policy of that Supplier.null if none is installed or availablepublic void setThreadDefaultSupplier(java.util.function.Supplier<C> supplier)
getThreadDefault() will obtain results consistent with a general expectation of stability.supplier - the supplier, or null to remove the per-thread defaultpublic void setThreadDefault(C threadDefault)
getThreadDefault(),
replacing any previous instance or supplier that was set.threadDefault - the per-thread default value, or null to remove the per-thread defaultpublic C get()
get in interface java.util.function.Supplier<C extends Contextual<C>>null if none is activepublic java.util.function.Supplier<C> getPrivilegedSupplier()
Copyright © 2017 JBoss, a division of Red Hat, Inc.