@Override public CascadingCache create( FlowProcess flowProcess ) { return new DirectMappedCache(); }
@Override public boolean containsKey( Object key ) { if( key == null ) throw new IllegalArgumentException( "null keys are not permitted" ); return get( key ) != null; }
@Override public Value get( Object key ) { int index = index( key ); Entry<Key, Value> existing = elements[ index ]; if( existing == null || !key.equals( existing.getKey() ) ) return null; return existing.getValue(); }
int index = index( key ); Entry<Key, Value> existing = elements[ index ]; if( putCalls % getCapacity() == 0 ) long totalMem = runtime.totalMemory() / 1024 / 1024; LOG.info( "mem on flush (mb), free: " + freeMem + ", total: " + totalMem + ", max: " + maxMem ); LOG.info( "capacity={}, puts={}, collisions={}, fill factor={}%", getCapacity(), putCalls, collisions, ( (double) getCapacity() / actualSize ) * 100 ); float percent = (float) totalMem / (float) maxMem; if( percent < 0.80F )
@Override public void putAll( Map<? extends Key, ? extends Value> m ) { for( Entry<? extends Key, ? extends Value> entry : m.entrySet() ) put( entry.getKey(), entry.getValue() ); }
private CascadingCache<Object, Object> getDirectMappedCache( int capacity, CacheEvictionCallback cacheEvictionCallback ) { CascadingCache<Object, Object> map = new DirectMappedCache<Object, Object>(); map.setCacheEvictionCallback( cacheEvictionCallback ); map.setCapacity( capacity ); map.initialize(); return map; }
@Override public Value remove( Object key ) { if( key == null ) throw new IllegalArgumentException( "key cannot be null" ); int index = index( key ); Entry<Key, Value> existing = elements[ index ]; if( existing == null || !existing.getKey().equals( key ) ) return null; elements[ index ] = null; actualSize--; evictionCallBack.evict( existing ); return existing.getValue(); }