/** * Subclass can override this method to create the specific cache manager. * <p> * @param prop the configuration object. * @return The cache hub configured with this configuration. * * @throws CacheException if the configuration cannot be loaded */ private CompositeCacheManager createCacheManager( Properties prop ) throws CacheException { CompositeCacheManager hub = CompositeCacheManager.getUnconfiguredInstance(); hub.configure( prop ); return hub; }
/** * shuts the cache down. */ @Override public void destroy() { super.destroy(); log.info( "Shutting down remote cache " ); try { CompositeCacheManager.getInstance().shutDown(); } catch (CacheException e) { log.error("Could not retrieve cache manager instance", e); } } }
/** * Gets the cache attribute of the CacheHub object * <p> * @param cattr * @return CompositeCache */ public <K, V> CompositeCache<K, V> getCache( ICompositeCacheAttributes cattr ) { return getCache( cattr, this.defaultElementAttr ); }
CompositeCacheManager cacheManager = new CompositeCacheManager(); cacheManager.setCacheManagers(cacheManagers); cacheManager.setFallbackToNoOpCache(false);
/** * Make sure we have a cache manager. This should have happened in the init method. * * @throws CacheException if the configuration cannot be loaded */ protected synchronized void ensureCacheManager() throws CacheException { if ( cacheMgr == null || !cacheMgr.isInitialized() ) { cacheMgr = CompositeCacheManager.getInstance(); } }
/** * Gets the cache attribute of the CacheHub object * <p> * @param cacheName * @return CompositeCache -- the cache region controller */ @Override public <K, V> CompositeCache<K, V> getCache( String cacheName ) { return getCache( cacheName, getDefaultCacheAttributes() ); }
/** * Verify that we can parse the spool chunk size */ public void testParseSpoolChunkSize_Normal() { // SETUP String regionName = "MyRegion"; int chunkSize = 5; Properties props = new Properties(); props.put( "jcs.default", "" ); props.put( "jcs.default.cacheattributes.SpoolChunkSize", String.valueOf( chunkSize ) ); CompositeCacheManager manager = CompositeCacheManager.getUnconfiguredInstance(); // DO WORK manager.configure( props ); // VERIFY CompositeCache<String, String> cache = manager.getCache( regionName ); assertEquals( "Wrong chunkSize", cache.getCacheAttributes().getSpoolChunkSize(), chunkSize ); } }
/** * Initializes the cache manager using the props file for the given name. * <p> * @param propsFilename * @return CompositeCacheManager configured from the give propsFileName * @throws CacheException if the configuration cannot be loaded */ public static synchronized CompositeCacheManager getInstance( String propsFilename ) throws CacheException { if ( instance == null ) { if ( log.isInfoEnabled() ) { log.info( "Instance is null, creating with config [" + propsFilename + "]" ); } instance = createInstance(); } if (!instance.isInitialized()) { instance.initialize(); } if (!instance.isConfigured()) { instance.configure( propsFilename ); } instance.incrementClients(); return instance; }
AuxiliaryCache<K, V> auxCache = (AuxiliaryCache<K, V>)compositeCacheManager.getAuxiliaryCache(auxName, regName); AuxiliaryCacheFactory auxFac = compositeCacheManager.registryFacGet( auxName ); if ( auxFac == null ) auxFac.initialize(); compositeCacheManager.registryFacPut( auxFac ); AuxiliaryCacheAttributes auxAttr = compositeCacheManager.registryAttrGet( auxName ); String attrName = AUXILIARY_PREFIX + auxName + ATTRIBUTE_PREFIX; if ( auxAttr == null ) compositeCacheManager.registryAttrPut( auxAttr ); compositeCacheManager.addAuxiliaryCache(auxName, regName, auxCache);
/** * Helper method which checks to make sure the cacheMgr class field is set, and if not requests * an instance from CacheManagerFactory. * * @throws CacheException if the configuration cannot be loaded */ private static CompositeCacheManager getCacheManager() throws CacheException { synchronized ( JCS.class ) { if ( cacheMgr == null || !cacheMgr.isInitialized()) { if ( configProps != null ) { cacheMgr = CompositeCacheManager.getUnconfiguredInstance(); cacheMgr.configure( configProps ); } else if ( configFilename != null ) { cacheMgr = CompositeCacheManager.getUnconfiguredInstance(); cacheMgr.configure( configFilename ); } else { cacheMgr = CompositeCacheManager.getInstance(); } } return cacheMgr; } }
/** * Configure with default properties file * @throws CacheException if the configuration cannot be loaded */ public void configure() throws CacheException { configure( CacheConstants.DEFAULT_CONFIG ); }
cache.get( "testKey" ); CompositeCacheManager mgr = CompositeCacheManager.getInstance(); String statsString = mgr.getStats(); assertTrue( "Should have the 4 in here.", statsString.indexOf("4") != -1 ); ICacheStats[] stats = mgr.getStatistics(); int statsLen = stats.length;
/** * Shut down the cache manager and set the instance to null */ public static void shutdown() { synchronized ( JCS.class ) { if ( cacheMgr != null && cacheMgr.isInitialized()) { cacheMgr.shutDown(); } cacheMgr = null; } }
/** * Verify that calling release, when there are active clients, the caches are correctly disposed or not. */ public void testRelease() { // See JCS-184 // create the manager CompositeCacheManager manager = CompositeCacheManager.getInstance(); // add a simple cache CompositeCacheAttributes cacheAttributes = new CompositeCacheAttributes(); CompositeCache<String, String> cache = new CompositeCache<String, String>(cacheAttributes, /* attr */ null); manager.addCache("simple_cache", cache); // add a client to the cache CompositeCacheManager.getUnconfiguredInstance(); // won't release as there are still clients. Only disposed when release() is called by // the last client manager.release(); assertEquals("The cache was disposed during release!", CacheStatus.ALIVE, cache.getStatus()); manager.release(); assertEquals("The cache was NOT disposed during release!", CacheStatus.DISPOSED, cache.getStatus()); }
/** * Gets the CacheHub instance. For backward compatibility, if this creates the instance it will * attempt to configure it with the default configuration. If you want to configure from your * own source, use {@link #getUnconfiguredInstance}and then call {@link #configure} * <p> * @return CompositeCacheManager * @throws CacheException if the configuration cannot be loaded */ public static synchronized CompositeCacheManager getInstance() throws CacheException { return getInstance( CacheConstants.DEFAULT_CONFIG ); }
public void shutDown() { manager.shutDown(); }
stats = CompositeCacheManager.getInstance().getStats();
/** * Get a CacheHub instance which is not configured. If an instance already exists, it will be * returned. *<p> * @return CompositeCacheManager */ public static synchronized CompositeCacheManager getUnconfiguredInstance() { if ( instance == null ) { if ( log.isInfoEnabled() ) { log.info( "Instance is null, returning unconfigured instance" ); } instance = createInstance(); } if (!instance.isInitialized()) { instance.initialize(); } instance.incrementClients(); return instance; }
/** * Gets the cache attribute of the CacheHub object * <p> * @param cattr * @return CompositeCache */ public <K, V> CompositeCache<K, V> getCache( ICompositeCacheAttributes cattr ) { return getCache( cattr, getDefaultElementAttributes() ); }
/** * Get a CacheHub instance which is not configured. If an instance already exists, it will be * returned. *<p> * @return CompositeCacheManager */ public static synchronized CompositeCacheManager getUnconfiguredInstance() { if ( instance == null ) { if ( log.isInfoEnabled() ) { log.info( "Instance is null, returning unconfigured instance" ); } instance = createInstance(); } if (!instance.isInitialized()) { instance.initialize(); } instance.clients.incrementAndGet(); return instance; }