Exemplo n.º 1
0
  @Override
  protected void applyModifications(List<? extends Modification> mods) throws CacheLoaderException {
    Cassandra.Client cassandraClient = null;

    try {
      cassandraClient = dataSource.getConnection();
      Map<ByteBuffer, Map<String, List<Mutation>>> mutationMap =
          new HashMap<ByteBuffer, Map<String, List<Mutation>>>();

      for (Modification m : mods) {
        switch (m.getType()) {
          case STORE:
            store0(((Store) m).getStoredEntry(), mutationMap);
            break;
          case CLEAR:
            clear();
            break;
          case REMOVE:
            remove0(ByteBufferUtil.bytes(hashKey(((Remove) m).getKey())), mutationMap);
            break;
          default:
            throw new AssertionError();
        }
      }

      cassandraClient.batch_mutate(mutationMap, writeConsistencyLevel);

    } catch (Exception e) {
      throw new CacheLoaderException(e);
    } finally {
      dataSource.releaseConnection(cassandraClient);
    }
  }
Exemplo n.º 2
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());
     }
   }
 }
 /**
  * {@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());
     }
 }
Exemplo n.º 4
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();
   }
 }