@Test(expected = IllegalArgumentException.class) public void initThrowsException() { cache.initCache(bufferStore, serializer, 0, 0, -12); }
protected void initCache(OffHeapByteBufferStore byteBufferStore, Serializer<V> serializer, long bufferCleanerPeriod, final float bufferCleanerThreshold, int concurrencyLevel) { if (concurrencyLevel > 11 || concurrencyLevel < 0) { throw new IllegalArgumentException("ConcurrencyLevel must be between 0 and 11 inclusive!"); } this.serializer = serializer; this.bufferStore = byteBufferStore; this.readWriteLock = new StripedReadWriteLock(concurrencyLevel); final ScheduledExecutorService cleanerService = Executors .newSingleThreadScheduledExecutor(runnable -> { String threadName = "imcache:bufferCleanerService(name=" + getName() + ",thread=" + NO_OF_CLEANERS.incrementAndGet() + ")"; return ThreadUtils.createDaemonThread(runnable, threadName); }); cleanerService .scheduleAtFixedRate(() -> cleanBuffers(bufferCleanerThreshold), bufferCleanerPeriod, bufferCleanerPeriod, TimeUnit.MILLISECONDS); final ScheduledExecutorService evictionService = Executors .newSingleThreadScheduledExecutor(runnable -> { String threadName = "imcache:evictionService(name=" + getName() + ",thread=" + NO_OF_EVICTORS.incrementAndGet() + ")"; return ThreadUtils.createDaemonThread(runnable, threadName); }); evictionService.scheduleAtFixedRate(() -> doEviction(), bufferCleanerPeriod, evictionPeriod, TimeUnit.MILLISECONDS); }
OffHeapCache extends AbstractSearchableCache<K, V> { protected void initCache(OffHeapByteBufferStore byteBufferStore, Serializer<V> serializer, long bufferCleanerPeriod, final float bufferCleanerThreshold, int concurrencyLevel) { if (concurrencyLevel > 11 || concurrencyLevel < 0) { throw new IllegalArgumentException("ConcurrencyLevel must be between 0 and 11 inclusive!"); } this.serializer = serializer; this.bufferStore = byteBufferStore; this.readWriteLock = new StripedReadWriteLock(concurrencyLevel); final ScheduledExecutorService cleanerService = Executors .newSingleThreadScheduledExecutor(runnable -> { String threadName = "imcache:bufferCleanerService(name=" + getName() + ",thread=" + NO_OF_CLEANERS.incrementAndGet() + ")"; return ThreadUtils.createDaemonThread(runnable, threadName); }); cleanerService .scheduleAtFixedRate(() -> cleanBuffers(bufferCleanerThreshold), bufferCleanerPeriod, bufferCleanerPeriod, TimeUnit.MILLISECONDS); final ScheduledExecutorService evictionService = Executors .newSingleThreadScheduledExecutor(runnable -> { String threadName = "imcache:evictionService(name=" + getName() + ",thread=" + NO_OF_EVICTORS.incrementAndGet() + ")"; return ThreadUtils.createDaemonThread(runnable, threadName); }); evictionService.scheduleAtFixedRate(() -> doEviction(), bufferCleanerPeriod, evictionPeriod, TimeUnit.MILLISECONDS); } }
OffHeapCache extends AbstractSearchableCache<K, V> { protected void initCache(OffHeapByteBufferStore byteBufferStore, Serializer<V> serializer, long bufferCleanerPeriod, final float bufferCleanerThreshold, int concurrencyLevel) { if (concurrencyLevel > 11 || concurrencyLevel < 0) { throw new IllegalArgumentException("ConcurrencyLevel must be between 0 and 11 inclusive!"); } this.serializer = serializer; this.bufferStore = byteBufferStore; this.readWriteLock = new StripedReadWriteLock(concurrencyLevel); final ScheduledExecutorService cleanerService = Executors .newSingleThreadScheduledExecutor(runnable -> { String threadName = "imcache:bufferCleanerService(name=" + getName() + ",thread=" + NO_OF_CLEANERS.incrementAndGet() + ")"; return ThreadUtils.createDaemonThread(runnable, threadName); }); cleanerService .scheduleAtFixedRate(() -> cleanBuffers(bufferCleanerThreshold), bufferCleanerPeriod, bufferCleanerPeriod, TimeUnit.MILLISECONDS); final ScheduledExecutorService evictionService = Executors .newSingleThreadScheduledExecutor(runnable -> { String threadName = "imcache:evictionService(name=" + getName() + ",thread=" + NO_OF_EVICTORS.incrementAndGet() + ")"; return ThreadUtils.createDaemonThread(runnable, threadName); }); evictionService.scheduleAtFixedRate(() -> doEviction(), bufferCleanerPeriod, evictionPeriod, TimeUnit.MILLISECONDS); } OffHeapCache(final String name, final CacheLoader<K, V> cacheLoader,
      final EvictionListener<K, V> evictionListener,
      final IndexHandler<K, V> indexHandler, final OffHeapByteBufferStore byteBufferStore,
      final Serializer<V> serializer,
      final long bufferCleanerPeriod, final float bufferCleanerThreshold,
      final int concurrencyLevel,
      final long evictionPeriod); }
OffHeapCache extends AbstractSearchableCache<K, V> { protected void initCache(OffHeapByteBufferStore byteBufferStore, Serializer<V> serializer, long bufferCleanerPeriod, final float bufferCleanerThreshold, int concurrencyLevel) { if (concurrencyLevel > 11 || concurrencyLevel < 0) { throw new IllegalArgumentException("ConcurrencyLevel must be between 0 and 11 inclusive!"); } this.serializer = serializer; this.bufferStore = byteBufferStore; this.readWriteLock = new StripedReadWriteLock(concurrencyLevel); final ScheduledExecutorService cleanerService = Executors .newSingleThreadScheduledExecutor(runnable -> { String threadName = "imcache:bufferCleanerService(name=" + getName() + ",thread=" + NO_OF_CLEANERS.incrementAndGet() + ")"; return ThreadUtils.createDaemonThread(runnable, threadName); }); cleanerService .scheduleAtFixedRate(() -> cleanBuffers(bufferCleanerThreshold), bufferCleanerPeriod, bufferCleanerPeriod, TimeUnit.MILLISECONDS); final ScheduledExecutorService evictionService = Executors .newSingleThreadScheduledExecutor(runnable -> { String threadName = "imcache:evictionService(name=" + getName() + ",thread=" + NO_OF_EVICTORS.incrementAndGet() + ")"; return ThreadUtils.createDaemonThread(runnable, threadName); }); evictionService.scheduleAtFixedRate(() -> doEviction(), bufferCleanerPeriod, evictionPeriod, TimeUnit.MILLISECONDS); } OffHeapCache(final String name, final CacheLoader<K, V> cacheLoader,
      final EvictionListener<K, V> evictionListener,
      final IndexHandler<K, V> indexHandler, final OffHeapByteBufferStore byteBufferStore,
      final Serializer<V> serializer,
      final long bufferCleanerPeriod, final float bufferCleanerThreshold,
      final int concurrencyLevel,
      final long evictionPeriod); void put(K key, V value); @Override void put(final K key, final V value, final TimeUnit timeUnit, final long duration); V get(K key); V invalidate(K key); boolean contains(K key); void clear(); @Override long size(); @Override CacheStats stats(); }
OffHeapCache extends AbstractSearchableCache<K, V> { protected void initCache(OffHeapByteBufferStore byteBufferStore, Serializer<V> serializer, long bufferCleanerPeriod, final float bufferCleanerThreshold, int concurrencyLevel) { if (concurrencyLevel > 11 || concurrencyLevel < 0) { throw new IllegalArgumentException("ConcurrencyLevel must be between 0 and 11 inclusive!"); } this.serializer = serializer; this.bufferStore = byteBufferStore; this.readWriteLock = new StripedReadWriteLock(concurrencyLevel); final ScheduledExecutorService cleanerService = Executors .newSingleThreadScheduledExecutor(runnable -> { String threadName = "imcache:bufferCleanerService(name=" + getName() + ",thread=" + NO_OF_CLEANERS.incrementAndGet() + ")"; return ThreadUtils.createDaemonThread(runnable, threadName); }); cleanerService .scheduleAtFixedRate(() -> cleanBuffers(bufferCleanerThreshold), bufferCleanerPeriod, bufferCleanerPeriod, TimeUnit.MILLISECONDS); final ScheduledExecutorService evictionService = Executors .newSingleThreadScheduledExecutor(runnable -> { String threadName = "imcache:evictionService(name=" + getName() + ",thread=" + NO_OF_EVICTORS.incrementAndGet() + ")"; return ThreadUtils.createDaemonThread(runnable, threadName); }); evictionService.scheduleAtFixedRate(() -> doEviction(), bufferCleanerPeriod, evictionPeriod, TimeUnit.MILLISECONDS); } OffHeapCache(final String name, final CacheLoader<K, V> cacheLoader,
      final EvictionListener<K, V> evictionListener,
      final IndexHandler<K, V> indexHandler, final OffHeapByteBufferStore byteBufferStore,
      final Serializer<V> serializer,
      final long bufferCleanerPeriod, final float bufferCleanerThreshold,
      final int concurrencyLevel,
      final long evictionPeriod); void put(K key, V value); @Override void put(final K key, final V value, final TimeUnit timeUnit, final long duration); V get(K key); V invalidate(K key); boolean contains(K key); void clear(); @Override long size(); @Override CacheStats stats(); static final long DEFAULT_BUFFER_CLEANER_PERIOD; static final long DEFAULT_EVICTION_PERIOD; static final float DEFAULT_BUFFER_CLEANER_THRESHOLD; static final int DEFAULT_CONCURRENCY_LEVEL; }