@Override public void replaceAtHead(long key, Chain expect, Chain update) { try { onStoreProxy(serverStoreProxy -> { serverStoreProxy.replaceAtHead(key, expect, update); return null; }); } catch (TimeoutException e) { throw new RuntimeException(e); } }
@Override public Chain get(long key) throws TimeoutException { return onStoreProxy(serverStoreProxy -> serverStoreProxy.get(key)); }
@Override public void append(long key, ByteBuffer payLoad) throws TimeoutException { onStoreProxy(serverStoreProxy -> { serverStoreProxy.append(key, payLoad); return null; }); }
@Override public void clear() throws TimeoutException { onStoreProxy(serverStoreProxy -> { serverStoreProxy.clear(); return null; }); }
@Override public Chain lock(long hash) throws TimeoutException { return onStoreProxy(lockingServerStoreProxy -> lockingServerStoreProxy.lock(hash)); }
@Override public void unlock(long hash) throws TimeoutException { onStoreProxy(lockingServerStoreProxy -> { lockingServerStoreProxy.unlock(hash); return null; }); }
@Override public Chain getAndAppend(long key, ByteBuffer payLoad) throws TimeoutException { return onStoreProxy(serverStoreProxy -> serverStoreProxy.getAndAppend(key, payLoad)); }
private <T> T onStoreProxy(TimeoutExceptionFunction<LockingServerStoreProxy, T> function) throws TimeoutException { LockingServerStoreProxy storeProxy = proxy(); try { return function.apply(storeProxy); } catch (ServerStoreProxyException sspe) { if (sspe.getCause() instanceof ConnectionClosedException) { if (delegateRef.compareAndSet(storeProxy, new ReconnectInProgressProxy(storeProxy.getCacheId()))) { onReconnect.run(); } return onStoreProxy(function); } else { throw sspe; } } }
@Override public void replaceAtHead(long key, Chain expect, Chain update) { try { onStoreProxy((TimeoutExceptionFunction<ServerStoreProxy, Void>)serverStoreProxy -> { serverStoreProxy.replaceAtHead(key, expect, update); return null; }); } catch (TimeoutException e) { throw new RuntimeException(e); } }
@Override public void append(long key, ByteBuffer payLoad) throws TimeoutException { onStoreProxy((TimeoutExceptionFunction<ServerStoreProxy, Void>) serverStoreProxy -> { serverStoreProxy.append(key, payLoad); return null; }); }
@Override public void clear() throws TimeoutException { onStoreProxy((TimeoutExceptionFunction<ServerStoreProxy, Void>) serverStoreProxy -> { serverStoreProxy.clear(); return null; }); }
@Override public Chain getAndAppend(long key, ByteBuffer payLoad) throws TimeoutException { return onStoreProxy(serverStoreProxy -> serverStoreProxy.getAndAppend(key, payLoad)); }
@Override public Chain get(long key) throws TimeoutException { return onStoreProxy(serverStoreProxy -> serverStoreProxy.get(key)); }
private <T> T onStoreProxy(TimeoutExceptionFunction<ServerStoreProxy, T> function) throws TimeoutException { ServerStoreProxy storeProxy = proxy(); try { return function.apply(storeProxy); } catch (ServerStoreProxyException sspe) { if (sspe.getCause() instanceof ConnectionClosedException) { if (delegateRef.compareAndSet(storeProxy, new ReconnectInProgressProxy(storeProxy.getCacheId()))) { onReconnect.run(); } return onStoreProxy(function); } else { throw sspe; } } }