@Override public ValueHolder<String> get(final String key) throws StoreAccessException { this.checkFailingKey(key); final FakeValueHolder valueHolder = this.entries.get(key); if (valueHolder != null) { valueHolder.lastAccessTime = System.currentTimeMillis(); } return valueHolder; }
@Override public RemoveStatus remove(final String key, final String value) throws StoreAccessException { this.checkFailingKey(key); final ValueHolder<String> currentValue = this.entries.get(key); if (currentValue == null) { return RemoveStatus.KEY_MISSING; } else if (!currentValue.get().equals(value)) { return RemoveStatus.KEY_PRESENT; } this.entries.remove(key); return RemoveStatus.REMOVED; }
@Override public ValueHolder<String> putIfAbsent(final String key, final String value, Consumer<Boolean> put) throws StoreAccessException { this.checkFailingKey(key); final FakeValueHolder currentValue = this.entries.get(key); if (currentValue == null) { this.entries.put(key, new FakeValueHolder(value)); return null; } currentValue.lastAccessTime = System.currentTimeMillis(); return currentValue; }
@Override public ValueHolder<String> computeIfAbsent(final String key, final Function<? super String, ? extends String> mappingFunction) throws StoreAccessException { this.checkFailingKey(key); FakeValueHolder currentValue = this.entries.get(key); if (currentValue == null) { String newValue; try { newValue = mappingFunction.apply(key); } catch (StorePassThroughException cpte) { Throwable cause = cpte.getCause(); if(cause instanceof RuntimeException) { throw (RuntimeException) cause; } else if(cause instanceof StoreAccessException){ throw (StoreAccessException) cause; } else { throw new StoreAccessException(cause); } } if (newValue != null) { final FakeValueHolder newValueHolder = new FakeValueHolder(newValue); this.entries.put(key, newValueHolder); currentValue = newValueHolder; } } else { currentValue.lastAccessTime = System.currentTimeMillis(); } return currentValue; }
@Override public ReplaceStatus replace(final String key, final String oldValue, final String newValue) throws StoreAccessException { this.checkFailingKey(key); final ValueHolder<String> currentValue = this.entries.get(key); if (currentValue == null) { return ReplaceStatus.MISS_NOT_PRESENT; } if (!currentValue.get().equals(oldValue)) { return ReplaceStatus.MISS_PRESENT; } this.entries.put(key, new FakeValueHolder(newValue)); return ReplaceStatus.HIT; }
@Override public boolean remove(final String key) throws StoreAccessException { this.checkFailingKey(key); if (this.entries.remove(key) == null) { return false; } return true; }
@Override public ValueHolder<String> computeAndGet( final String key, final BiFunction<? super String, ? super String, ? extends String> mappingFunction, final Supplier<Boolean> replaceEqual, Supplier<Boolean> invokeWriter) throws StoreAccessException { this.checkFailingKey(key); return this.computeInternal(key, this.entries.get(key), mappingFunction, replaceEqual); }
@Override public PutStatus put(final String key, final String value) throws StoreAccessException { this.checkFailingKey(key); FakeValueHolder toPut = new FakeValueHolder(value); this.entries.put(key, toPut); return PutStatus.PUT; }
@Override public ValueHolder<String> replace(final String key, final String value) throws StoreAccessException { this.checkFailingKey(key); final ValueHolder<String> currentValue = this.entries.get(key); if (currentValue != null) { this.entries.put(key, new FakeValueHolder(value)); } return currentValue; }
@Override public boolean containsKey(final String key) throws StoreAccessException { this.checkFailingKey(key); return this.entries.containsKey(key); }