@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); } } }
requireNonNull(invalidation, "ServerCallback must be non-null"); entity.addDisconnectionListener(invalidation::onInvalidateAll); entity.addResponseListener(ServerInvalidateHash.class, response -> { long key = response.getKey(); LOGGER.debug("CLIENT: on cache {}, server requesting hash {} to be invalidated", cacheId, key); invalidation.onInvalidateHash(key); }); entity.addResponseListener(ClientInvalidateHash.class, response -> { long key = response.getKey(); int invalidationId = response.getInvalidationId(); entity.invokeAndWaitForSend(new ClientInvalidationAck(key, invalidationId), false); } catch (Exception e) { entity.addResponseListener(ClientInvalidateAll.class, response -> { int invalidationId = response.getInvalidationId(); entity.invokeAndWaitForSend(new ClientInvalidationAllAck(invalidationId), false); } catch (Exception e) { entity.addResponseListener(EhcacheEntityResponse.ResolveRequest.class, response -> { Chain incoming = response.getChain(); Chain compacted = invalidation.compact(incoming, response.getKey());
@SuppressWarnings("unchecked") @Override public void close() { entity.close(); }
public StrongServerStoreProxy(final String cacheId, final ClusterTierClientEntity entity, final ServerCallback invalidation) { this.delegate = new CommonServerStoreProxy(cacheId, entity, invalidation); this.entity = entity; delegate.addResponseListener(EhcacheEntityResponse.HashInvalidationDone.class, this::hashInvalidationDoneResponseListener); delegate.addResponseListener(EhcacheEntityResponse.AllInvalidationDone.class, this::allInvalidationDoneResponseListener); entity.addReconnectListener(this::reconnectListener); entity.addDisconnectionListener(this::disconnectionListener); }
storeClientEntity.validate(clientStoreConfiguration); } catch (ClusterTierException e) { serverStoreProxy.close();
@Override public void clear() throws TimeoutException { performWaitingForAllInvalidation(() -> { delegate.clear(); return null; }, entity.getTimeouts().getWriteOperationTimeout()); } }
@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); } } }
public StrongServerStoreProxy(final String cacheId, final ClusterTierClientEntity entity, final ServerCallback invalidation) { this.delegate = new CommonServerStoreProxy(cacheId, entity, invalidation); this.entity = entity; delegate.addResponseListener(EhcacheEntityResponse.HashInvalidationDone.class, this::hashInvalidationDoneResponseListener); delegate.addResponseListener(EhcacheEntityResponse.AllInvalidationDone.class, this::allInvalidationDoneResponseListener); entity.setReconnectListener(this::reconnectListener); entity.addDisconnectionListener(this::disconnectionListener); }
@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 append(long key, ByteBuffer payLoad) { try { entity.invokeAndWaitForReceive(new AppendMessage(key, payLoad), true); } catch (Exception e) { throw new ServerStoreProxyException(e); } }
private Object getResponse(StateRepositoryOpMessage message, boolean track) { try { EhcacheEntityResponse response = entity.invokeStateRepositoryOperation(message, track); return ((EhcacheEntityResponse.MapValue)response).getValue(); } catch (ClusterException | TimeoutException ce) { throw new ClusteredMapException(ce); } }
<T extends EhcacheEntityResponse> void addResponseListener(Class<T> listenerClass, SimpleClusterTierClientEntity.ResponseListener<T> listener) { entity.addResponseListener(listenerClass, listener); }
@Before public void setup() throws Exception { UnitTestConnectionService.add( CLUSTER_URI, new UnitTestConnectionService.PassthroughServerBuilder().resource("defaultResource", 8, MemoryUnit.MB).build() ); Connection connection = new UnitTestConnectionService().connect(CLUSTER_URI, new Properties()); ClusterTierManagerClientEntityFactory entityFactory = new ClusterTierManagerClientEntityFactory(connection); ServerSideConfiguration serverConfig = new ServerSideConfiguration("defaultResource", Collections.emptyMap()); entityFactory.create("TestCacheManager", serverConfig); ClusteredResourcePool resourcePool = ClusteredResourcePoolBuilder.clusteredDedicated(4, MemoryUnit.MB); ServerStoreConfiguration serverStoreConfiguration = new ServerStoreConfiguration(resourcePool.getPoolAllocation(), Long.class.getName(), String.class.getName(), LongSerializer.class.getName(), StringSerializer.class.getName(), null, false); ClusterTierClientEntity clientEntity = entityFactory.fetchOrCreateClusteredStoreEntity("TestCacheManager", CACHE_IDENTIFIER, serverStoreConfiguration, true); clientEntity.validate(serverStoreConfiguration); ServerStoreProxy serverStoreProxy = new CommonServerStoreProxy(CACHE_IDENTIFIER, clientEntity, mock(ServerCallback.class)); TestTimeSource testTimeSource = new TestTimeSource(); OperationsCodec<Long, String> codec = new OperationsCodec<>(new LongSerializer(), new StringSerializer()); EternalChainResolver<Long, String> resolver = new EternalChainResolver<>(codec); store = new ClusteredStore<>(config, codec, resolver, serverStoreProxy, testTimeSource); }
@Override public void append(final long key, final ByteBuffer payLoad) throws TimeoutException { performWaitingForHashInvalidation(key, () -> { delegate.append(key, payLoad); return null; }, entity.getTimeouts().getWriteOperationTimeout()); }
@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 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 append(long key, ByteBuffer payLoad) { try { entity.invokeAndWaitForReceive(new AppendMessage(key, payLoad), true); } catch (Exception e) { throw new ServerStoreProxyException(e); } }
private Object getResponse(StateRepositoryOpMessage message, boolean track) { try { EhcacheEntityResponse response = entity.invokeStateRepositoryOperation(message, track); return ((EhcacheEntityResponse.MapValue)response).getValue(); } catch (ClusterException | TimeoutException ce) { throw new ClusteredMapException(ce); } }
<T extends EhcacheEntityResponse> void addResponseListener(Class<T> listenerClass, SimpleClusterTierClientEntity.ResponseListener<T> listener) { entity.addResponseListener(listenerClass, listener); }
requireNonNull(invalidation, "ServerCallback must be non-null"); entity.addDisconnectionListener(invalidation::onInvalidateAll); entity.addResponseListener(ServerInvalidateHash.class, response -> { long key = response.getKey(); LOGGER.debug("CLIENT: on cache {}, server requesting hash {} to be invalidated", cacheId, key); invalidation.onInvalidateHash(key); }); entity.addResponseListener(ClientInvalidateHash.class, response -> { long key = response.getKey(); int invalidationId = response.getInvalidationId(); entity.invokeAndWaitForSend(new ClientInvalidationAck(key, invalidationId), false); } catch (Exception e) { entity.addResponseListener(ClientInvalidateAll.class, response -> { int invalidationId = response.getInvalidationId(); entity.invokeAndWaitForSend(new ClientInvalidationAllAck(invalidationId), false); } catch (Exception e) { entity.addResponseListener(EhcacheEntityResponse.ResolveRequest.class, response -> { Chain incoming = response.getChain(); Chain compacted = invalidation.compact(incoming);