View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.spi.config.cache.infinispan;
17  
18  import org.infinispan.configuration.cache.CacheMode;
19  import org.infinispan.configuration.cache.Configuration;
20  import org.infinispan.configuration.cache.ConfigurationBuilder;
21  import org.infinispan.configuration.global.GlobalConfiguration;
22  import org.infinispan.configuration.global.GlobalConfigurationBuilder;
23  import org.infinispan.manager.DefaultCacheManager;
24  import org.infinispan.manager.EmbeddedCacheManager;
25  
26  /**
27   * This service looks up the jndi name in the cache.properties file and fetches
28   * the CacheManager using this name from the jndi context.
29   */
30  public final class InternalCacheManagerLookupService
31  {
32    // ********************************* Fields *********************************
33  
34    // --- constants ------------------------------------------------------------
35  
36    /**
37     * The default cluster name of the cache that shall be used.
38     * <p>
39     * The value of this constant is {@value}.
40     * </p>
41     */
42    public static final String CLUSTER_NAME = "de.smartics.properties";
43  
44    // --- members --------------------------------------------------------------
45  
46    // ****************************** Initializer *******************************
47  
48    // ****************************** Constructors ******************************
49  
50    /**
51     * Default.
52     */
53    private InternalCacheManagerLookupService()
54    {
55  
56    }
57  
58    // ****************************** Inner Classes *****************************
59  
60    // ********************************* Methods ********************************
61  
62    // --- init -----------------------------------------------------------------
63  
64    // --- get&set --------------------------------------------------------------
65  
66    // --- business -------------------------------------------------------------
67  
68    /**
69     * Creates the embedded cache manager.
70     *
71     * @return the embedded cache manager.
72     */
73    public static EmbeddedCacheManager createManager()
74    {
75      final GlobalConfigurationBuilder globalBuilder =
76          new GlobalConfigurationBuilder();
77      globalBuilder.nonClusteredDefault().globalJmxStatistics()
78          .allowDuplicateDomains(true).transport()
79          .clusterName(CLUSTER_NAME);
80      final GlobalConfiguration globalCfg = globalBuilder.build();
81  
82      final ConfigurationBuilder builder = new ConfigurationBuilder();
83      builder.clustering().cacheMode(CacheMode.LOCAL).indexing().disable();
84      final Configuration cfg = builder.build();
85      final EmbeddedCacheManager manager =
86          new DefaultCacheManager(globalCfg, cfg);
87  
88      return manager;
89    }
90  
91    // --- object basics
92    // --------------------------------------------------------
93  
94  }