org.modeshape.jcr

## Class LocalEnvironment

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

- All Implemented Interfaces:
    Environment

      public class LocalEnvironment
      extends Object
      implements Environment

  An `Environment` that can be used within a local (non-clustered) process.

  To use a custom Environment instance, simply create a `RepositoryConfiguration` as usual but then call the `RepositoryConfiguration.with(Environment)` with the Environment instance and then use the resulting RepositoryConfiguration instance.

  When a ModeShape `repository configuration` defines cache containers with configuration files on the file system or the classpath, then a `LocalEnvironment` instance can be used as-is with no other configuration or setup.

  If applications wish to programmatically configure the Infinispan caches or cache containers, then those configurations can be registered with a LocalEnvironment instance. Specifically, the `addCacheContainer(String, CacheContainer)` and `addCacheContainerIfAbsent(String, CacheContainer)` methods register a programmatically created instance of a `CacheContainer`. Alternatively, the `defineCache(String, String, Configuration)` method can be used to register a named cache with a programmatically created `Infinispan cache configuration`.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `DEFAULT_CONFIGURATION_NAME` The name for the default cache container that is used when `getCacheContainer()` is called or if null is supplied as the name in `getCacheContainer(String)`.
    `static Class<? extends TransactionManagerLookup>` | `DEFAULT_TRANSACTION_MANAGER_LOOKUP_CLASS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LocalEnvironment()`
    `LocalEnvironment(Class<? extends TransactionManagerLookup> transactionManagerLookupClass)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `CacheContainer` | `addCacheContainer(String name, CacheContainer cacheContainer)` Add the supplied `CacheContainer` under the supplied name if and only if there is not already a cache container registered at that name.
    `void` | `addCacheContainerIfAbsent(String name, CacheContainer cacheContainer)` Add the supplied `CacheContainer` under the supplied name if and only if there is not already a cache container registered at that name.
    `protected CacheContainer` | `createContainer(GlobalConfigurationBuilder globalConfigurationBuilder, ConfigurationBuilder configurationBuilder)` Create a cache container using the supplied configurations.
    `protected CacheContainer` | `createContainer(GlobalConfiguration globalConfiguration, Configuration configuration)` Deprecated. use `createContainer(GlobalConfigurationBuilder, ConfigurationBuilder)` instead
    `protected CacheContainer` | `createContainer(String configFile)`
    `protected Configuration` | `createDefaultConfiguration()` Deprecated. see `createDefaultConfigurationBuilder()`
    `protected ConfigurationBuilder` | `createDefaultConfigurationBuilder()` Create the default configuration.
    `protected GlobalConfiguration` | `createGlobalConfiguration()` Deprecated. see `createGlobalConfigurationBuilder()`
    `protected GlobalConfigurationBuilder` | `createGlobalConfigurationBuilder()` Create the global configuration.
    `Configuration` | `defineCache(String cacheName, Configuration configuration)` Define within the default cache container an Infinispan cache with the given cache name and configuration.
    `Configuration` | `defineCache(String cacheContainerName, String cacheName, Configuration configuration)` Define within the named cache container an Infinispan cache with the given cache name and configuration.
    `protected void` | `doShutdown()` Shutdown all containers and caches.
    `CacheContainer` | `getCacheContainer()` Get the default cache container.
    `CacheContainer` | `getCacheContainer(String name)` Get the cache container with the given name.
    `ClassLoader` | `getClassLoader(ClassLoader fallbackLoader, String... classpathEntries)` Get a classloader given the supplied set of logical classpath entries, which the implementation can interpret however it needs.
    `boolean` | `isShared()` Return whether this environment is shared amongst multiple repositories.
    `protected Context` | `jndiContext()`
    `void` | `setShared(boolean shared)` Set whether this environment is shared amongst multiple repositories.
    `void` | `shutdown()` Shutdown this environment, allowing it to reclaim any resources.
    `protected void` | `shutdown(CacheContainer container)`
    `protected Class<? extends TransactionManagerLookup>` | `transactionManagerLookupClass()`
    `protected TransactionManagerLookup` | `transactionManagerLookupInstance()`

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

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

- - ### Field Detail

    - #### DEFAULT_TRANSACTION_MANAGER_LOOKUP_CLASS

          public static final Class<? extends TransactionManagerLookup> DEFAULT_TRANSACTION_MANAGER_LOOKUP_CLASS

    - #### DEFAULT_CONFIGURATION_NAME

          public static final String DEFAULT_CONFIGURATION_NAME

      The name for the default cache container that is used when `getCacheContainer()` is called or if null is supplied as the name in `getCacheContainer(String)`.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### LocalEnvironment

          public LocalEnvironment()

    - #### LocalEnvironment

          public LocalEnvironment(Class<? extends TransactionManagerLookup> transactionManagerLookupClass)

  - ### Method Detail

    - #### getCacheContainer

          public CacheContainer getCacheContainer()
                                           throws IOException,
                                                  NamingException

      Get the default cache container.
      Returns:
        the default cache container; never null
      Throws:
        `IOException`
        `NamingException`

    - #### getCacheContainer

          public CacheContainer getCacheContainer(String name)
                                           throws IOException,
                                                  NamingException

      Description copied from interface: `Environment`
      Get the cache container with the given name. Note that the name might be a logical name or it might refer to the location of an Infinispan configuration; the exact semantics is dependent upon the implementation.
      Specified by:
        `getCacheContainer` in interface `Environment`
      Parameters:
        `name` - the name of the cache container; may be null
      Returns:
        the cache container; never null
      Throws:
        `IOException` - if there is an error accessing any resources required to start the container
        `NamingException` - if there is an error accessing JNDI (if that is used in the implementation)

    - #### shutdown

          public void shutdown()

      Shutdown this environment, allowing it to reclaim any resources.

      This method does nothing if the environment has been marked as `shared`.

      Specified by:
        `shutdown` in interface `Environment`

    - #### doShutdown

          protected void doShutdown()

      Shutdown all containers and caches.

    - #### getClassLoader

          public ClassLoader getClassLoader(ClassLoader fallbackLoader,
                                   String... classpathEntries)

      Description copied from interface: `Environment`
      Get a classloader given the supplied set of logical classpath entries, which the implementation can interpret however it needs.
      Specified by:
        `getClassLoader` in interface `Environment`
      Parameters:
        `fallbackLoader` - the classloader that should be used is the fallback class loader
        `classpathEntries` - the logical classpath entries
      Returns:
        the classloader

    - #### shutdown

          protected void shutdown(CacheContainer container)

    - #### transactionManagerLookupClass

          protected Class<? extends TransactionManagerLookup> transactionManagerLookupClass()

    - #### transactionManagerLookupInstance

          protected TransactionManagerLookup transactionManagerLookupInstance()

    - #### createContainer

          protected CacheContainer createContainer(String configFile)
                                            throws IOException,
                                                   NamingException

      Throws:
        `IOException`
        `NamingException`

    - #### createDefaultConfigurationBuilder

          protected ConfigurationBuilder createDefaultConfigurationBuilder()

      Create the default configuration.
      Returns:
        the default cache configuration.

    - #### createGlobalConfigurationBuilder

          protected GlobalConfigurationBuilder createGlobalConfigurationBuilder()

      Create the global configuration.
      Returns:
        the global configuration.

    - #### createContainer

          protected CacheContainer createContainer(GlobalConfigurationBuilder globalConfigurationBuilder,
                                       ConfigurationBuilder configurationBuilder)

      Create a cache container using the supplied configurations.
      Parameters:
        `globalConfigurationBuilder` - the global configuration builder
        `configurationBuilder` - the default cache configuration builder
      Returns:
        the cache container

    - #### createDefaultConfiguration

          @Deprecated
          protected Configuration createDefaultConfiguration()

      Deprecated. see `createDefaultConfigurationBuilder()`
      Create the default configuration.
      Returns:
        the default cache configuration.

    - #### createGlobalConfiguration

          @Deprecated
          protected GlobalConfiguration createGlobalConfiguration()

      Deprecated. see `createGlobalConfigurationBuilder()`
      Create the global configuration.
      Returns:
        the global configuration.

    - #### createContainer

          @Deprecated
          protected CacheContainer createContainer(GlobalConfiguration globalConfiguration,
                                                  Configuration configuration)

      Deprecated. use `createContainer(GlobalConfigurationBuilder, ConfigurationBuilder)` instead
      Create a cache container using the supplied configurations.
      Parameters:
        `globalConfiguration` - the global configuration
        `configuration` - the default cache configuration
      Returns:
        the cache container

    - #### jndiContext

          protected Context jndiContext()
                                 throws NamingException

      Throws:
        `NamingException`

    - #### addCacheContainerIfAbsent

          public void addCacheContainerIfAbsent(String name,
                                       CacheContainer cacheContainer)

      Add the supplied `CacheContainer` under the supplied name if and only if there is not already a cache container registered at that name.
      Parameters:
        `name` - the cache container name; may be null if the `default configuration name` should be used
        `cacheContainer` - the cache container; may not be null

    - #### addCacheContainer

          public CacheContainer addCacheContainer(String name,
                                         CacheContainer cacheContainer)

      Add the supplied `CacheContainer` under the supplied name if and only if there is not already a cache container registered at that name.
      Parameters:
        `name` - the cache container name; may be null if the `default configuration name` should be used
        `cacheContainer` - the cache container; may not be null
      Returns:
        the cache container that was previously registered in this environment by the supplied name, or null if there was no such previously-registered cache container

    - #### defineCache

          public Configuration defineCache(String cacheName,
                                  Configuration configuration)

      Define within the default cache container an Infinispan cache with the given cache name and configuration. Note that the cache container is created if required, but if it exists it must implement the `EmbeddedCacheManager` interface for this method to succeed.
      Parameters:
        `cacheName` - the name of the cache being defined; may not be null
        `configuration` - the cache configuration; may not be null
      Returns:
        the clone of the supplied configuration that is used by the cache container; never null

    - #### defineCache

          public Configuration defineCache(String cacheContainerName,
                                  String cacheName,
                                  Configuration configuration)

      Define within the named cache container an Infinispan cache with the given cache name and configuration. Note that the cache container is created if required, but if it exists it must implement the `EmbeddedCacheManager` interface for this method to succeed.
      Parameters:
        `cacheContainerName` - the name of the cache container; if null, the `default container name` is used
        `cacheName` - the name of the cache being defined; may not be null
        `configuration` - the cache configuration; may not be null
      Returns:
        the clone of the supplied configuration that is used by the cache container; never null

    - #### setShared

          public void setShared(boolean shared)

      Set whether this environment is shared amongst multiple repositories. Shared environments are not shutdown automatically, and the application is expected to shutdown all containers and caches. By default, environments are not shared unless this method is explicitly called with a parameter value of `true`.
      Parameters:
        `shared` - true if this environment is shared, or false otherwise
      See Also:
        `isShared()`

    - #### isShared

          public boolean isShared()

      Return whether this environment is shared amongst multiple repositories.
      Returns:
        true if this environment is shared, or false otherwise
      See Also:
        `setShared(boolean)`

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