Top Description Inners Fields Constructors Methods
org.wildfly.common.context

public final Class ContextManager<C extends org.wildfly.common.context.Contextual<C>>

extends Object
implements Supplier<C extends Contextual<C>>
Class Inheritance
All Implemented Interfaces
java.util.function.Supplier
Type Parameters
<C>
the public type of the contextual object
Static Imports
java.security.AccessController.doPrivileged

A context manager for a Contextual type.
Author
David M. Lloyd

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private final ContextPermission
private final AtomicReference<Supplier<C>>
private final String
private final ConcurrentHashMap<ClassLoader, Supplier<C>>
private final ThreadLocal<ContextManager.State<C>>
private final Class<C>

Constructor Summary

AccessConstructor and Description
public
ContextManager(final Class<C>
the type class of the context object (must not be null)
type
)

Construct a new instance, with a name matching the class name of the given type.

public
ContextManager(final Class<C>
the type class of the context object (must not be null)
type
,
final String
the name to use for permission checks (must not be null or empty)
name
)

Construct a new instance.

Method Summary

Modifier and TypeMethod and Description
public C

Returns:

the current context, or null if none is active
get
()

Implements java.util.function.Supplier.get.

Get the currently active context, possibly examining the per-thread or global defaults.
pack-priv C
public C

Returns:

the global default, or null if none is installed or available
getClassLoaderDefault
(final ClassLoader
the class loader
classLoader
)

Get the class loader default instance.

public Supplier<C>

Returns:

the global default, or null if none is installed or available
getClassLoaderDefaultSupplier
(final ClassLoader
the class loader
classLoader
)

Get the class loader default supplier.\

public C

Returns:

the global default, or null if none is installed or available
getGlobalDefault
()

Get the global default context instance.

public Supplier<C>

Returns:

the global default supplier, or null if none is installed or available
getGlobalDefaultSupplier
()

Get the global default supplier instance.

private C
public Supplier<C>

Returns:

the privileged supplier
getPrivilegedSupplier
()

Get a privileged supplier for this context manager which returns the currently active context without a permission check.

public C

Returns:

the per-thread default, or null if none is installed or available
getThreadDefault
()

Get the per-thread default context instance.

public Supplier<C>

Returns:

the per-thread default supplier, or null if none is installed or available
getThreadDefaultSupplier
()

Get the per-thread default context instance.

pack-priv void
restoreCurrent(C oldVal)

public void
setClassLoaderDefault(final ClassLoader
the class loader (must not be null)
classLoader
,
final C
the class loader default value, or null to remove the default
classLoaderDefault
)

Set the per-class loader default instance supplier.

public void
setClassLoaderDefaultSupplier(final ClassLoader
the class loader (must not be null)
classLoader
,
final Supplier<C>
the supplier, or null to remove the default for this class loader
supplier
)

Set the per-class loader default instance supplier.

public void
setGlobalDefault(final C
the global default value, or null to remove the global default
globalDefault
)

Set the global default instance.

public void
setGlobalDefaultSupplier(final Supplier<C>
the supplier, or null to remove the global default
supplier
)

Set the global default instance supplier.

public boolean

Returns:

true if the supplier was set, false if it was already set to something else
setGlobalDefaultSupplierIfNotSet
(final Supplier<Supplier<C>>
the supplier supplier (must not be null)
supplierSupplier
)

Set the global default instance supplier, but only if it was not already set.

public void
setThreadDefault(final C
the per-thread default value, or null to remove the per-thread default
threadDefault
)

Set the per-thread default instance.

public void
setThreadDefaultSupplier(final Supplier<C>
the supplier, or null to remove the per-thread default
supplier
)

Set the per-thread default instance supplier.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

getPermissionback to summary
private final ContextPermission getPermission
globalDefaultSupplierRefback to summary
private final AtomicReference<Supplier<C>> globalDefaultSupplierRef
nameback to summary
private final String name
perClassLoaderDefaultback to summary
private final ConcurrentHashMap<ClassLoader, Supplier<C>> perClassLoaderDefault
stateRefback to summary
private final ThreadLocal<ContextManager.State<C>> stateRef
typeback to summary
private final Class<C> type

Constructor Detail

ContextManagerback to summary
public ContextManager(final Class<C> type)

Construct a new instance, with a name matching the class name of the given type.

Parameters
type:Class<C>

the type class of the context object (must not be null)

ContextManagerback to summary
public ContextManager(final Class<C> type, final String name)

Construct a new instance.

Parameters
type:Class<C>

the type class of the context object (must not be null)

name:String

the name to use for permission checks (must not be null or empty)

Method Detail

getback to summary
public C get()

Implements java.util.function.Supplier.get.

Get the currently active context, possibly examining the per-thread or global defaults.

Returns:C

the current context, or null if none is active

getAndSetCurrentback to summary
pack-priv C getAndSetCurrent(Contextual<C> newVal)
getClassLoaderDefaultback to summary
public C getClassLoaderDefault(final ClassLoader classLoader)

Get the class loader default instance. Note that the class loader default is determined by way of a Supplier so the returned value may vary from call to call, depending on the policy of that Supplier.

Parameters
classLoader:ClassLoader

the class loader

Returns:C

the global default, or null if none is installed or available

getClassLoaderDefaultSupplierback to summary
public Supplier<C> getClassLoaderDefaultSupplier(final ClassLoader classLoader)

Get the class loader default supplier.\

Parameters
classLoader:ClassLoader

the class loader

Returns:Supplier<C>

the global default, or null if none is installed or available

getGlobalDefaultback to summary
public C getGlobalDefault()

Get the global default context instance. Note that the global default is determined by way of a Supplier so the returned value may vary from call to call, depending on the policy of that Supplier.

Returns:C

the global default, or null if none is installed or available

getGlobalDefaultSupplierback to summary
public Supplier<C> getGlobalDefaultSupplier()

Get the global default supplier instance.

Returns:Supplier<C>

the global default supplier, or null if none is installed or available

getPrivilegedback to summary
private C getPrivileged()
getPrivilegedSupplierback to summary
public Supplier<C> getPrivilegedSupplier()

Get a privileged supplier for this context manager which returns the currently active context without a permission check.

Returns:Supplier<C>

the privileged supplier

getThreadDefaultback to summary
public C getThreadDefault()

Get the per-thread default context instance. Note that the per-thread default is determined by way of a Supplier so the returned value may vary from call to call, depending on the policy of that Supplier.

Returns:C

the per-thread default, or null if none is installed or available

getThreadDefaultSupplierback to summary
public Supplier<C> getThreadDefaultSupplier()

Get the per-thread default context instance.

Returns:Supplier<C>

the per-thread default supplier, or null if none is installed or available

restoreCurrentback to summary
pack-priv void restoreCurrent(C oldVal)
setClassLoaderDefaultback to summary
public void setClassLoaderDefault(final ClassLoader classLoader, final C classLoaderDefault)

Set the per-class loader default instance supplier. The supplier, if one is given, should have a reasonable policy such that callers of getClassLoaderDefault(ClassLoader) will obtain results consistent with a general expectation of stability.

Parameters
classLoader:ClassLoader

the class loader (must not be null)

classLoaderDefault:C

the class loader default value, or null to remove the default

setClassLoaderDefaultSupplierback to summary
public void setClassLoaderDefaultSupplier(final ClassLoader classLoader, final Supplier<C> supplier)

Set the per-class loader default instance supplier. The supplier, if one is given, should have a reasonable policy such that callers of getClassLoaderDefault(ClassLoader) will obtain results consistent with a general expectation of stability.

Parameters
classLoader:ClassLoader

the class loader (must not be null)

supplier:Supplier<C>

the supplier, or null to remove the default for this class loader

setGlobalDefaultback to summary
public void setGlobalDefault(final C globalDefault)

Set the global default instance. This instance will be returned from all subsequent calls to getGlobalDefault(), replacing any previous instance or supplier that was set.

Parameters
globalDefault:C

the global default value, or null to remove the global default

setGlobalDefaultSupplierback to summary
public void setGlobalDefaultSupplier(final Supplier<C> supplier)

Set the global default instance supplier. The supplier, if one is given, should have a reasonable policy such that callers of getGlobalDefault() will obtain results consistent with a general expectation of stability.

Parameters
supplier:Supplier<C>

the supplier, or null to remove the global default

setGlobalDefaultSupplierIfNotSetback to summary
public boolean setGlobalDefaultSupplierIfNotSet(final Supplier<Supplier<C>> supplierSupplier)

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:Supplier<Supplier<C>>

the supplier supplier (must not be null)

Returns:boolean

true if the supplier was set, false if it was already set to something else

See Also
setGlobalDefaultSupplier(Supplier)
setThreadDefaultback to summary
public void setThreadDefault(final C threadDefault)

Set the per-thread default instance. This instance will be returned from all subsequent calls to getThreadDefault(), replacing any previous instance or supplier that was set.

Parameters
threadDefault:C

the per-thread default value, or null to remove the per-thread default

setThreadDefaultSupplierback to summary
public void setThreadDefaultSupplier(final Supplier<C> supplier)

Set the per-thread default instance supplier. The supplier, if one is given, should have a reasonable policy such that callers of getThreadDefault() will obtain results consistent with a general expectation of stability.

Parameters
supplier:Supplier<C>

the supplier, or null to remove the per-thread default

org.wildfly.common.context back to summary

pack-priv Class ContextManager.State<T>

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv T
pack-priv Supplier<T>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentback to summary
pack-priv T current
defaultSupplierback to summary
pack-priv Supplier<T> defaultSupplier

Constructor Detail

Stateback to summary
pack-priv State()