01: package ri.cache.transport;
02:
03: import javax.cache.spi.CacheLoaderException;
04: import javax.cache.spi.CacheLoader;
05:
06: import ri.cache.loader.AbstractCacheLoader;
07: import ri.cache.transport.events.CacheGetRequest;
08: import ri.cache.transport.events.CacheGetResponse;
09:
10: /**
11: * RemoteCacheLoader
12: *
13: * @author Brian Goetz
14: */
15: public class RemoteCacheLoader extends AbstractCacheLoader implements
16: CacheLoader {
17: private final TransportEndpoint remoteEndpoint;
18:
19: public RemoteCacheLoader(TransportEndpoint remoteEndpoint) {
20: this .remoteEndpoint = remoteEndpoint;
21: }
22:
23: public Object load(Object key) throws CacheLoaderException {
24: try {
25: CacheGetResponse resp = (CacheGetResponse) remoteEndpoint
26: .sendCacheRequest(new CacheGetRequest(key));
27: if (resp != null)
28: return resp.value;
29: else
30: return null;
31: } catch (TransportException e) {
32: throw new CacheLoaderException(
33: "Exception loading from remote cache", e);
34: }
35: }
36:
37: // Default implementation performance of loadAll will suck
38: }
|