KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > cache > SwarmCacheProvider


1 //$Id: SwarmCacheProvider.java,v 1.6 2005/02/12 07:19:08 steveebersole Exp $
2
package org.hibernate.cache;
3
4 import net.sf.swarmcache.CacheConfiguration;
5 import net.sf.swarmcache.CacheConfigurationManager;
6 import net.sf.swarmcache.CacheFactory;
7 import net.sf.swarmcache.ObjectCache;
8
9 import java.util.Properties JavaDoc;
10
11 /**
12  * Support for SwarmCache replicated cache. SwarmCache does not support
13  * locking, so strict "read-write" semantics are unsupported.
14  * @author Jason Carreira
15  */

16 public class SwarmCacheProvider implements CacheProvider {
17
18     private CacheFactory factory;
19
20     public Cache buildCache(String JavaDoc regionName, Properties JavaDoc properties) throws CacheException {
21         ObjectCache cache = factory.createCache(regionName);
22         if (cache==null) {
23             throw new CacheException("SwarmCache did not create a cache: " + regionName);
24         }
25         return new SwarmCache(cache, regionName);
26     }
27
28     public long nextTimestamp() {
29         return System.currentTimeMillis() / 100;
30     }
31
32     /**
33      * Callback to perform any necessary initialization of the underlying cache implementation
34      * during SessionFactory construction.
35      *
36      * @param properties current configuration settings.
37      */

38     public void start(Properties JavaDoc properties) throws CacheException {
39         CacheConfiguration config = CacheConfigurationManager.getConfig(properties);
40         factory = new CacheFactory(config);
41     }
42
43     /**
44      * Callback to perform any necessary cleanup of the underlying cache implementation
45      * during SessionFactory.close().
46      */

47     public void stop() {
48         if (factory != null) {
49             factory.shutdown();
50             factory = null;
51         }
52     }
53
54     public boolean isMinimalPutsEnabledByDefault() {
55         return true;
56     }
57
58 }
59
Popular Tags