org.modeshape.jcr

## Class ExecutionContext

- java.lang.Object
- - org.modeshape.jcr.ExecutionContext

- All Implemented Interfaces:
    Cloneable, ThreadPoolFactory, NamespaceRegistry.Holder

      @Immutable
      public final class ExecutionContext
      extends Object
      implements ThreadPoolFactory, Cloneable, NamespaceRegistry.Holder

  An ExecutionContext is a representation of the environment or context in which a component or operation is operating. Some components require this context to be passed into individual methods, allowing the context to vary with each method invocation. Other components require the context to be provided before it's used, and will use that context for all its operations (until it is given a different one).

  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`.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `ExecutionContext.ContextFactories`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static ExecutionContext` | `DEFAULT_CONTEXT`

  - ### Constructor Summary

    Constructors
    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)` Create an instance of the execution context by supplying all parameters.

  - ### Method Summary

    Methods
    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)` 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(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`.

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_CONTEXT

          public static final ExecutionContext DEFAULT_CONTEXT

  - ### Constructor Detail

    - #### ExecutionContext

          public 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`.

    - #### ExecutionContext

          protected ExecutionContext(ExecutionContext context)

    - #### ExecutionContext

          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)

      Create an instance of the execution context by supplying all parameters.
      Parameters:
        `securityContext` - the security context, or null if there is no associated authenticated user
        `namespaceRegistry` - the namespace registry implementation, or null if a thread-safe version of `SimpleNamespaceRegistry` instance should be used
        `propertyFactory` - the `PropertyFactory` implementation, or null if a `BasicPropertyFactory` instance should be used
        `threadPoolFactory` - the `ThreadPoolFactory` implementation, or null if a `ThreadPools` instance should be used
        `binaryStore` - the `BinaryStore` implementation, or null if a default `TransientBinaryStore` should be used
        `data` - the custom data for this context, or null if there is no such data
        `processId` - the unique identifier of the process in which this context exists, or null if it should be generated
        `decoder` - 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 used
        `binaryFactory` - the binary factory that should be used; if null, a default implementation will be used
        `booleanFactory` - the boolean factory that should be used; if null, a default implementation will be used
        `dateFactory` - the date factory that should be used; if null, a default implementation will be used
        `decimalFactory` - the decimal factory that should be used; if null, a default implementation will be used
        `doubleFactory` - the double factory that should be used; if null, a default implementation will be used
        `longFactory` - the long factory that should be used; if null, a default implementation will be used
        `nameFactory` - the name factory that should be used; if null, a default implementation will be used
        `pathFactory` - the path factory that should be used; if null, a default implementation will be used
        `referenceFactory` - the strong reference factory that should be used; if null, a default implementation will be used
        `weakReferenceFactory` - the weak reference factory that should be used; if null, a default implementation will be used
        `simpleReferenceFactory` - the simple reference factory that should be used; if null, a default implementation will be used
        `uriFactory` - the URI factory that should be used; if null, a default implementation will be used
        `objectFactory` - the object factory that should be used; if null, a default implementation will be used

  - ### Method Detail

    - #### getThreadPoolFactory

          protected ThreadPoolFactory getThreadPoolFactory()

    - #### getLogger

          public Logger getLogger(Class<?> clazz)

      Return a logger associated with this context. This logger records only those activities within the context and provide a way to capture the context-specific activities. All log messages are also sent to the system logger, so classes that log via this mechanism should not also `obtain a system logger`.
      Parameters:
        `clazz` - the class that is doing the logging
      Returns:
        the logger, named after `clazz`; never null
      See Also:
        `getLogger(String)`

    - #### getLogger

          public Logger getLogger(String name)

      Return a logger associated with this context. This logger records only those activities within the context and provide a way to capture the context-specific activities. All log messages are also sent to the system logger, so classes that log via this mechanism should not also `obtain a system logger`.
      Parameters:
        `name` - the name for the logger
      Returns:
        the logger, named after `clazz`; never null
      See Also:
        `getLogger(Class)`

    - #### getSecurityContext

          public SecurityContext getSecurityContext()

      Get the `security context` for this context.
      Returns:
        the security context; never `null`

    - #### getNamespaceRegistry

          public NamespaceRegistry getNamespaceRegistry()

      Get the (mutable) namespace registry for this context.
      Specified by:
        `getNamespaceRegistry` in interface `NamespaceRegistry.Holder`
      Returns:
        the namespace registry; never `null`

    - #### getPropertyFactory

          public final PropertyFactory getPropertyFactory()

      Get the factory for creating `Property` objects.
      Returns:
        the property factory; never `null`

    - #### getValueFactories

          public ValueFactories getValueFactories()

      Get the factories that should be used to create values for `properties`.
      Returns:
        the property value factory; never null

    - #### getBinaryStore

          public BinaryStore getBinaryStore()

      Get the binary store that should be used to store binary values. This store is used by the `BinaryFactory` in the `getValueFactories()`.
      Returns:
        the binary store; never null

    - #### getThreadPool

          public ExecutorService getThreadPool(String name)

      Description copied from interface: `ThreadPoolFactory`
      Obtain a thread pool with the supplied name, or create and return one if no thread pool exists with that name. When finished with the thread pool, it should be `released`.
      Specified by:
        `getThreadPool` in interface `ThreadPoolFactory`
      Parameters:
        `name` - the name of the thread pool; may not be null
      Returns:
        the thread pool executor; never null

    - #### releaseThreadPool

          public void releaseThreadPool(ExecutorService pool)

      Description copied from interface: `ThreadPoolFactory`
      Performs a `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`
      Specified by:
        `releaseThreadPool` in interface `ThreadPoolFactory`
      Parameters:
        `pool` - the pool that is no longer needed

    - #### getCachedTreadPool

          public ExecutorService getCachedTreadPool(String name)

      Description copied from interface: `ThreadPoolFactory`
      Signal that the supplied thread pool is no longer needed. Obtain a cached thread pool with the supplied name, or create and return one if no thread pool exists with that name. When finished with the thread pool, it should be `released`.
      Specified by:
        `getCachedTreadPool` in interface `ThreadPoolFactory`
      Parameters:
        `name` - the name of the thread pool; may not be null
      Returns:
        the thread pool executor; never null

    - #### getScheduledThreadPool

          public ScheduledExecutorService getScheduledThreadPool(String name)

      Description copied from interface: `ThreadPoolFactory`
      Obtain a scheduled thread pool with the supplied name, or create and return one if no thread pool exists with that name. When finished with the thread pool, it should be `released`.
      Specified by:
        `getScheduledThreadPool` in interface `ThreadPoolFactory`
      Parameters:
        `name` - the name of the thread pool; may not be null
      Returns:
        the thread pool executor; never null

    - #### terminateAllPools

          public void terminateAllPools(long maxWaitTime,
                               TimeUnit timeUnit)

      Description copied from interface: `ThreadPoolFactory`
      Terminates all the existing thread pool, by waiting for them maximum `maxWaitTimeMillis` milliseconds, after which calling `ExecutorService.shutdownNow()`.
      Specified by:
        `terminateAllPools` in interface `ThreadPoolFactory`
      Parameters:
        `maxWaitTime` - the maximum amount of time that should be given to the pools to shutdown on their own; must be non-negative
        `timeUnit` - the unit of time for the `maxWaitTime` parameter

    - #### getId

          public String getId()

      Get the unique identifier for this context. Each context will always have a unique identifier.
      Returns:
        the unique identifier string; never null and never empty

    - #### getProcessId

          public String getProcessId()

      Get the identifier for the process in which this context exists. Multiple contexts running in the same "process" will all have the same identifier.
      Returns:
        the identifier for the process; never null and never empty

    - #### getData

          public Map<String,String> getData()

      Get the immutable map of custom data that is affiliated with this context.
      Returns:
        the custom data; never null but possibly empty

    - #### getDecoder

          public TextDecoder getDecoder()

      Get the text decoder for this context.
      Returns:
        the decoder; never null

    - #### with

          public ExecutionContext with(BinaryStore binaryStore)

      Create a new execution context that mirrors this context but that uses the supplied binary store.
      Parameters:
        `binaryStore` - the binary store that should be used, or null if the default implementation should be used
      Returns:
        the execution context that is identical with this execution context, but which uses the supplied binary store; never null

    - #### with

          public ExecutionContext with(NamespaceRegistry namespaceRegistry)

      Create a new execution context that mirrors this context but that uses the supplied namespace registry. The resulting context's `value factories` and `property factory` all make use of the new namespace registry.
      Parameters:
        `namespaceRegistry` - the new namespace registry implementation, or null if the default implementation should be used
      Returns:
        the execution context that is identical with this execution context, but which uses the supplied registry; never null

    - #### with

          public ExecutionContext with(ThreadPoolFactory threadPoolFactory)

      Create a new execution context that mirrors this context but that uses the supplied `thread pool factory`.
      Parameters:
        `threadPoolFactory` - the new thread pool factory implementation, or null if the default implementation should be used
      Returns:
        the execution context that is identical with this execution context, but which uses the supplied thread pool factory implementation; never null

    - #### with

          public ExecutionContext with(PropertyFactory propertyFactory)

      Create a new execution context that mirrors this context but that uses the supplied `factory`.
      Parameters:
        `propertyFactory` - the new propertyfactory implementation, or null if the default implementation should be used
      Returns:
        the execution context that is identical with this execution context, but which uses the supplied property factory implementation; never null

    - #### with

          public ExecutionContext with(SecurityContext securityContext)

      Create an `ExecutionContext` that is the same as this context, but which uses the supplied `security context`.
      Parameters:
        `securityContext` - the new security context to use; may be null
      Returns:
        the execution context that is identical with this execution context, but with a different security context; never null
      Throws:
        `IllegalArgumentException` - if the `name` is null

    - #### with

          public ExecutionContext with(Map<String,String> data)

      Create a new execution context that mirrors this context but that contains the supplied data. Note that the supplied map is always copied to ensure that it is immutable.
      Parameters:
        `data` - the data that is to be affiliated with the resulting context or null if the resulting context should have no data
      Returns:
        the execution context that is identical with this execution context, but which uses the supplied data; never null
      Since:
        2.0

    - #### with

          protected ExecutionContext with(ReferenceFactory referenceFactory)

    - #### with

          public 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.
      Parameters:
        `key` - the key for the new data that is to be affiliated with the resulting context
        `value` - 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 context
      Returns:
        the execution context that is identical with this execution context, but which uses the supplied data; never null
      Since:
        2.0

    - #### with

          public ExecutionContext with(String processId)

      Create a new execution context that mirrors this context but that contains the supplied process identifier.
      Parameters:
        `processId` - the identifier of the process
      Returns:
        the execution context that is identical with this execution context, but which uses the supplied process identifier; never null
      Since:
        2.1

    - #### clone

          public ExecutionContext clone()

      Overrides:
        `clone` in class `Object`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### initializeDefaultNamespaces

          protected void initializeDefaultNamespaces(NamespaceRegistry namespaceRegistry)

      Method that initializes the default namespaces for namespace registries.
      Parameters:
        `namespaceRegistry` - the namespace registry

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.