View Javadoc

1   /***
2    *  Copyright 2003-2010 Terracotta, Inc.
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  
17  package net.sf.ehcache.terracotta;
18  
19  import net.sf.ehcache.bootstrap.BootstrapCacheLoaderFactory;
20  import net.sf.ehcache.util.PropertyUtil;
21  
22  import java.util.Properties;
23  
24  /***
25   * @author Alex Snaps
26   */
27  public class TerracottaBootstrapCacheLoaderFactory extends BootstrapCacheLoaderFactory<TerracottaBootstrapCacheLoader> {
28  
29      @Override
30      public TerracottaBootstrapCacheLoader createBootstrapCacheLoader(final Properties properties) {
31  
32          final boolean asynchronous = extractBootstrapAsynchronously(properties);
33          TerracottaBootstrapCacheLoader cacheLoader;
34  
35          final String directory = PropertyUtil.extractAndLogProperty("directory", properties);
36          if (extractBoolean(properties, "doKeySnapshot", true)) {
37              cacheLoader = new TerracottaBootstrapCacheLoader(asynchronous,
38                  directory,
39                  extractLong(properties, "interval", TerracottaBootstrapCacheLoader.DEFAULT_INTERVAL),
40                  extractBoolean(properties, "useDedicatedThread", TerracottaBootstrapCacheLoader.DEFAULT_DEDICATED_THREAD)
41              );
42          } else {
43              cacheLoader = new TerracottaBootstrapCacheLoader(asynchronous, directory, false);
44          }
45          cacheLoader.setImmediateShutdown(extractBoolean(properties, "immediateShutdown", true));
46          cacheLoader.setSnapshotOnDispose(extractBoolean(properties, "doKeySnapshotOnDispose", false));
47          return cacheLoader;
48  
49      }
50  
51  }