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 unlock(long hash) throws TimeoutException { try { clientEntity.invokeAndWaitForComplete(new UnlockMessage(hash), false); locksHeld.remove(hash); } catch (TimeoutException tme) { throw tme; } catch (Exception e) { throw new ServerStoreProxyException(e); } } }
private LockSuccess getlockResponse(long hash) throws TimeoutException { EhcacheEntityResponse response; do { try { response = clientEntity.invokeAndWaitForComplete(new LockMessage(hash), false); } catch (TimeoutException tme) { throw tme; } catch (Exception e) { throw new ServerStoreProxyException(e); } if (response == null) { throw new ServerStoreProxyException("Response for acquiring lock was invalid null message"); } } while (response.getResponseType() == LOCK_FAILURE); return (LockSuccess) response; }
@Test public void testLockWhenException() throws Exception { ClusterTierClientEntity clusterTierClientEntity = mock(ClusterTierClientEntity.class); LockManagerImpl lockManager = new LockManagerImpl(clusterTierClientEntity); when(clusterTierClientEntity.invokeAndWaitForComplete(any(LockMessage.class), anyBoolean())) .thenThrow(new UnknownClusterException(""), new TimeoutException("timed out test")); try { lockManager.lock(2L); fail(); } catch (ServerStoreProxyException sspe) { assertThat(sspe.getCause(), instanceOf(UnknownClusterException.class)); } try { lockManager.lock(2L); fail(); } catch (TimeoutException e) { assertThat(e.getMessage(), is("timed out test")); } }
@Override public void append(long key, ByteBuffer payLoad) { try { entity.invokeAndWaitForReceive(new AppendMessage(key, payLoad), true); } catch (Exception e) { throw new ServerStoreProxyException(e); } }
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 replaceAtHead(long key, Chain expect, Chain update) { // TODO: Optimize this method to just send sequences for expect Chain try { entity.invokeAndWaitForSend(new ReplaceAtHeadMessage(key, expect, update), false); } catch (Exception e) { throw new ServerStoreProxyException(e); } }
@Override public void clear() throws TimeoutException { try { entity.invokeAndWaitForRetired(new ServerStoreOpMessage.ClearMessage(), true); } catch (TimeoutException e) { throw e; } catch (Exception e) { throw new ServerStoreProxyException(e); } } }
@Override public Chain getAndAppend(long key, ByteBuffer payLoad) throws TimeoutException { EhcacheEntityResponse response; try { response = entity.invokeAndWaitForRetired(new GetAndAppendMessage(key, payLoad), true); } catch (TimeoutException e) { throw e; } catch (Exception e) { throw new ServerStoreProxyException(e); } if (response != null && response.getResponseType() == EhcacheResponseType.GET_RESPONSE) { return ((EhcacheEntityResponse.GetResponse)response).getChain(); } else { throw new ServerStoreProxyException("Response for getAndAppend operation was invalid : " + (response != null ? response.getResponseType() : "null message")); } }
@Override public Chain get(long key) throws TimeoutException { EhcacheEntityResponse response; try { response = entity.invokeAndWaitForComplete(new GetMessage(key), false); } catch (TimeoutException e) { throw e; } catch (Exception e) { throw new ServerStoreProxyException(e); } if (response != null && response.getResponseType() == EhcacheResponseType.GET_RESPONSE) { return ((EhcacheEntityResponse.GetResponse)response).getChain(); } else { throw new ServerStoreProxyException("Response for get operation was invalid : " + (response != null ? response.getResponseType() : "null message")); } }
@Override public void clear() throws TimeoutException { try { entity.invokeAndWaitForRetired(new ServerStoreOpMessage.ClearMessage(), true); } catch (TimeoutException e) { throw e; } catch (Exception e) { throw new ServerStoreProxyException(e); } } }
@Override public void append(long key, ByteBuffer payLoad) { try { entity.invokeAndWaitForReceive(new AppendMessage(key, payLoad), true); } catch (Exception e) { throw new ServerStoreProxyException(e); } }
@Override public void replaceAtHead(long key, Chain expect, Chain update) { // TODO: Optimize this method to just send sequences for expect Chain try { entity.invokeAndWaitForSend(new ReplaceAtHeadMessage(key, expect, update), false); } catch (Exception e) { throw new ServerStoreProxyException(e); } }
@Override public Chain getAndAppend(long key, ByteBuffer payLoad) throws TimeoutException { EhcacheEntityResponse response; try { response = entity.invokeAndWaitForRetired(new GetAndAppendMessage(key, payLoad), true); } catch (TimeoutException e) { throw e; } catch (Exception e) { throw new ServerStoreProxyException(e); } if (response != null && response.getResponseType() == EhcacheResponseType.GET_RESPONSE) { return ((EhcacheEntityResponse.GetResponse)response).getChain(); } else { throw new ServerStoreProxyException("Response for getAndAppend operation was invalid : " + (response != null ? response.getResponseType() : "null message")); } }
@Override public Chain get(long key) throws TimeoutException { EhcacheEntityResponse response; try { response = entity.invokeAndWaitForComplete(new GetMessage(key), false); } catch (TimeoutException e) { throw e; } catch (Exception e) { throw new ServerStoreProxyException(e); } if (response != null && response.getResponseType() == EhcacheResponseType.GET_RESPONSE) { return ((EhcacheEntityResponse.GetResponse)response).getChain(); } else { throw new ServerStoreProxyException("Response for get operation was invalid : " + (response != null ? response.getResponseType() : "null message")); } }