/** * Resets the file and creates a new key map. */ protected void reset() { synchronized (keyFile) { clearMemoryMap(); saveKeys(); } }
/** * Returns the number of keys. * <p> * (non-Javadoc) * @see org.apache.commons.jcs.auxiliary.disk.AbstractDiskCache#getSize() */ @Override public int getSize() { return this.keyStore.size(); }
/** * Return the keys in this cache. * <p> * @see org.apache.commons.jcs.auxiliary.disk.AbstractDiskCache#getKeySet() */ @Override public Set<K> getKeySet() throws IOException { HashSet<K> keys = new HashSet<K>(); storageLock.readLock().lock(); try { keys.addAll(this.keyStore.keySet()); } finally { storageLock.readLock().unlock(); } return keys; }
private void testSaveLoadKeysInner(BlockDiskCacheAttributes attributes) { BlockDiskKeyStore<String> keyStore = new BlockDiskKeyStore<String>( attributes, null ); keyStore.put( String.valueOf( i ), new int[blocks] ); keyStore.put( String.valueOf( i ), new int[i] ); assertEquals( "Wrong number of keys", numElements, keyStore.size() ); keyStore.saveKeys(); keyStore.clearMemoryMap(); assertEquals( "Wrong number of keys after clearing memory", 0, keyStore.size() ); keyStore.loadKeys(); assertEquals( "Wrong number of keys after loading", numElements, keyStore.size() ); for ( int i = 0; i < numElements; i++ ) int[] result = keyStore.get( String.valueOf( i ) ); assertEquals( "Wrong array returned.", i, result.length );
private void innerTestPutKeys(BlockDiskCacheAttributes attributes) { BlockDiskCache<String, String> blockDiskCache = new BlockDiskCache<String, String>(attributes); BlockDiskKeyStore<String> keyStore = new BlockDiskKeyStore<String>(attributes, blockDiskCache); // DO WORK int numElements = 100; for (int i = 0; i < numElements; i++) { keyStore.put(String.valueOf(i), new int[i]); } // System.out.println( "testPutKeys " + keyStore ); // VERIFY assertEquals("Wrong number of keys", numElements, keyStore.size()); for (int i = 0; i < numElements; i++) { int[] result = keyStore.get(String.valueOf(i)); assertEquals("Wrong array returned.", i, result.length); } }
public void testObjectLargerThanMaxSize() { BlockDiskCacheAttributes attributes = new BlockDiskCacheAttributes(); attributes.setCacheName( "testObjectLargerThanMaxSize" ); attributes.setDiskPath( rootDirName ); attributes.setMaxKeySize( 1000 ); attributes.setBlockSizeBytes( 2000 ); attributes.setDiskLimitType(DiskLimitType.SIZE); @SuppressWarnings({ "unchecked", "rawtypes" }) BlockDiskKeyStore<String> keyStore = new BlockDiskKeyStore<String>( attributes, new BlockDiskCache(attributes)); keyStore.put("1", new int[1000]); keyStore.put("2", new int[1000]); assertNull(keyStore.get("1")); assertNotNull(keyStore.get("2")); } }
loadKeys(); if (!verify()) initKeyMap(); reset(); initKeyMap();
keyStore = new BlockDiskKeyStore<K>( this.blockDiskCacheAttributes, this ); if ( keyStore.size() == 0 || !alright )
Iterator<Map.Entry<K, int[]>> iter = this.keyStore.entrySet().iterator(); int[] ded = this.keyStore.get( key ); this.dataFile.freeBlocks( ded ); iter.remove(); Iterator<Map.Entry<K, int[]>> iter = this.keyStore.entrySet().iterator(); while ( iter.hasNext() ) ((GroupAttrName<?>)k).groupId.equals(((GroupAttrName<?>)key).groupId)) int[] ded = this.keyStore.get( key ); this.dataFile.freeBlocks( ded ); iter.remove(); int[] ded = this.keyStore.remove( key ); removed = ded != null; if ( removed )
@Override public void run() { keyStore.saveKeys(); } },
int[] ded = this.keyStore.get( key ); if ( ded != null )
Iterator<Map.Entry<K, int[]>> it = this.keyStore.entrySet().iterator(); while ( it.hasNext() && count < maxToTest )
private void testSaveLoadKeysInner(BlockDiskCacheAttributes attributes) BlockDiskKeyStore<String> keyStore = new BlockDiskKeyStore<String>(attributes, null); block2[j] = blockIndex++; keyStore.put(String.valueOf(i), block1); keyStore.put(String.valueOf(i), block2); assertEquals("Wrong number of keys", numElements, keyStore.size()); keyStore.saveKeys(); keyStore.clearMemoryMap(); assertEquals("Wrong number of keys after clearing memory", 0, keyStore.size()); keyStore.loadKeys(); assertEquals("Wrong number of keys after loading", numElements, keyStore.size()); for (int i = 0; i < numElements; i++) int[] result = keyStore.get(String.valueOf(i)); assertEquals("Wrong array returned.", i, result.length);
private void innerTestPutKeys(BlockDiskCacheAttributes attributes) { BlockDiskCache<String, String> blockDiskCache = new BlockDiskCache<String, String>( attributes ); BlockDiskKeyStore<String> keyStore = new BlockDiskKeyStore<String>( attributes, blockDiskCache ); // DO WORK int numElements = 100; for ( int i = 0; i < numElements; i++ ) { keyStore.put( String.valueOf( i ), new int[i] ); } // System.out.println( "testPutKeys " + keyStore ); // VERIFY assertEquals( "Wrong number of keys", numElements, keyStore.size() ); for ( int i = 0; i < numElements; i++ ) { int[] result = keyStore.get( String.valueOf( i ) ); assertEquals( "Wrong array returned.", i, result.length ); } }
public void testObjectLargerThanMaxSize() { BlockDiskCacheAttributes attributes = new BlockDiskCacheAttributes(); attributes.setCacheName("testObjectLargerThanMaxSize"); attributes.setDiskPath(rootDirName); attributes.setMaxKeySize(1000); attributes.setBlockSizeBytes(2000); attributes.setDiskLimitType(DiskLimitType.SIZE); @SuppressWarnings({ "unchecked", "rawtypes" }) BlockDiskKeyStore<String> keyStore = new BlockDiskKeyStore<String>(attributes, new BlockDiskCache(attributes)); keyStore.put("1", new int[1000]); keyStore.put("2", new int[1000]); assertNull(keyStore.get("1")); assertNotNull(keyStore.get("2")); } }
keyStore = new BlockDiskKeyStore<K>( this.blockDiskCacheAttributes, this ); if ( keyStore.size() == 0 || !alright )