@Override public Map<K, ValueHolder<V>> bulkCompute(Set<? extends K> keys, final Function<Iterable<? extends Map.Entry<? extends K, ? extends V>>, Iterable<? extends Map.Entry<? extends K, ? extends V>>> remappingFunction, Supplier<Boolean> replaceEqual) throws StoreAccessException { Map<K, ValueHolder<V>> result = new HashMap<>(); for (K key : keys) { checkKey(key); final ValueHolder<V> newValue = computeAndGet(key, (k, oldValue) -> { final Set<Map.Entry<K, V>> entrySet = Collections.singletonMap(k, oldValue).entrySet(); final Iterable<? extends Map.Entry<? extends K, ? extends V>> entries = remappingFunction.apply(entrySet); final java.util.Iterator<? extends Map.Entry<? extends K, ? extends V>> iterator = entries.iterator(); final Map.Entry<? extends K, ? extends V> next = iterator.next(); K key1 = next.getKey(); V value = next.getValue(); checkKey(key1); if (value != null) { checkValue(value); } return value; }, replaceEqual, () -> false); result.put(key, newValue); } return result; }
@Override public Map<K, ValueHolder<V>> bulkComputeIfAbsent(Set<? extends K> keys, final Function<Iterable<? extends K>, Iterable<? extends Map.Entry<? extends K, ? extends V>>> mappingFunction) throws StoreAccessException { Map<K, ValueHolder<V>> result = new HashMap<>(); for (final K key : keys) { final ValueHolder<V> newValue = computeIfAbsent(key, keyParam -> { final Iterable<K> keySet = Collections.singleton(keyParam); final Iterable<? extends Map.Entry<? extends K, ? extends V>> entries = mappingFunction.apply(keySet); final java.util.Iterator<? extends Map.Entry<? extends K, ? extends V>> iterator = entries.iterator(); final Map.Entry<? extends K, ? extends V> next = iterator.next(); K computedKey = next.getKey(); V computedValue = next.getValue(); checkKey(computedKey); if (computedValue == null) { return null; } checkValue(computedValue); return computedValue; }); result.put(key, newValue); } return result; }
@Override public boolean containsKey(K key) throws StoreAccessException { checkKey(key); if (getCurrentContext().touched(key)) { return getCurrentContext().newValueHolderOf(key) != null; } ValueHolder<SoftLock<V>> softLockValueHolder = getSoftLockValueHolderFromUnderlyingStore(key); return softLockValueHolder != null && softLockValueHolder.get().getTransactionId() == null && softLockValueHolder.get().getOldValue() != null; }
@Override public ValueHolder<V> computeAndGet(K key, BiFunction<? super K, ? super V, ? extends V> mappingFunction, Supplier<Boolean> replaceEqual, Supplier<Boolean> invokeWriter) throws StoreAccessException { checkKey(key); XATransactionContext<K, V> currentContext = getCurrentContext(); if (currentContext.touched(key)) {
@Override public RemoveStatus remove(K key, V value) throws StoreAccessException { checkKey(key); checkValue(value); XATransactionContext<K, V> currentContext = getCurrentContext();
@Override public ValueHolder<V> get(K key) throws StoreAccessException { checkKey(key); XATransactionContext<K, V> currentContext = getCurrentContext(); if (currentContext.removed(key)) { return null; } XAValueHolder<V> newValueHolder = currentContext.newValueHolderOf(key); if (newValueHolder != null) { return newValueHolder; } ValueHolder<SoftLock<V>> softLockValueHolder = getSoftLockValueHolderFromUnderlyingStore(key); if (softLockValueHolder == null) { return null; } SoftLock<V> softLock = softLockValueHolder.get(); if (isInDoubt(softLock)) { currentContext.addCommand(key, new StoreEvictCommand<>(softLock.getOldValue())); return null; } return new XAValueHolder<>(softLockValueHolder, softLock.getOldValue()); }
@Override public ReplaceStatus replace(K key, V oldValue, V newValue) throws StoreAccessException { checkKey(key); checkValue(oldValue); checkValue(newValue);
@Override public boolean remove(K key) throws StoreAccessException { checkKey(key); XATransactionContext<K, V> currentContext = getCurrentContext(); if (currentContext.touched(key)) { V oldValue = currentContext.oldValueOf(key); V newValue = currentContext.newValueOf(key); currentContext.addCommand(key, new StoreRemoveCommand<>(oldValue)); return newValue != null; } ValueHolder<SoftLock<V>> softLockValueHolder = getSoftLockValueHolderFromUnderlyingStore(key); boolean status = false; if (softLockValueHolder != null) { SoftLock<V> softLock = softLockValueHolder.get(); if (isInDoubt(softLock)) { currentContext.addCommand(key, new StoreEvictCommand<>(softLock.getOldValue())); } else { status = currentContext.addCommand(key, new StoreRemoveCommand<>(softLock.getOldValue())); } } return status; }
@Override public ValueHolder<V> computeIfAbsent(K key, final Function<? super K, ? extends V> mappingFunction) throws StoreAccessException { checkKey(key); XATransactionContext<K, V> currentContext = getCurrentContext(); if (currentContext.removed(key)) {
@Override public ValueHolder<V> getAndCompute(K key, BiFunction<? super K, ? super V, ? extends V> mappingFunction) throws StoreAccessException { checkKey(key); XATransactionContext<K, V> currentContext = getCurrentContext(); if (currentContext.touched(key)) {
@Override public ValueHolder<V> putIfAbsent(K key, V value, Consumer<Boolean> put) throws StoreAccessException { checkKey(key); checkValue(value); XATransactionContext<K, V> currentContext = getCurrentContext(); if (currentContext.touched(key)) { V oldValue = currentContext.oldValueOf(key); V newValue = currentContext.newValueOf(key); if (newValue == null) { currentContext.addCommand(key, new StorePutCommand<>(oldValue, new XAValueHolder<>(value, timeSource.getTimeMillis()))); return null; } else { return currentContext.newValueHolderOf(key); } } ValueHolder<SoftLock<V>> softLockValueHolder = getSoftLockValueHolderFromUnderlyingStore(key); if (softLockValueHolder != null) { SoftLock<V> softLock = softLockValueHolder.get(); if (isInDoubt(softLock)) { currentContext.addCommand(key, new StoreEvictCommand<>(softLock.getOldValue())); return null; } else { return new XAValueHolder<>(softLockValueHolder, softLock.getOldValue()); } } else { currentContext.addCommand(key, new StorePutCommand<>(null, new XAValueHolder<>(value, timeSource.getTimeMillis()))); return null; } }
@Override public PutStatus put(K key, V value) throws StoreAccessException { checkKey(key); checkValue(value); XATransactionContext<K, V> currentContext = getCurrentContext(); if (currentContext.touched(key)) { V oldValue = currentContext.oldValueOf(key); currentContext.addCommand(key, new StorePutCommand<>(oldValue, new XAValueHolder<>(value, timeSource.getTimeMillis()))); return PutStatus.PUT; } ValueHolder<SoftLock<V>> softLockValueHolder = getSoftLockValueHolderFromUnderlyingStore(key); if (softLockValueHolder != null) { SoftLock<V> softLock = softLockValueHolder.get(); if (isInDoubt(softLock)) { currentContext.addCommand(key, new StoreEvictCommand<>(softLock.getOldValue())); } else { if (currentContext.addCommand(key, new StorePutCommand<>(softLock.getOldValue(), new XAValueHolder<>(value, timeSource .getTimeMillis())))) { return PutStatus.PUT; } } } else { if (currentContext.addCommand(key, new StorePutCommand<>(null, new XAValueHolder<>(value, timeSource.getTimeMillis())))) { return PutStatus.PUT; } } return PutStatus.NOOP; }
@Override public ValueHolder<V> replace(K key, V value) throws StoreAccessException { checkKey(key); checkValue(value); XATransactionContext<K, V> currentContext = getCurrentContext();
@Override public Map<K, ValueHolder<V>> bulkCompute(Set<? extends K> keys, final Function<Iterable<? extends Map.Entry<? extends K, ? extends V>>, Iterable<? extends Map.Entry<? extends K, ? extends V>>> remappingFunction, Supplier<Boolean> replaceEqual) throws StoreAccessException { Map<K, ValueHolder<V>> result = new HashMap<>(); for (K key : keys) { checkKey(key); final ValueHolder<V> newValue = compute(key, (k, oldValue) -> { final Set<Map.Entry<K, V>> entrySet = Collections.singletonMap(k, oldValue).entrySet(); final Iterable<? extends Map.Entry<? extends K, ? extends V>> entries = remappingFunction.apply(entrySet); final java.util.Iterator<? extends Map.Entry<? extends K, ? extends V>> iterator = entries.iterator(); final Map.Entry<? extends K, ? extends V> next = iterator.next(); K key1 = next.getKey(); V value = next.getValue(); checkKey(key1); if (value != null) { checkValue(value); } return value; }, replaceEqual); result.put(key, newValue); } return result; }
@Override public Map<K, ValueHolder<V>> bulkComputeIfAbsent(Set<? extends K> keys, final Function<Iterable<? extends K>, Iterable<? extends Map.Entry<? extends K, ? extends V>>> mappingFunction) throws StoreAccessException { Map<K, ValueHolder<V>> result = new HashMap<>(); for (final K key : keys) { final ValueHolder<V> newValue = computeIfAbsent(key, keyParam -> { final Iterable<K> keySet = Collections.singleton(keyParam); final Iterable<? extends Map.Entry<? extends K, ? extends V>> entries = mappingFunction.apply(keySet); final java.util.Iterator<? extends Map.Entry<? extends K, ? extends V>> iterator = entries.iterator(); final Map.Entry<? extends K, ? extends V> next = iterator.next(); K computedKey = next.getKey(); V computedValue = next.getValue(); checkKey(computedKey); if (computedValue == null) { return null; } checkValue(computedValue); return computedValue; }); result.put(key, newValue); } return result; }
@Override public boolean containsKey(K key) throws StoreAccessException { checkKey(key); if (getCurrentContext().touched(key)) { return getCurrentContext().newValueHolderOf(key) != null; } ValueHolder<SoftLock<V>> softLockValueHolder = getSoftLockValueHolderFromUnderlyingStore(key); return softLockValueHolder != null && softLockValueHolder.get().getTransactionId() == null && softLockValueHolder.get().getOldValue() != null; }
@Override public ValueHolder<V> get(K key) throws StoreAccessException { checkKey(key); XATransactionContext<K, V> currentContext = getCurrentContext(); if (currentContext.removed(key)) { return null; } XAValueHolder<V> newValueHolder = currentContext.newValueHolderOf(key); if (newValueHolder != null) { return newValueHolder; } ValueHolder<SoftLock<V>> softLockValueHolder = getSoftLockValueHolderFromUnderlyingStore(key); if (softLockValueHolder == null) { return null; } SoftLock<V> softLock = softLockValueHolder.get(); if (isInDoubt(softLock)) { currentContext.addCommand(key, new StoreEvictCommand<>(softLock.getOldValue())); return null; } return new XAValueHolder<>(softLockValueHolder, softLock.getOldValue()); }
@Override public boolean remove(K key) throws StoreAccessException { checkKey(key); XATransactionContext<K, V> currentContext = getCurrentContext(); if (currentContext.touched(key)) { V oldValue = currentContext.oldValueOf(key); V newValue = currentContext.newValueOf(key); currentContext.addCommand(key, new StoreRemoveCommand<>(oldValue)); return newValue != null; } ValueHolder<SoftLock<V>> softLockValueHolder = getSoftLockValueHolderFromUnderlyingStore(key); boolean status = false; if (softLockValueHolder != null) { SoftLock<V> softLock = softLockValueHolder.get(); if (isInDoubt(softLock)) { currentContext.addCommand(key, new StoreEvictCommand<>(softLock.getOldValue())); } else { status = currentContext.addCommand(key, new StoreRemoveCommand<>(softLock.getOldValue())); } } return status; }
@Override public ValueHolder<V> putIfAbsent(K key, V value) throws StoreAccessException { checkKey(key); checkValue(value); XATransactionContext<K, V> currentContext = getCurrentContext(); if (currentContext.touched(key)) { V oldValue = currentContext.oldValueOf(key); V newValue = currentContext.newValueOf(key); if (newValue == null) { currentContext.addCommand(key, new StorePutCommand<>(oldValue, new XAValueHolder<>(value, timeSource.getTimeMillis()))); return null; } else { return currentContext.newValueHolderOf(key); } } ValueHolder<SoftLock<V>> softLockValueHolder = getSoftLockValueHolderFromUnderlyingStore(key); if (softLockValueHolder != null) { SoftLock<V> softLock = softLockValueHolder.get(); if (isInDoubt(softLock)) { currentContext.addCommand(key, new StoreEvictCommand<>(softLock.getOldValue())); return null; } else { return new XAValueHolder<>(softLockValueHolder, softLock.getOldValue()); } } else { currentContext.addCommand(key, new StorePutCommand<>(null, new XAValueHolder<>(value, timeSource.getTimeMillis()))); return null; } }
@Override public PutStatus put(K key, V value) throws StoreAccessException { checkKey(key); checkValue(value); XATransactionContext<K, V> currentContext = getCurrentContext(); if (currentContext.touched(key)) { V oldValue = currentContext.oldValueOf(key); currentContext.addCommand(key, new StorePutCommand<>(oldValue, new XAValueHolder<>(value, timeSource.getTimeMillis()))); return PutStatus.PUT; } ValueHolder<SoftLock<V>> softLockValueHolder = getSoftLockValueHolderFromUnderlyingStore(key); if (softLockValueHolder != null) { SoftLock<V> softLock = softLockValueHolder.get(); if (isInDoubt(softLock)) { currentContext.addCommand(key, new StoreEvictCommand<>(softLock.getOldValue())); } else { if (currentContext.addCommand(key, new StorePutCommand<>(softLock.getOldValue(), new XAValueHolder<>(value, timeSource .getTimeMillis())))) { return PutStatus.PUT; } } } else { if (currentContext.addCommand(key, new StorePutCommand<>(null, new XAValueHolder<>(value, timeSource.getTimeMillis())))) { return PutStatus.PUT; } } return PutStatus.NOOP; }