Example #1
0
 protected void delegatePurgeExpired() {
   try {
     super.purgeExpired();
   } catch (CacheLoaderException e) {
     log.errorPurgingAsyncStore(e);
   }
 }
Example #2
0
 @Override
 public void start() throws CacheLoaderException {
   state = newStateMap();
   log.debugf("Async cache loader starting %s", this);
   stopped.set(false);
   lastAsyncProcessorShutsDownExecutor = false;
   super.start();
   int poolSize = asyncStoreConfig.getThreadPoolSize();
   executor =
       new ThreadPoolExecutor(
           poolSize,
           poolSize,
           0L,
           TimeUnit.MILLISECONDS,
           // note the use of poolSize+1 as maximum workingQueue together with DiscardPolicy:
           // this way when a new AsyncProcessor is started unnecessarily we discard it
           // before it takes locks to perform no work
           // this way we save memory from the executor queue, CPU, and also avoid
           // any possible RejectedExecutionException.
           new LinkedBlockingQueue<Runnable>(poolSize + 1),
           new ThreadFactory() {
             public Thread newThread(Runnable r) {
               Thread t = new Thread(r, "CoalescedAsyncStore-" + threadId.getAndIncrement());
               t.setDaemon(true);
               return t;
             }
           },
           new ThreadPoolExecutor.DiscardPolicy());
   startStoreCoordinator();
 }
Example #3
0
  @Override
  public void init(CacheLoaderConfig config, Cache<?, ?> cache, StreamingMarshaller m)
      throws CacheLoaderException {
    super.init(config, cache, m);
    Configuration cacheCfg = cache != null ? cache.getConfiguration() : null;
    concurrencyLevel = cacheCfg != null ? cacheCfg.getConcurrencyLevel() : 16;
    int cacheStopTimeout = cacheCfg != null ? cacheCfg.getCacheStopTimeout() : 30000;
    Long configuredAsyncStopTimeout = asyncStoreConfig.getShutdownTimeout();
    cacheName = cacheCfg != null ? cacheCfg.getName() : null;

    // Async store shutdown timeout cannot be bigger than
    // the overall cache stop timeout, so limit it accordingly.
    if (configuredAsyncStopTimeout >= cacheStopTimeout) {
      shutdownTimeout = Math.round(cacheStopTimeout * 0.90);
      log.asyncStoreShutdownTimeoutTooHigh(
          configuredAsyncStopTimeout, cacheStopTimeout, shutdownTimeout);
    } else {
      shutdownTimeout = configuredAsyncStopTimeout;
    }

    lockContainer = new ReleaseAllLockContainer(concurrencyLevel);
    transactions =
        new ConcurrentHashMap<GlobalTransaction, List<? extends Modification>>(
            64, 0.75f, concurrencyLevel);
  }
Example #4
0
 protected void applyModificationsSync(ConcurrentMap<Object, Modification> mods)
     throws CacheLoaderException {
   Set<Map.Entry<Object, Modification>> entries = mods.entrySet();
   for (Map.Entry<Object, Modification> entry : entries) {
     Modification mod = entry.getValue();
     switch (mod.getType()) {
       case STORE:
         super.store(((Store) mod).getStoredEntry());
         break;
       case REMOVE:
         super.remove(entry.getKey());
         break;
       default:
         throw new IllegalArgumentException("Unexpected modification type " + mod.getType());
     }
   }
 }
Example #5
0
 protected boolean applyClear() {
   try {
     super.clear();
     return true;
   } catch (CacheLoaderException e) {
     log.errorClearinAsyncStore(e);
     return false;
   }
 }
Example #6
0
 @Override
 public void stop() throws CacheLoaderException {
   stopped.set(true);
   try {
     changesDeque.put(QUIT_SIGNAL);
     executor.awaitTermination(shutdownTimeout, TimeUnit.MILLISECONDS);
   } catch (InterruptedException e) {
     log.interruptedWaitingAsyncStorePush(e);
     Thread.currentThread().interrupt();
   }
   super.stop();
 }