/** * 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; }
@Override public void initialise(final Properties properties) { String configFile = properties.getProperty(CacheProperties.CACHE_CONFIG_FILE); manager = CompositeCacheManager.getUnconfiguredInstance(); if (null != configFile) { try { Properties cacheProperties = readProperties(configFile); manager.configure(cacheProperties); return; } catch (final IOException e) { throw new IllegalArgumentException("Cannot create cache using config file " + configFile, e); } } LOGGER.debug("No config file configured. Using default."); manager.configure(); }
/** * Subclass can override this method to create the specific cache manager. * <p> * @param prop The name of the configuration file. * @return The cache hub configured with this configuration file. * * @throws CacheException if the configuration cannot be loaded */ private CompositeCacheManager createCacheManager( String prop ) throws CacheException { CompositeCacheManager hub = CompositeCacheManager.getUnconfiguredInstance(); if ( prop == null ) { hub.configure( "/remote.cache.ccf" ); } else { hub.configure( prop ); } return hub; }
/** * 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; } }
/** * 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; } }
CompositeCacheManager manager = CompositeCacheManager.getUnconfiguredInstance(); CompositeCacheConfigurator configurator = new CompositeCacheConfigurator();
CompositeCacheManager manager = CompositeCacheManager.getUnconfiguredInstance();
/** * 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 ); } }
/** * 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 ); } }
/** * Verify that the system properties are not used is specified. * * @throws Exception * */ public void testSystemPropertyUsage_inactive() throws Exception { System.setProperty( JCS_DEFAULT_CACHEATTRIBUTES_MAX_OBJECTS, String.valueOf(testValue) ); manager = CompositeCacheManager.getUnconfiguredInstance(); Properties props = PropertyLoader.loadProperties( "TestSystemPropertyUsage.ccf" ); manager.configure( props, false ); CacheAccess<String, String> jcs = JCS.getInstance( "someCacheNotInFile" ); assertEquals( "System property value should not be reflected", Integer.parseInt( props.getProperty( JCS_DEFAULT_CACHEATTRIBUTES_MAX_OBJECTS ) ), jcs.getCacheAttributes().getMaxObjects()); } }
/** * Verify that the system properties are not used is specified. * * @throws Exception * */ public void testSystemPropertyUsage_inactive() throws Exception { System.setProperty( JCS_DEFAULT_CACHEATTRIBUTES_MAX_OBJECTS, String.valueOf(testValue) ); manager = CompositeCacheManager.getUnconfiguredInstance(); Properties props = PropertyLoader.loadProperties( "TestSystemPropertyUsage.ccf" ); manager.configure( props, false ); CacheAccess<String, String> jcs = JCS.getInstance( "someCacheNotInFile" ); assertEquals( "System property value should not be reflected", Integer.parseInt( props.getProperty( JCS_DEFAULT_CACHEATTRIBUTES_MAX_OBJECTS ) ), jcs.getCacheAttributes().getMaxObjects()); } }
/** * Verify that we use a system property for a ${FOO} string in a value. We * define a propety in the cache.ccf file, but we do not have it as a system * property. The default value should be used, if one exists. * * @throws Exception * */ public void test2SystemPropertyMissingInValueDelimeter() throws Exception { System.getProperties().setProperty( "MY_SYSTEM_PROPERTY_DISK_DIR", "system_set" ); CompositeCacheManager mgr = CompositeCacheManager.getUnconfiguredInstance(); mgr.configure( "/TestSystemProperties.ccf" ); CacheAccess<String, String> cache = JCS.getInstance( "missing" ); // TODO check against the actual default def assertEquals( "We should have used the default property for the memory size", 100, cache.getCacheAttributes() .getMaxObjects() ); System.clearProperty("MY_SYSTEM_PROPERTY_DISK_DIR"); }
/** * Verify that we use a system property for a ${FOO} string in a value. We * define a propety in the cache.ccf file, but we do not have it as a system * property. The default value should be used, if one exists. * * @throws Exception * */ public void test2SystemPropertyMissingInValueDelimeter() throws Exception { System.getProperties().setProperty( "MY_SYSTEM_PROPERTY_DISK_DIR", "system_set" ); CompositeCacheManager mgr = CompositeCacheManager.getUnconfiguredInstance(); mgr.configure( "/TestSystemProperties.ccf" ); CacheAccess<String, String> cache = JCS.getInstance( "missing" ); // TODO check against the actual default def assertEquals( "We should have used the default property for the memory size", 100, cache.getCacheAttributes() .getMaxObjects() ); System.clearProperty("MY_SYSTEM_PROPERTY_DISK_DIR"); }
CompositeCacheManager.getUnconfiguredInstance() );
/** * 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()); }
/** * Put half the max and clear. get the key array and verify that it has the correct number of * items. * <p> * @throws Exception */ public void testGetKeyArray() throws Exception { CompositeCacheManager cacheMgr = CompositeCacheManager.getUnconfiguredInstance(); cacheMgr.configure( "/TestSoftReferenceCache.ccf" ); CompositeCache<String, String> cache = cacheMgr.getCache( "testGetKeyArray" ); SoftReferenceMemoryCache<String, String> srmc = new SoftReferenceMemoryCache<String, String>(); srmc.initialize( cache ); int max = cache.getCacheAttributes().getMaxObjects(); int items = max / 2; for ( int i = 0; i < items; i++ ) { ICacheElement<String, String> ice = new CacheElement<String, String>( cache.getCacheName(), i + ":key", cache.getCacheName() + " data " + i ); ice.setElementAttributes( cache.getElementAttributes() ); srmc.update( ice ); } Set<String> keys = srmc.getKeySet(); assertEquals( "Wrong number of keys.", items, keys.size() ); }
/** * Put half the max and clear. get the key array and verify that it has the correct number of * items. * <p> * @throws Exception */ public void testGetKeyArray() throws Exception { CompositeCacheManager cacheMgr = CompositeCacheManager.getUnconfiguredInstance(); cacheMgr.configure( "/TestLHMLRUCache.ccf" ); CompositeCache<String, String> cache = cacheMgr.getCache( "testGetKeyArray" ); LHMLRUMemoryCache<String, String> mru = new LHMLRUMemoryCache<String, String>(); mru.initialize( cache ); int max = cache.getCacheAttributes().getMaxObjects(); int items = max / 2; for ( int i = 0; i < items; i++ ) { ICacheElement<String, String> ice = new CacheElement<String, String>( cache.getCacheName(), i + ":key", cache.getCacheName() + " data " + i ); ice.setElementAttributes( cache.getElementAttributes() ); mru.update( ice ); } Set<String> keys = mru.getKeySet(); assertEquals( "Wrong number of keys.", items, keys.size() ); }
/** * Put half the max and clear. get the key array and verify that it has the correct number of * items. * <p> * @throws Exception */ public void testGetKeyArray() throws Exception { CompositeCacheManager cacheMgr = CompositeCacheManager.getUnconfiguredInstance(); cacheMgr.configure( "/TestMRUCache.ccf" ); CompositeCache<String, String> cache = cacheMgr.getCache( "testGetKeyArray" ); MRUMemoryCache<String, String> mru = new MRUMemoryCache<String, String>(); mru.initialize( cache ); int max = cache.getCacheAttributes().getMaxObjects(); int items = max / 2; for ( int i = 0; i < items; i++ ) { ICacheElement<String, String> ice = new CacheElement<String, String>( cache.getCacheName(), i + ":key", cache.getCacheName() + " data " + i ); ice.setElementAttributes( cache.getElementAttributes() ); mru.update( ice ); } Set<String> keys = mru.getKeySet(); assertEquals( "Wrong number of keys.", items, keys.size() ); }
/** * Put half the max and clear. get the key array and verify that it has the correct number of * items. * <p> * @throws Exception */ public void testGetKeyArray() throws Exception { CompositeCacheManager cacheMgr = CompositeCacheManager.getUnconfiguredInstance(); cacheMgr.configure( "/TestLHMLRUCache.ccf" ); CompositeCache<String, String> cache = cacheMgr.getCache( "testGetKeyArray" ); LHMLRUMemoryCache<String, String> mru = new LHMLRUMemoryCache<String, String>(); mru.initialize( cache ); int max = cache.getCacheAttributes().getMaxObjects(); int items = max / 2; for ( int i = 0; i < items; i++ ) { ICacheElement<String, String> ice = new CacheElement<String, String>( cache.getCacheName(), i + ":key", cache.getCacheName() + " data " + i ); ice.setElementAttributes( cache.getElementAttributes() ); mru.update( ice ); } Set<String> keys = mru.getKeySet(); assertEquals( "Wrong number of keys.", items, keys.size() ); }
/** * Put half the max and clear. get the key array and verify that it has the correct number of * items. * <p> * @throws Exception */ public void testGetKeyArray() throws Exception { CompositeCacheManager cacheMgr = CompositeCacheManager.getUnconfiguredInstance(); cacheMgr.configure( "/TestMRUCache.ccf" ); CompositeCache<String, String> cache = cacheMgr.getCache( "testGetKeyArray" ); MRUMemoryCache<String, String> mru = new MRUMemoryCache<String, String>(); mru.initialize( cache ); int max = cache.getCacheAttributes().getMaxObjects(); int items = max / 2; for ( int i = 0; i < items; i++ ) { ICacheElement<String, String> ice = new CacheElement<String, String>( cache.getCacheName(), i + ":key", cache.getCacheName() + " data " + i ); ice.setElementAttributes( cache.getElementAttributes() ); mru.update( ice ); } Set<String> keys = mru.getKeySet(); assertEquals( "Wrong number of keys.", items, keys.size() ); }