예제 #1
0
 @Override
 public ReplaceStatus replace(final K key, final V oldValue, final V newValue)
     throws StoreAccessException {
   conditionalReplaceObserver.begin();
   try {
     ConditionalReplaceOperation<K, V> operation =
         new ConditionalReplaceOperation<K, V>(
             key, oldValue, newValue, timeSource.getTimeMillis());
     ByteBuffer payload = codec.encode(operation);
     Chain chain = storeProxy.getAndAppend(key.hashCode(), payload);
     ResolvedChain<K, V> resolvedChain = resolver.resolve(chain, key, timeSource.getTimeMillis());
     Result<V> result = resolvedChain.getResolvedResult(key);
     if (result != null) {
       if (oldValue.equals(result.getValue())) {
         conditionalReplaceObserver.end(StoreOperationOutcomes.ConditionalReplaceOutcome.REPLACED);
         return ReplaceStatus.HIT;
       } else {
         conditionalReplaceObserver.end(StoreOperationOutcomes.ConditionalReplaceOutcome.MISS);
         return ReplaceStatus.MISS_PRESENT;
       }
     } else {
       conditionalReplaceObserver.end(StoreOperationOutcomes.ConditionalReplaceOutcome.MISS);
       return ReplaceStatus.MISS_NOT_PRESENT;
     }
   } catch (RuntimeException re) {
     handleRuntimeException(re);
     return null;
   }
 }
예제 #2
0
 @Override
 public boolean remove(final K key) throws StoreAccessException {
   removeObserver.begin();
   if (silentRemove(key)) {
     removeObserver.end(StoreOperationOutcomes.RemoveOutcome.REMOVED);
     return true;
   } else {
     removeObserver.end(StoreOperationOutcomes.RemoveOutcome.MISS);
     return false;
   }
 }
예제 #3
0
 @Override
 public ValueHolder<V> get(final K key) throws StoreAccessException {
   getObserver.begin();
   V value = getInternal(key);
   if (value == null) {
     getObserver.end(StoreOperationOutcomes.GetOutcome.MISS);
     return null;
   } else {
     getObserver.end(StoreOperationOutcomes.GetOutcome.HIT);
     return new ClusteredValueHolder<V>(value);
   }
 }
예제 #4
0
 @Override
 public ValueHolder<V> getAndFault(K key) throws CacheAccessException {
   getOperationObserver.begin();
   checkKey(key);
   OffHeapValueHolder<V> mappedValue = map.getAndPin(key);
   if (mappedValue == null) {
     getOperationObserver.end(StoreOperationOutcomes.GetOutcome.MISS);
   } else {
     getOperationObserver.end(StoreOperationOutcomes.GetOutcome.HIT);
   }
   return mappedValue;
 }
예제 #5
0
  @Override
  public ValueHolder<V> get(K key) {
    checkKey(key);
    getOperationObserver.begin();

    ValueHolder<V> result = internalGet(key, true);
    if (result == null) {
      getOperationObserver.end(StoreOperationOutcomes.GetOutcome.MISS);
    } else {
      getOperationObserver.end(StoreOperationOutcomes.GetOutcome.HIT);
    }
    return result;
  }
예제 #6
0
 @Override
 public PutStatus put(final K key, final V value) throws StoreAccessException {
   putObserver.begin();
   PutStatus status = silentPut(key, value);
   switch (status) {
     case PUT:
       putObserver.end(StoreOperationOutcomes.PutOutcome.PUT);
       break;
     case UPDATE:
       putObserver.end(StoreOperationOutcomes.PutOutcome.REPLACED);
       break;
     case NOOP:
       putObserver.end(StoreOperationOutcomes.PutOutcome.NOOP);
       break;
     default:
       throw new AssertionError("Invalid put status: " + status);
   }
   return status;
 }
예제 #7
0
 @Override
 public void remove(K key) {
   checkKey(key);
   removeOperationObserver.begin();
   try {
     map.remove(key);
   } finally {
     removeOperationObserver.end(StoreOperationOutcomes.RemoveOutcome.SUCCESS);
   }
 }
예제 #8
0
 @Override
 public ValueHolder<V> replace(final K key, final V value) throws StoreAccessException {
   replaceObserver.begin();
   try {
     ReplaceOperation<K, V> operation =
         new ReplaceOperation<K, V>(key, value, timeSource.getTimeMillis());
     ByteBuffer payload = codec.encode(operation);
     Chain chain = storeProxy.getAndAppend(key.hashCode(), payload);
     ResolvedChain<K, V> resolvedChain = resolver.resolve(chain, key, timeSource.getTimeMillis());
     Result<V> result = resolvedChain.getResolvedResult(key);
     if (result == null) {
       replaceObserver.end(StoreOperationOutcomes.ReplaceOutcome.MISS);
       return null;
     } else {
       replaceObserver.end(StoreOperationOutcomes.ReplaceOutcome.REPLACED);
       return new ClusteredValueHolder<V>(result.getValue());
     }
   } catch (RuntimeException re) {
     handleRuntimeException(re);
     return null;
   }
 }