public InternalCacheEntry retrieveFromRemoteSource(Object key, InvocationContext ctx) throws Exception { ClusteredGetCommand get = cf.buildClusteredGetCommand(key, ctx.getFlags()); List<Address> targets = locate(key); targets.remove(getSelf()); ResponseFilter filter = new ClusteredGetResponseValidityFilter(targets); Map<Address, Response> responses = rpcManager.invokeRemotely( targets, get, ResponseMode.SYNCHRONOUS, configuration.getSyncReplTimeout(), false, filter); if (!responses.isEmpty()) { for (Response r : responses.values()) { if (r instanceof SuccessfulResponse) { InternalCacheValue cacheValue = (InternalCacheValue) ((SuccessfulResponse) r).getResponseValue(); return cacheValue.toInternalCacheEntry(key); } } } return null; }
private InternalCacheEntry unmarshall(Object o, Object key) throws IOException, ClassNotFoundException { if (o == null) return null; byte b[] = (byte[]) o; InternalCacheValue v = (InternalCacheValue) getMarshaller().objectFromByteBuffer(b); return v.toInternalCacheEntry(key); }
public InternalCacheEntry load(Object key) throws CacheLoaderException { if (!(isCacheReady() && isLocalCall())) return null; ClusteredGetCommand clusteredGetCommand = new ClusteredGetCommand(key, cache.getName()); Collection<Response> responses = doRemoteCall(clusteredGetCommand); if (responses.isEmpty()) return null; // Remove duplicates before deciding if multiple responses were received Set<Response> setResponses = new HashSet(responses); if (setResponses.size() > 1) throw new CacheLoaderException( String.format( "Responses contains more than 1 element and these elements are not equal, so can't decide which one to use: %s", setResponses)); for (Response r : setResponses) { if (r.isSuccessful() && r instanceof SuccessfulResponse) { InternalCacheValue value = (InternalCacheValue) ((SuccessfulResponse) r).getResponseValue(); return value.toInternalCacheEntry(key); } } String message = "Unknown responses from remote cache: " + responses; log.error(message); throw new CacheLoaderException(message); }