@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); } }
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 close() { try { proxy().close(); } catch (ConnectionClosedException | ConnectionShutdownException e) { LOGGER.debug("Store was already closed, since connection was closed"); } }
ServerStoreProxy storeProxy = clusteringService.getServerStoreProxy(cacheIdentifier, storeConfig.getStoreConfig(), storeConfig.getConsistency(), getServerCallback(clusteredStore)); ReconnectingServerStoreProxy reconnectingServerStoreProxy = new ReconnectingServerStoreProxy(storeProxy, () -> { Runnable reconnectTask = () -> { connectLock.lock();
@Test public void testGetAndAppend() throws Exception { doThrow(storeProxyException).when(proxy).getAndAppend(anyLong(), any(ByteBuffer.class)); exception.expect(ReconnectInProgressException.class); serverStoreProxy.getAndAppend(0, ByteBuffer.allocate(2)); }
@Test public void testAppend() throws Exception { doThrow(storeProxyException).when(proxy).append(anyLong(), any(ByteBuffer.class)); exception.expect(ReconnectInProgressException.class); serverStoreProxy.append(0, ByteBuffer.allocate(2)); }
@Test public void testGet() throws Exception { doThrow(storeProxyException).when(proxy).get(anyLong()); exception.expect(ReconnectInProgressException.class); serverStoreProxy.get(0); }
@Override public String getCacheId() { return proxy().getCacheId(); }
ReconnectingServerStoreProxy reconnectingServerStoreProxy = new ReconnectingServerStoreProxy(storeProxy, () -> { Runnable reconnectTask = () -> { connectLock.lock();
@Override public void clear() throws TimeoutException { onStoreProxy(serverStoreProxy -> { serverStoreProxy.clear(); return null; }); }
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; } } }
@Override public void close() { try { proxy().close(); } catch (ConnectionClosedException | ConnectionShutdownException e) { LOGGER.debug("Store was already closed, since connection was closed"); } }
@Override public Chain get(long key) throws TimeoutException { return onStoreProxy(serverStoreProxy -> serverStoreProxy.get(key)); }
@Override public String getCacheId() { return proxy().getCacheId(); }
@Override public void unlock(long hash) throws TimeoutException { onStoreProxy(lockingServerStoreProxy -> { lockingServerStoreProxy.unlock(hash); return null; }); }
@Override public Chain lock(long hash) throws TimeoutException { return onStoreProxy(lockingServerStoreProxy -> lockingServerStoreProxy.lock(hash)); }
@Override public void append(long key, ByteBuffer payLoad) throws TimeoutException { onStoreProxy(serverStoreProxy -> { serverStoreProxy.append(key, payLoad); return null; }); }
@Override public Chain getAndAppend(long key, ByteBuffer payLoad) throws TimeoutException { return onStoreProxy(serverStoreProxy -> serverStoreProxy.getAndAppend(key, payLoad)); }
@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; }); }