Exemplo n.º 1
0
 private void replaceAll(AdvancedCache cache, Map<? extends K, ? extends V> map) {
   startAtomic();
   try {
     AtomicMap<K, V> data = getDataInternal(cache);
     data.clear();
     data.putAll(map);
   } finally {
     endAtomic();
   }
 }
Exemplo n.º 2
0
 private V replace(AdvancedCache<?, ?> cache, K key, V value) {
   startAtomic();
   try {
     AtomicMap<K, V> map = getAtomicMap(cache, dataKey);
     if (map.containsKey(key)) return map.put(key, value);
     else return null;
   } finally {
     endAtomic();
   }
 }
Exemplo n.º 3
0
 private V putIfAbsent(AdvancedCache<?, ?> cache, K key, V value) {
   startAtomic();
   try {
     AtomicMap<K, V> data = getDataInternal(cache);
     if (!data.containsKey(key)) return data.put(key, value);
     return null;
   } finally {
     endAtomic();
   }
 }
 @Override
 public void replaceAll(Map<? extends K, ? extends V> map) {
   startAtomic();
   try {
     AtomicMap<K, V> data = getDataInternal();
     data.clear();
     data.putAll(map);
   } finally {
     endAtomic();
   }
 }
 @Override
 public V replace(K key, V value) {
   startAtomic();
   try {
     AtomicMap<K, V> map = getAtomicMap(dataKey);
     if (map.containsKey(key)) return map.put(key, value);
     else return null;
   } finally {
     endAtomic();
   }
 }
  @Override
  public V putIfAbsent(K key, V value) {
    startAtomic();
    try {
      AtomicMap<K, V> data = getDataInternal();
      if (!data.containsKey(key)) return data.put(key, value);

      return null;
    } finally {
      endAtomic();
    }
  }
Exemplo n.º 7
0
 private boolean replace(AdvancedCache<?, ?> cache, K key, V oldValue, V newValue) {
   startAtomic();
   try {
     AtomicMap<K, V> data = getDataInternal(cache);
     V old = data.get(key);
     if (Util.safeEquals(oldValue, old)) {
       data.put(key, newValue);
       return true;
     }
     return false;
   } finally {
     endAtomic();
   }
 }
 @Override
 public boolean replace(K key, V oldValue, V newValue) {
   startAtomic();
   try {
     AtomicMap<K, V> data = getDataInternal();
     V old = data.get(key);
     if (Util.safeEquals(oldValue, old)) {
       data.put(key, newValue);
       return true;
     }
     return false;
   } finally {
     endAtomic();
   }
 }
Exemplo n.º 9
0
  private Node<K, V> addChild(AdvancedCache<?, ?> cache, Fqn f) {
    startAtomic();
    try {
      Fqn absoluteChildFqn = Fqn.fromRelativeFqn(fqn, f);

      // 1) first register it with the parent
      AtomicMap<Object, Fqn> structureMap = getStructure(cache);
      structureMap.put(f.getLastElement(), absoluteChildFqn);

      // 2) then create the structure and data maps
      createNodeInCache(cache, absoluteChildFqn);

      return new NodeImpl<K, V>(absoluteChildFqn, cache, batchContainer);
    } finally {
      endAtomic();
    }
  }
Exemplo n.º 10
0
  private boolean removeChild(AdvancedCache cache, Object childName) {
    startAtomic();
    try {
      AtomicMap<Object, Fqn> s = getStructure(cache);
      Fqn childFqn = s.remove(childName);
      if (childFqn != null) {
        Node<K, V> child = new NodeImpl<K, V>(childFqn, cache, batchContainer);
        child.removeChildren();
        child
            .clearData(); // this is necessary in case we have a remove and then an add on the same
                          // node, in the same tx.
        cache.remove(new NodeKey(childFqn, NodeKey.Type.DATA));
        cache.remove(new NodeKey(childFqn, NodeKey.Type.STRUCTURE));
        return true;
      }

      return false;
    } finally {
      endAtomic();
    }
  }