@Immutable public final class ExecutionContext extends Object implements ThreadPoolFactory, Cloneable, NamespaceRegistry.Holder
ExecutionContext instances are immutable
, so components may hold onto references to them without concern of
those contexts changing. Contexts may be used to create other contexts that vary the environment and/or security context. For
example, an ExecutionContext could be used to create another context that references the same namespace registry
but which has a different security context
.
Modifier and Type | Class and Description |
---|---|
protected class |
ExecutionContext.ContextFactories |
Modifier and Type | Field and Description |
---|---|
static ExecutionContext |
DEFAULT_CONTEXT |
Modifier | Constructor and Description |
---|---|
|
ExecutionContext()
Create an instance of an execution context that uses the
current JAAS calling context
, with default implementations for all other components (including default namespaces in the
namespace registry . |
protected |
ExecutionContext(ExecutionContext context) |
protected |
ExecutionContext(SecurityContext securityContext,
NamespaceRegistry namespaceRegistry,
PropertyFactory propertyFactory,
ThreadPoolFactory threadPoolFactory,
BinaryStore binaryStore,
Map<String,String> data,
String processId,
TextDecoder decoder,
TextEncoder encoder,
StringFactory stringFactory,
BinaryFactory binaryFactory,
ValueFactory<Boolean> booleanFactory,
DateTimeFactory dateFactory,
ValueFactory<BigDecimal> decimalFactory,
ValueFactory<Double> doubleFactory,
ValueFactory<Long> longFactory,
NameFactory nameFactory,
PathFactory pathFactory,
ReferenceFactory referenceFactory,
ReferenceFactory weakReferenceFactory,
ReferenceFactory simpleReferenceFactory,
UriFactory uriFactory,
ValueFactory<Object> objectFactory,
Locale locale)
Create an instance of the execution context by supplying all parameters.
|
Modifier and Type | Method and Description |
---|---|
ExecutionContext |
clone() |
BinaryStore |
getBinaryStore()
Get the binary store that should be used to store binary values.
|
ExecutorService |
getCachedTreadPool(String name,
int maxPoolSize)
Signal that the supplied thread pool is no longer needed.
|
Map<String,String> |
getData()
Get the immutable map of custom data that is affiliated with this context.
|
TextDecoder |
getDecoder()
Get the text decoder for this context.
|
String |
getId()
Get the unique identifier for this context.
|
Logger |
getLogger(Class<?> clazz)
Return a logger associated with this context.
|
Logger |
getLogger(String name)
Return a logger associated with this context.
|
NamespaceRegistry |
getNamespaceRegistry()
Get the (mutable) namespace registry for this context.
|
String |
getProcessId()
Get the identifier for the process in which this context exists.
|
PropertyFactory |
getPropertyFactory()
Get the factory for creating
Property objects. |
ScheduledExecutorService |
getScheduledThreadPool(String name)
Obtain a scheduled thread pool with the supplied name, or create and return one if no thread pool exists with that name.
|
SecurityContext |
getSecurityContext()
Get the
security context for this context. |
ExecutorService |
getThreadPool(String name)
Obtain a thread pool with the supplied name, or create and return one if no thread pool exists with that name.
|
protected ThreadPoolFactory |
getThreadPoolFactory() |
ValueFactories |
getValueFactories()
Get the factories that should be used to create values for
properties . |
protected void |
initializeDefaultNamespaces(NamespaceRegistry namespaceRegistry)
Method that initializes the default namespaces for namespace registries.
|
void |
releaseThreadPool(ExecutorService pool)
Performs a
ExecutorService.shutdownNow() on the given pool, if the pool has been created
previously by this class. |
void |
terminateAllPools(long maxWaitTime,
TimeUnit timeUnit)
Terminates all the existing thread pool, by waiting for them maximum
maxWaitTimeMillis milliseconds, after which
calling ExecutorService.shutdownNow() . |
String |
toString() |
ExecutionContext |
with(BinaryStore binaryStore)
Create a new execution context that mirrors this context but that uses the supplied binary store.
|
ExecutionContext |
with(Locale locale)
Create a new execution context that mirrors this context but that contains the supplied locale.
|
ExecutionContext |
with(Map<String,String> data)
Create a new execution context that mirrors this context but that contains the supplied data.
|
ExecutionContext |
with(NamespaceRegistry namespaceRegistry)
Create a new execution context that mirrors this context but that uses the supplied namespace registry.
|
ExecutionContext |
with(PropertyFactory propertyFactory)
Create a new execution context that mirrors this context but that uses the supplied
factory . |
protected ExecutionContext |
with(ReferenceFactory referenceFactory) |
ExecutionContext |
with(SecurityContext securityContext)
Create an
ExecutionContext that is the same as this context, but which uses the supplied security context . |
ExecutionContext |
with(String processId)
Create a new execution context that mirrors this context but that contains the supplied process identifier.
|
ExecutionContext |
with(String key,
String value)
Create a new execution context that mirrors this context but that contains the supplied key-value pair in the new context's
data.
|
ExecutionContext |
with(ThreadPoolFactory threadPoolFactory)
Create a new execution context that mirrors this context but that uses the supplied
thread pool
factory . |
public static final ExecutionContext DEFAULT_CONTEXT
public ExecutionContext()
current JAAS calling context
, with default implementations for all other components (including default namespaces in the
namespace registry
.protected ExecutionContext(ExecutionContext context)
protected ExecutionContext(SecurityContext securityContext, NamespaceRegistry namespaceRegistry, PropertyFactory propertyFactory, ThreadPoolFactory threadPoolFactory, BinaryStore binaryStore, Map<String,String> data, String processId, TextDecoder decoder, TextEncoder encoder, StringFactory stringFactory, BinaryFactory binaryFactory, ValueFactory<Boolean> booleanFactory, DateTimeFactory dateFactory, ValueFactory<BigDecimal> decimalFactory, ValueFactory<Double> doubleFactory, ValueFactory<Long> longFactory, NameFactory nameFactory, PathFactory pathFactory, ReferenceFactory referenceFactory, ReferenceFactory weakReferenceFactory, ReferenceFactory simpleReferenceFactory, UriFactory uriFactory, ValueFactory<Object> objectFactory, Locale locale)
securityContext
- the security context, or null if there is no associated authenticated usernamespaceRegistry
- the namespace registry implementation, or null if a thread-safe version of
SimpleNamespaceRegistry
instance should be usedpropertyFactory
- the PropertyFactory
implementation, or null if a BasicPropertyFactory
instance
should be usedthreadPoolFactory
- the ThreadPoolFactory
implementation, or null if a ThreadPools
instance should be
usedbinaryStore
- the BinaryStore
implementation, or null if a default TransientBinaryStore
should be useddata
- the custom data for this context, or null if there is no such dataprocessId
- the unique identifier of the process in which this context exists, or null if it should be generateddecoder
- the decoder that should be used; if null, the default decoder
is used.encoder
- the encoder that should be used; if null, the default encoder
is used.stringFactory
- the string factory that should be used; if null, a default implementation will be usedbinaryFactory
- the binary factory that should be used; if null, a default implementation will be usedbooleanFactory
- the boolean factory that should be used; if null, a default implementation will be useddateFactory
- the date factory that should be used; if null, a default implementation will be useddecimalFactory
- the decimal factory that should be used; if null, a default implementation will be useddoubleFactory
- the double factory that should be used; if null, a default implementation will be usedlongFactory
- the long factory that should be used; if null, a default implementation will be usednameFactory
- the name factory that should be used; if null, a default implementation will be usedpathFactory
- the path factory that should be used; if null, a default implementation will be usedreferenceFactory
- the strong reference factory that should be used; if null, a default implementation will be usedweakReferenceFactory
- the weak reference factory that should be used; if null, a default implementation will be usedsimpleReferenceFactory
- the simple reference factory that should be used; if null, a default implementation will be useduriFactory
- the URI factory that should be used; if null, a default implementation will be usedobjectFactory
- the object factory that should be used; if null, a default implementation will be usedlocale
- an optional Locale than can be used; if null it will be ignoredprotected ThreadPoolFactory getThreadPoolFactory()
public Logger getLogger(Class<?> clazz)
obtain a system logger
.clazz
- the class that is doing the loggingclazz
; never nullgetLogger(String)
public Logger getLogger(String name)
obtain a system logger
.name
- the name for the loggerclazz
; never nullgetLogger(Class)
public SecurityContext getSecurityContext()
security context
for this context.null
public NamespaceRegistry getNamespaceRegistry()
getNamespaceRegistry
in interface NamespaceRegistry.Holder
null
public final PropertyFactory getPropertyFactory()
Property
objects.null
public ValueFactories getValueFactories()
properties
.public BinaryStore getBinaryStore()
BinaryFactory
in the
getValueFactories()
.public ExecutorService getThreadPool(String name)
ThreadPoolFactory
released
.getThreadPool
in interface ThreadPoolFactory
name
- the name of the thread pool; may not be nullpublic void releaseThreadPool(ExecutorService pool)
ThreadPoolFactory
ExecutorService.shutdownNow()
on the given pool, if the pool has been created
previously by this class. Clients which use this method should handle, if necessary, any potential
InterruptedException
releaseThreadPool
in interface ThreadPoolFactory
pool
- the pool that is no longer neededpublic ExecutorService getCachedTreadPool(String name, int maxPoolSize)
ThreadPoolFactory
released
.getCachedTreadPool
in interface ThreadPoolFactory
name
- the name of the thread pool; may not be nullmaxPoolSize
- the maximum number of threads that can be spawned by this pool.public ScheduledExecutorService getScheduledThreadPool(String name)
ThreadPoolFactory
released
.getScheduledThreadPool
in interface ThreadPoolFactory
name
- the name of the thread pool; may not be nullpublic void terminateAllPools(long maxWaitTime, TimeUnit timeUnit)
ThreadPoolFactory
maxWaitTimeMillis
milliseconds, after which
calling ExecutorService.shutdownNow()
.terminateAllPools
in interface ThreadPoolFactory
maxWaitTime
- the maximum amount of time that should be given to the pools to shutdown on their own; must be
non-negativetimeUnit
- the unit of time for the maxWaitTime
parameterpublic String getId()
public String getProcessId()
public Map<String,String> getData()
public TextDecoder getDecoder()
public ExecutionContext with(BinaryStore binaryStore)
binaryStore
- the binary store that should be used, or null if the default implementation should be usedpublic ExecutionContext with(NamespaceRegistry namespaceRegistry)
value factories
and property factory
all make use of
the new namespace registry.namespaceRegistry
- the new namespace registry implementation, or null if the default implementation should be usedpublic ExecutionContext with(ThreadPoolFactory threadPoolFactory)
thread pool
factory
.threadPoolFactory
- the new thread pool factory implementation, or null if the default implementation should be usedpublic ExecutionContext with(PropertyFactory propertyFactory)
factory
.propertyFactory
- the new propertyfactory implementation, or null if the default implementation should be usedpublic ExecutionContext with(SecurityContext securityContext)
ExecutionContext
that is the same as this context, but which uses the supplied security context
.securityContext
- the new security context to use; may be nullIllegalArgumentException
- if the name
is nullpublic ExecutionContext with(Map<String,String> data)
data
- the data that is to be affiliated with the resulting context or null if the resulting context should have no
dataprotected ExecutionContext with(ReferenceFactory referenceFactory)
public ExecutionContext with(String key, String value)
key
- the key for the new data that is to be affiliated with the resulting contextvalue
- the data value to be affiliated with the supplied key in the resulting context, or null if an existing data
affiliated with the key should be removed in the resulting contextpublic ExecutionContext with(String processId)
processId
- the identifier of the processpublic ExecutionContext with(Locale locale)
locale
- a Locale
instancepublic ExecutionContext clone()
protected void initializeDefaultNamespaces(NamespaceRegistry namespaceRegistry)
namespaceRegistry
- the namespace registryCopyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.