/** * Gets multiple items from the cache matching the pattern. * <p> * @param cacheName * @param pattern * @param requesterId * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no * data in cache matching the pattern. * @throws IOException */ @Override public Map<K, ICacheElement<K, V>> getMatching( String cacheName, String pattern, long requesterId ) throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createGetMatchingRequest( cacheName, pattern, requesterId ); RemoteCacheResponse<Map<K, ICacheElement<K, V>>> remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); if ( log.isDebugEnabled() ) { log.debug( "GetMatching [" + pattern + "] = " + remoteHttpCacheResponse ); } return remoteHttpCacheResponse.getPayload(); }
/** * Gets multiple items from the cache based on the given set of keys. * <p> * @param cacheName * @param keys * @param requesterId * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no * data in cache for any of these keys * @throws IOException */ @Override public Map<K, ICacheElement<K, V>> getMultiple( String cacheName, Set<K> keys, long requesterId ) throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createGetMultipleRequest( cacheName, keys, requesterId ); RemoteCacheResponse<Map<K, ICacheElement<K, V>>> remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); if ( log.isDebugEnabled() ) { log.debug( "GetMultiple [" + keys + "] = " + remoteHttpCacheResponse ); } return remoteHttpCacheResponse.getPayload(); }
RemoteCacheRequestFactory.createGetRequest( cacheName, key, requesterId );
/** * Removes the given key from the specified cache. * <p> * @param cacheName * @param key * @param requesterId * @throws IOException */ @Override public void remove( String cacheName, K key, long requesterId ) throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createRemoveRequest( cacheName, key, requesterId ); getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); }
/** * Remove all keys from the sepcified cache. * <p> * @param cacheName * @param requesterId * @throws IOException */ @Override public void removeAll( String cacheName, long requesterId ) throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createRemoveAllRequest( cacheName, requesterId ); getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); }
/** * Puts a cache item to the cache. * <p> * @param cacheElement * @param requesterId * @throws IOException */ @Override public void update( ICacheElement<K, V> cacheElement, long requesterId ) throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createUpdateRequest( cacheElement, requesterId ); getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); }
/** * Frees the specified cache. * <p> * @param cacheName * @throws IOException */ @Override public void dispose( String cacheName ) throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createDisposeRequest( cacheName, 0 ); getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); }
/** * Return the keys in this cache. * <p> * @param cacheName the name of the cache * @see org.apache.commons.jcs.auxiliary.AuxiliaryCache#getKeySet() */ @Override public Set<K> getKeySet( String cacheName ) throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<String, String> remoteHttpCacheRequest = RemoteCacheRequestFactory.createGetKeySetRequest(cacheName, 0 ); RemoteCacheResponse<Set<K>> remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); if ( remoteHttpCacheResponse != null && remoteHttpCacheResponse.getPayload() != null ) { return remoteHttpCacheResponse.getPayload(); } return Collections.emptySet(); }
/** * Make and alive request. * <p> * @return true if we make a successful alive request. * @throws IOException */ @Override public boolean isAlive() throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createAliveCheckRequest( 0 ); RemoteCacheResponse<String> remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); if ( remoteHttpCacheResponse != null ) { return remoteHttpCacheResponse.isSuccess(); } return false; }
/** * Removes the given key from the specified cache. * <p> * @param cacheName * @param key * @param requesterId * @throws IOException */ @Override public void remove( String cacheName, K key, long requesterId ) throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createRemoveRequest( cacheName, key, requesterId ); getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); }
/** * Remove all keys from the sepcified cache. * <p> * @param cacheName * @param requesterId * @throws IOException */ @Override public void removeAll( String cacheName, long requesterId ) throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createRemoveAllRequest( cacheName, requesterId ); getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); }
/** * Puts a cache item to the cache. * <p> * @param cacheElement * @param requesterId * @throws IOException */ @Override public void update( ICacheElement<K, V> cacheElement, long requesterId ) throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createUpdateRequest( cacheElement, requesterId ); getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); }
/** * Frees the specified cache. * <p> * @param cacheName * @throws IOException */ @Override public void dispose( String cacheName ) throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createDisposeRequest( cacheName, 0 ); getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); }
/** * Return the keys in this cache. * <p> * @param cacheName the name of the cache * @see org.apache.commons.jcs.auxiliary.AuxiliaryCache#getKeySet() */ @Override public Set<K> getKeySet( String cacheName ) throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<String, String> remoteHttpCacheRequest = RemoteCacheRequestFactory.createGetKeySetRequest(cacheName, 0 ); RemoteCacheResponse<Set<K>> remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); if ( remoteHttpCacheResponse != null && remoteHttpCacheResponse.getPayload() != null ) { return remoteHttpCacheResponse.getPayload(); } return Collections.emptySet(); }
/** * Make and alive request. * <p> * @return true if we make a successful alive request. * @throws IOException */ @Override public boolean isAlive() throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createAliveCheckRequest( 0 ); RemoteCacheResponse<String> remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); if ( remoteHttpCacheResponse != null ) { return remoteHttpCacheResponse.isSuccess(); } return false; }
/** Verify that the service is called. */ public void testProcessRequest_Remove() { String cacheName = "test"; Serializable key = "key"; long requesterId = 2; RemoteCacheRequest<Serializable, Serializable> request = RemoteCacheRequestFactory.createRemoveRequest( cacheName, key, requesterId ); // DO WORK RemoteCacheResponse<Object> result = servlet.processRequest( request ); // VERIFY assertNotNull( "Should have a result.", result ); assertEquals( "Wrong key.", key, remoteHttpCacheService.lastRemoveKey ); }
/** Verify that the service is called. */ public void testProcessRequest_RemoveAll() { String cacheName = "testRemoveALl"; long requesterId = 2; RemoteCacheRequest<Serializable, Serializable> request = RemoteCacheRequestFactory.createRemoveAllRequest( cacheName, requesterId ); // DO WORK RemoteCacheResponse<Object> result = servlet.processRequest( request ); // VERIFY assertNotNull( "Should have a result.", result ); assertEquals( "Wrong cacheName.", cacheName, remoteHttpCacheService.lastRemoveAllCacheName ); } }
RemoteCacheRequestFactory.createGetRequest( cacheName, key, requesterId );
/** Verify that the service is called. */ public void testProcessRequest_Update() { String cacheName = "test"; String key = "key"; long requesterId = 2; CacheElement<Serializable, Serializable> element = new CacheElement<Serializable, Serializable>( cacheName, key, null ); RemoteCacheRequest<Serializable, Serializable> request = RemoteCacheRequestFactory.createUpdateRequest( element, requesterId ); // DO WORK RemoteCacheResponse<Object> result = servlet.processRequest( request ); // VERIFY assertNotNull( "Should have a result.", result ); assertEquals( "Wrong object.", element, remoteHttpCacheService.lastUpdate ); }
/** * Gets multiple items from the cache matching the pattern. * <p> * @param cacheName * @param pattern * @param requesterId * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no * data in cache matching the pattern. * @throws IOException */ @Override public Map<K, ICacheElement<K, V>> getMatching( String cacheName, String pattern, long requesterId ) throws IOException { if ( !isInitialized() ) { String message = "The Remote Http Client is not initialized. Cannot process request."; log.warn( message ); throw new IOException( message ); } RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createGetMatchingRequest( cacheName, pattern, requesterId ); RemoteCacheResponse<Map<K, ICacheElement<K, V>>> remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); if ( log.isDebugEnabled() ) { log.debug( "GetMatching [" + pattern + "] = " + remoteHttpCacheResponse ); } return remoteHttpCacheResponse.getPayload(); }