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 org.infinispan.transaction.lookup.TransactionManagerLookup>` | `DEFAULT_TRANSACTION_MANAGER_LOOKUP_CLASS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LocalEnvironment()`
    `LocalEnvironment(Class<? extends org.infinispan.transaction.lookup.TransactionManagerLookup> transactionManagerLookupClass)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `org.infinispan.manager.CacheContainer` | `addCacheContainer(String name, org.infinispan.manager.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, org.infinispan.manager.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 org.infinispan.manager.CacheContainer` | `createContainer(org.infinispan.configuration.global.GlobalConfigurationBuilder globalConfigurationBuilder, org.infinispan.configuration.cache.ConfigurationBuilder configurationBuilder)` Create a cache container using the supplied configurations.
    `protected org.infinispan.manager.CacheContainer` | `createContainer(org.infinispan.configuration.global.GlobalConfiguration globalConfiguration, org.infinispan.configuration.cache.Configuration configuration)` Deprecated. use `createContainer(GlobalConfigurationBuilder, ConfigurationBuilder)` instead
    `protected org.infinispan.manager.CacheContainer` | `createContainer(String configFile)`
    `protected org.infinispan.configuration.cache.Configuration` | `createDefaultConfiguration()` Deprecated. see `createDefaultConfigurationBuilder()`
    `protected org.infinispan.configuration.cache.ConfigurationBuilder` | `createDefaultConfigurationBuilder()` Create the default configuration.
    `protected org.infinispan.configuration.global.GlobalConfiguration` | `createGlobalConfiguration()` Deprecated. see `createGlobalConfigurationBuilder()`
    `protected org.infinispan.configuration.global.GlobalConfigurationBuilder` | `createGlobalConfigurationBuilder()` Create the global configuration.
    `org.infinispan.configuration.cache.Configuration` | `defineCache(String cacheName, org.infinispan.configuration.cache.Configuration configuration)` Define within the default cache container an Infinispan cache with the given cache name and configuration.
    `org.infinispan.configuration.cache.Configuration` | `defineCache(String cacheContainerName, String cacheName, org.infinispan.configuration.cache.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.
    `org.infinispan.manager.CacheContainer` | `getCacheContainer()` Get the default cache container.
    `org.infinispan.manager.CacheContainer` | `getCacheContainer(String name)` Get the cache container with the given name.
    `org.jgroups.Channel` | `getChannel(String name)` Get the JGroups channel with the given logical 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(org.infinispan.manager.CacheContainer container)`
    `protected Class<? extends org.infinispan.transaction.lookup.TransactionManagerLookup>` | `transactionManagerLookupClass()`
    `protected org.infinispan.transaction.lookup.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 org.infinispan.transaction.lookup.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 org.infinispan.transaction.lookup.TransactionManagerLookup> transactionManagerLookupClass)

  - ### Method Detail

    - #### getCacheContainer

          public org.infinispan.manager.CacheContainer getCacheContainer()
                                                                  throws IOException,
                                                                         NamingException

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

    - #### getCacheContainer

          public org.infinispan.manager.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)

    - #### getChannel

          public org.jgroups.Channel getChannel(String name)

      Description copied from interface: `Environment`
      Get the JGroups channel with the given logical name.
      Specified by:
        `getChannel` in interface `Environment`
      Parameters:
        `name` - the name of the channel; may not be null
      Returns:
        the channel, or null if there is no such channel and the environment does not support clustering

    - #### 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(org.infinispan.manager.CacheContainer container)

    - #### transactionManagerLookupClass

          protected Class<? extends org.infinispan.transaction.lookup.TransactionManagerLookup> transactionManagerLookupClass()

    - #### transactionManagerLookupInstance

          protected org.infinispan.transaction.lookup.TransactionManagerLookup transactionManagerLookupInstance()

    - #### createContainer

          protected org.infinispan.manager.CacheContainer createContainer(String configFile)
                                                                   throws IOException,
                                                                          NamingException

      Throws:
        `IOException`
        `NamingException`

    - #### createDefaultConfigurationBuilder

          protected org.infinispan.configuration.cache.ConfigurationBuilder createDefaultConfigurationBuilder()

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

    - #### createGlobalConfigurationBuilder

          protected org.infinispan.configuration.global.GlobalConfigurationBuilder createGlobalConfigurationBuilder()

      Create the global configuration.
      Returns:
        the global configuration.

    - #### createContainer

          protected org.infinispan.manager.CacheContainer createContainer(org.infinispan.configuration.global.GlobalConfigurationBuilder globalConfigurationBuilder,
                                                              org.infinispan.configuration.cache.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 org.infinispan.configuration.cache.Configuration createDefaultConfiguration()

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

    - #### createGlobalConfiguration

          @Deprecated
          protected org.infinispan.configuration.global.GlobalConfiguration createGlobalConfiguration()

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

    - #### createContainer

          @Deprecated
          protected org.infinispan.manager.CacheContainer createContainer(org.infinispan.configuration.global.GlobalConfiguration globalConfiguration,
                                                                         org.infinispan.configuration.cache.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,
                                       org.infinispan.manager.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 org.infinispan.manager.CacheContainer addCacheContainer(String name,
                                                                org.infinispan.manager.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 org.infinispan.configuration.cache.Configuration defineCache(String cacheName,
                                                                     org.infinispan.configuration.cache.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 org.infinispan.configuration.cache.Configuration defineCache(String cacheContainerName,
                                                                     String cacheName,
                                                                     org.infinispan.configuration.cache.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.