/**
  * {@inheritDoc} This implementation iterates through a list of work represented by {@link
  * Modification} objects and executes it against the {@link CacheStore}.
  *
  * <p>Current commands supported are:
  *
  * <ul>
  *   <li>STORE
  *   <li>CLEAR
  *   <li>REMOVE
  *   <li>PURGE_EXPIRED
  * </ul>
  */
 public void doWork() throws Exception {
   for (Modification modification : mods)
     switch (modification.getType()) {
       case STORE:
         Store s = (Store) modification;
         cs.store(s.getStoredEntry());
         break;
       case CLEAR:
         cs.clear();
         break;
       case REMOVE:
         Remove r = (Remove) modification;
         cs.remove(r.getKey());
         break;
       case PURGE_EXPIRED:
         cs.purgeExpired();
         break;
       default:
         throw new IllegalArgumentException("Unknown modification type " + modification.getType());
     }
 }
Beispiel #2
0
 private void handle(Modification mod, boolean nested) {
   boolean asyncProcessorNeeded = false;
   switch (mod.getType()) {
     case STORE:
       Store store = (Store) mod;
       stateMapLock.lock();
       state.put(store.getStoredEntry().getKey(), store);
       stateMapLock.unlock();
       asyncProcessorNeeded = true;
       break;
     case REMOVE:
       Remove remove = (Remove) mod;
       stateMapLock.lock();
       state.put(remove.getKey(), remove);
       stateMapLock.unlock();
       asyncProcessorNeeded = true;
       break;
     case CLEAR:
       performClear();
       break;
     case PURGE_EXPIRED:
       delegatePurgeExpired();
       break;
     case LIST:
       applyModificationsList((ModificationsList) mod);
       asyncProcessorNeeded = true;
       break;
     default:
       throw new IllegalArgumentException("Unexpected modification type " + mod.getType());
   }
   if (asyncProcessorNeeded && !nested) {
     // we know when it's possible for some work to be done, starting short-lived
     // AsyncProcessor(s) simplifies shutdown process.
     ensureMoreWorkIsHandled();
   }
 }