/** * Wraps the key in a LateralElementDescriptor. * <p> * @see org.apache.commons.jcs.engine.behavior.ICacheServiceNonLocal#remove(String, Object, long) */ @Override public void remove( String cacheName, K key, long requesterId ) throws IOException { CacheElement<K, V> ce = new CacheElement<K, V>( cacheName, key, null ); LateralElementDescriptor<K, V> led = new LateralElementDescriptor<K, V>( ce ); led.requesterId = requesterId; led.command = LateralCommand.REMOVE; sender.send( led ); }
/** * @param cacheName * @param requesterId * @throws IOException */ @Override public void removeAll( String cacheName, long requesterId ) throws IOException { CacheElement<String, String> ce = new CacheElement<String, String>( cacheName, "ALL", null ); LateralElementDescriptor<String, String> led = new LateralElementDescriptor<String, String>( ce ); led.requesterId = requesterId; led.command = LateralCommand.REMOVEALL; sender.send( led ); }
/** * @param cacheName * @param requesterId * @throws IOException */ @Override public void removeAll( String cacheName, long requesterId ) throws IOException { CacheElement<String, String> ce = new CacheElement<String, String>( cacheName, "ALL", null ); LateralElementDescriptor<String, String> led = new LateralElementDescriptor<String, String>( ce ); led.requesterId = requesterId; led.command = LateralCommand.REMOVEALL; sender.send( led ); }
/** * Wraps the key in a LateralElementDescriptor. * <p> * @see org.apache.commons.jcs.engine.behavior.ICacheServiceNonLocal#remove(java.lang.String, * java.io.Serializable, long) */ @Override public void remove( String cacheName, K key, long requesterId ) throws IOException { CacheElement<K, V> ce = new CacheElement<K, V>( cacheName, key, null ); LateralElementDescriptor<K, V> led = new LateralElementDescriptor<K, V>( ce ); led.requesterId = requesterId; led.command = LateralCommand.REMOVE; sender.send( led ); }
/** * Return the keys in this cache. * <p> * @param cacheName the name of the cache region * @see org.apache.commons.jcs.auxiliary.AuxiliaryCache#getKeySet() */ @Override @SuppressWarnings("unchecked") // Need cast from Object public Set<K> getKeySet(String cacheName) throws IOException { CacheElement<String, String> ce = new CacheElement<String, String>(cacheName, null, null); LateralElementDescriptor<String, String> led = new LateralElementDescriptor<String, String>(ce); // led.requesterId = requesterId; // later led.command = LateralCommand.GET_KEYSET; Object response = sender.sendAndReceive(led); if (response != null) { return (Set<K>) response; } return null; }
/** * Return the keys in this cache. * <p> * @param cacheName the name of the cache region * @see org.apache.commons.jcs.auxiliary.AuxiliaryCache#getKeySet() */ @Override @SuppressWarnings("unchecked") // Need cast from Object public Set<K> getKeySet(String cacheName) throws IOException { CacheElement<String, String> ce = new CacheElement<String, String>(cacheName, null, null); LateralElementDescriptor<String, String> led = new LateralElementDescriptor<String, String>(ce); // led.requesterId = requesterId; // later led.command = LateralCommand.GET_KEYSET; Object response = sender.sendAndReceive(led); if (response != null) { return (Set<K>) response; } return null; }
/** * Creates an array of ICacheElements with DiskTestObjects with payloads the byte size. * <p> * @param numToCreate * @param bytes * @param cacheName * @return ICacheElement[] */ public static ICacheElement<Integer, DiskTestObject>[] createCacheElementsWithTestObjects( int numToCreate, int bytes, String cacheName ) { @SuppressWarnings("unchecked") ICacheElement<Integer, DiskTestObject>[] elements = new ICacheElement[numToCreate]; for ( int i = 0; i < numToCreate; i++ ) { // 24 KB int size = bytes * 1024; DiskTestObject tile = new DiskTestObject( Integer.valueOf( i ), new byte[size] ); ICacheElement<Integer, DiskTestObject> element = new CacheElement<Integer, DiskTestObject>( cacheName, tile.id, tile ); elements[i] = element; } return elements; }
/** * Creates an array of ICacheElements with DiskTestObjects with payloads the byte size. * <p> * @param numToCreate * @param bytes * @param cacheName * @return ICacheElement[] */ public static ICacheElement<Integer, DiskTestObject>[] createCacheElementsWithTestObjects( int numToCreate, int bytes, String cacheName ) { @SuppressWarnings("unchecked") ICacheElement<Integer, DiskTestObject>[] elements = new ICacheElement[numToCreate]; for ( int i = 0; i < numToCreate; i++ ) { // 24 KB int size = bytes * 1024; DiskTestObject tile = new DiskTestObject( Integer.valueOf( i ), new byte[size] ); ICacheElement<Integer, DiskTestObject> element = new CacheElement<Integer, DiskTestObject>( cacheName, tile.id, tile ); elements[i] = element; } return elements; }
/** * Creates an array of ICacheElements with DiskTestObjects with payloads the byte size. * <p> * @param numToCreate * @param cacheName * @return ICacheElement[] */ public static ICacheElement<Integer, DiskTestObject>[] createCacheElementsWithTestObjectsOfVariableSizes( int numToCreate, String cacheName ) { @SuppressWarnings("unchecked") ICacheElement<Integer, DiskTestObject>[] elements = new ICacheElement[numToCreate]; Random random = new Random( 89 ); for ( int i = 0; i < numToCreate; i++ ) { int bytes = random.nextInt( 20 ); // 4-24 KB int size = ( bytes + 4 ) * 1024; DiskTestObject tile = new DiskTestObject( Integer.valueOf( i ), new byte[size] ); ICacheElement<Integer, DiskTestObject> element = new CacheElement<Integer, DiskTestObject>( cacheName, tile.id, tile ); elements[i] = element; } return elements; }
/** * Creates an array of ICacheElements with DiskTestObjects with payloads the byte size. * <p> * @param numToCreate * @param cacheName * @return ICacheElement[] */ public static ICacheElement<Integer, DiskTestObject>[] createCacheElementsWithTestObjectsOfVariableSizes( int numToCreate, String cacheName ) { @SuppressWarnings("unchecked") ICacheElement<Integer, DiskTestObject>[] elements = new ICacheElement[numToCreate]; Random random = new Random( 89 ); for ( int i = 0; i < numToCreate; i++ ) { int bytes = random.nextInt( 20 ); // 4-24 KB int size = ( bytes + 4 ) * 1024; DiskTestObject tile = new DiskTestObject( Integer.valueOf( i ), new byte[size] ); ICacheElement<Integer, DiskTestObject> element = new CacheElement<Integer, DiskTestObject>( cacheName, tile.id, tile ); elements[i] = element; } return elements; }
private ICacheElement<K, V> updateElement(final K key, final V v, final Duration duration, final IElementAttributes attrs) { final ICacheElement<K, V> element = new CacheElement<K, V>(name, key, v); if (duration != null) { attrs.setTimeFactorForMilliseconds(1); final boolean eternal = duration.isEternal(); attrs.setIsEternal(eternal); if (!eternal) { attrs.setLastAccessTimeNow(); } // MaxLife = -1 to use IdleTime excepted if jcache.ccf asked for something else } element.setElementAttributes(attrs); return element; }
/** * Simply verify that the client getMultiple is called from the no wait. * <p> * @throws Exception */ public void testGetMultiple() throws Exception { // SETUP MockRemoteCacheClient<String, String> client = new MockRemoteCacheClient<String, String>(); RemoteCacheNoWait<String, String> noWait = new RemoteCacheNoWait<String, String>( client ); ICacheElement<String, String> inputElement = new CacheElement<String, String>( "testUpdate", "key", "value" ); Map<String, ICacheElement<String, String>> inputMap = new HashMap<String, ICacheElement<String,String>>(); inputMap.put( "key", inputElement ); Set<String> keys = new HashSet<String>(); keys.add( "key" ); client.getMultipleSetupMap.put( keys, inputMap ); // DO WORK Map<String, ICacheElement<String, String>> result = noWait.getMultiple( keys ); // VERIFY assertEquals( "elements map", inputMap, result ); }
/** * Adds put events to the queue. * @param end * @param expectedPutCount * @throws Exception */ public void runPutTest( int end, int expectedPutCount ) throws Exception { for ( int i = 0; i <= end; i++ ) { CacheElement<String, String> elem = new CacheElement<String, String>( "testCache1", i + ":key", i + "data" ); queue.addPutEvent( elem ); } while ( !queue.isEmpty() ) { synchronized ( this ) { System.out.println( "queue is still busy, waiting 250 millis" ); this.wait( 250 ); } } System.out.println( "queue is empty, comparing putCount" ); // this becomes less accurate with each test. It should never fail. If // it does things are very off. assertTrue( "The put count [" + listen.putCount + "] is below the expected minimum threshold [" + expectedPutCount + "]", listen.putCount >= ( expectedPutCount - 1 ) ); }
/** * Simply verify that the client getMultiple is called from the no wait. * <p> * @throws Exception */ public void testGetMultiple() throws Exception { // SETUP MockRemoteCacheClient<String, String> client = new MockRemoteCacheClient<String, String>(); RemoteCacheNoWait<String, String> noWait = new RemoteCacheNoWait<String, String>( client ); ICacheElement<String, String> inputElement = new CacheElement<String, String>( "testUpdate", "key", "value" ); Map<String, ICacheElement<String, String>> inputMap = new HashMap<String, ICacheElement<String,String>>(); inputMap.put( "key", inputElement ); Set<String> keys = new HashSet<String>(); keys.add( "key" ); client.getMultipleSetupMap.put( keys, inputMap ); // DO WORK Map<String, ICacheElement<String, String>> result = noWait.getMultiple( keys ); // VERIFY assertEquals( "elements map", inputMap, result ); }
private void touch(final K key, final ICacheElement<K, V> element) { if (config.isStoreByValue()) { final K copy = copy(serializer, manager.getClassLoader(), key); try { delegate.update(new CacheElement<K, V>(name, copy, element.getVal(), element.getElementAttributes())); } catch (final IOException e) { throw new CacheException(e); } } }
private ICacheElement<K, V> updateElement(final K key, final V v, final Duration duration) { final ICacheElement<K, V> element = new CacheElement<K, V>(name, key, v); final IElementAttributes copy = delegate.getElementAttributes().copy(); if (duration != null) { copy.setTimeFactorForMilliseconds(1); final boolean eternal = duration.isEternal(); copy.setIsEternal(eternal); if (!eternal) { copy.setIdleTime(duration.getTimeUnit().toMillis(duration.getDurationAmount())); } // MaxLife = -1 to use IdleTime excepted if jcache.ccf asked for something else } element.setElementAttributes(copy); return element; }
private void touch(final K key, final ICacheElement<K, V> element) { if (config.isStoreByValue()) { final K copy = copy(serializer, manager.getClassLoader(), key); try { delegate.update(new CacheElement<K, V>(name, copy, element.getVal(), element.getElementAttributes())); } catch (final IOException e) { throw new CacheException(e); } } }
/** Verify basic data */ public void testToString_normal() { // SETUP String cacheName = "myCacheName"; String key = "myKey"; String value = "myValue"; IElementAttributes elementAttributes = new ElementAttributes(); ICacheElement<String, String> cacheElement = new CacheElement<String, String>( cacheName, key, value, elementAttributes ); PurgatoryElement<String, String> purgatoryElement = new PurgatoryElement<String, String>( cacheElement ); // DO WORK String result = purgatoryElement.toString(); // VERIFY assertTrue( "Should have the cacheName.", result.indexOf( cacheName ) != -1 ); assertTrue( "Should have the key.", result.indexOf( key ) != -1 ); assertTrue( "Should have the value.", result.indexOf( value ) != -1 ); } }
/** Verify basic data */ public void testToString_normal() { // SETUP String cacheName = "myCacheName"; String key = "myKey"; String value = "myValue"; IElementAttributes elementAttributes = new ElementAttributes(); ICacheElement<String, String> cacheElement = new CacheElement<String, String>( cacheName, key, value, elementAttributes ); PurgatoryElement<String, String> purgatoryElement = new PurgatoryElement<String, String>( cacheElement ); // DO WORK String result = purgatoryElement.toString(); // VERIFY assertTrue( "Should have the cacheName.", result.indexOf( cacheName ) != -1 ); assertTrue( "Should have the key.", result.indexOf( key ) != -1 ); assertTrue( "Should have the value.", result.indexOf( value ) != -1 ); } }
/** * Simply verify that the client get is called from the no wait. * <p> * @throws Exception */ public void testGet() throws Exception { // SETUP MockRemoteCacheClient<String, String> client = new MockRemoteCacheClient<String, String>(); RemoteCacheNoWait<String, String> noWait = new RemoteCacheNoWait<String, String>( client ); ICacheElement<String, String> input = new CacheElement<String, String>( "testUpdate", "key", "value" ); client.getSetupMap.put( "key", input ); // DO WORK ICacheElement<String, String> result = noWait.get( "key" ); // VERIFY assertEquals( "Wrong element", input, result ); }