/** * Returns a remote cache for the given cache name. * <p> * @param cacheName * @return The cache value */ // @Override public <K, V> RemoteCacheNoWait<K, V> getCache( String cacheName ) { // TODO get some defaults! // Perhaps we will need a manager per URL???? RemoteHttpCacheAttributes ca = new RemoteHttpCacheAttributes(); ca.setCacheName( cacheName ); return getCache( ca ); }
/** * This is an extension point. The manager and other classes will only create * RemoteHttpCacheClient through this method. * @param cattr the cache configuration * @return the client instance */ protected <V, K> IRemoteHttpCacheClient<K, V> createRemoteHttpCacheClientForAttributes(RemoteHttpCacheAttributes cattr) { IRemoteHttpCacheClient<K, V> remoteService = OptionConverter.instantiateByClassName( cattr .getRemoteHttpClientClassName(), null ); if ( remoteService == null ) { if ( log.isInfoEnabled() ) { log.info( "Creating the default client for " + cattr.getCacheName()); } remoteService = new RemoteHttpCacheClient<K, V>( ); } remoteService.initialize( cattr ); return remoteService; }
/** * @return String details */ @Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append( "\n RemoteHttpCacheAttributes" ); buf.append( "\n maxConnectionsPerHost = [" + getMaxConnectionsPerHost() + "]" ); buf.append( "\n socketTimeoutMillis = [" + getSocketTimeoutMillis() + "]" ); buf.append( "\n httpVersion = [" + getHttpVersion() + "]" ); buf.append( "\n connectionTimeoutMillis = [" + getConnectionTimeoutMillis() + "]" ); buf.append( "\n includeCacheNameAsParameter = [" + isIncludeCacheNameAsParameter() + "]" ); buf.append( "\n includeKeysAndPatternsAsParameter = [" + isIncludeKeysAndPatternsAsParameter() + "]" ); buf.append( "\n includeRequestTypeasAsParameter = [" + isIncludeRequestTypeasAsParameter() + "]" ); buf.append( "\n url = [" + getUrl() + "]" ); buf.append( "\n remoteHttpClientClassName = [" + getRemoteHttpClientClassName() + "]" ); buf.append( super.toString() ); return buf.toString(); } }
/** Verify that we get the default. */ public void testCreateRemoteHttpCacheClient_default() { // SETUP RemoteHttpCacheAttributes cattr = new RemoteHttpCacheAttributes(); RemoteHttpCacheFactory factory = new RemoteHttpCacheFactory(); // DO WORK IRemoteHttpCacheClient<String, String> result = factory.createRemoteHttpCacheClientForAttributes( cattr ); // VEIFY assertNotNull( "Should have a cache.", result ); assertTrue( "Wrong default.", result instanceof RemoteHttpCacheClient ); }
if ( getRemoteHttpCacheAttributes().getMaxConnectionsPerHost() > 0 ) .setMaxTotalConnections(getRemoteHttpCacheAttributes().getMaxConnectionsPerHost()); this.connectionManager.getParams() .setDefaultMaxConnectionsPerHost(getRemoteHttpCacheAttributes().getMaxConnectionsPerHost()); this.connectionManager.getParams().setSoTimeout( getRemoteHttpCacheAttributes().getSocketTimeoutMillis() ); String httpVersion = getRemoteHttpCacheAttributes().getHttpVersion(); if ( httpVersion != null ) .setConnectionTimeout(getRemoteHttpCacheAttributes().getConnectionTimeoutMillis());
if ( getRemoteHttpCacheAttributes().isIncludeCacheNameAsParameter() ) if ( getRemoteHttpCacheAttributes().isIncludeKeysAndPatternsAsParameter() ) url.append( "&" + PARAMETER_KEY + "=" + encodedKeyValue ); if ( getRemoteHttpCacheAttributes().isIncludeRequestTypeasAsParameter() )
/** Verify that we get the default. */ public void testCreateRemoteHttpCacheClient_Bad() { // SETUP String remoteHttpClientClassName = "junk"; RemoteHttpCacheAttributes cattr = new RemoteHttpCacheAttributes(); cattr.setRemoteHttpClientClassName( remoteHttpClientClassName ); RemoteHttpCacheFactory factory = new RemoteHttpCacheFactory(); // DO WORK IRemoteHttpCacheClient<String, String> result = factory.createRemoteHttpCacheClientForAttributes( cattr ); // VEIFY assertNotNull( "Should have a cache.", result ); assertTrue( "Wrong default.", result instanceof RemoteHttpCacheClient ); assertTrue( "Should be initialized", ((RemoteHttpCacheClient<String, String>)result).isInitialized() ); }
rca.setRemoteType( RemoteType.LOCAL ); ICache<K, V> ic = rcm.getCache( rca ); noWaits.add( ic ); new RemoteCacheNoWaitFacade<K, V>(rcnwArray, rca, cacheMgr, cacheEventLogger, elementSerializer ); getFacades().put( rca.getCacheName(), rcnwf );
RemoteCacheNoWait<K, V> remoteCacheNoWait2 = (RemoteCacheNoWait<K, V>) caches.get( cattr.getCacheName() + cattr.getUrl() ); remoteCacheNoWait = remoteCacheNoWait2; if ( remoteCacheNoWait == null ) remoteCacheNoWait.setElementSerializer( elementSerializer ); caches.put( cattr.getCacheName() + cattr.getUrl(), remoteCacheNoWait );
String url = addParameters( remoteCacheRequest, getRemoteHttpCacheAttributes().getUrl() );
/** * This is an extension point. The manager and other classes will only create * RemoteHttpCacheClient through this method. * <p> * @param cattr * @return IRemoteHttpCacheClient */ protected <K, V> IRemoteHttpCacheClient<K, V> createRemoteHttpCacheClientForAttributes( RemoteHttpCacheAttributes cattr ) { IRemoteHttpCacheClient<K, V> client = OptionConverter.instantiateByClassName( cattr .getRemoteHttpClientClassName(), null ); if ( client == null ) { if ( log.isInfoEnabled() ) { log.info( "Creating the default client." ); } client = new RemoteHttpCacheClient<K, V>( ); } client.initialize( cattr ); return client; }
/** Verify that we get a cache no wait. */ public void testGetCache_normal() { // SETUP ICompositeCacheManager cacheMgr = new MockCompositeCacheManager(); ICacheEventLogger cacheEventLogger = null; IElementSerializer elementSerializer = null; RemoteHttpCacheAttributes cattr = new RemoteHttpCacheAttributes(); RemoteHttpCacheFactory factory = new RemoteHttpCacheFactory(); // DO WORK AuxiliaryCache<String, String> result = factory.createCache(cattr, cacheMgr, cacheEventLogger, elementSerializer); // VEIFY assertNotNull( "Should have a cache.", result ); } }
if ( getRemoteHttpCacheAttributes().getMaxConnectionsPerHost() > 0 ) .getMaxConnectionsPerHost() ); getConnectionManager().getParams().setSoTimeout( getRemoteHttpCacheAttributes().getSocketTimeoutMillis() ); String httpVersion = getRemoteHttpCacheAttributes().getHttpVersion(); if ( httpVersion != null ) .getConnectionTimeoutMillis() );
if ( getRemoteHttpCacheAttributes().isIncludeCacheNameAsParameter() ) if ( getRemoteHttpCacheAttributes().isIncludeKeysAndPatternsAsParameter() ) url.append( "&" + PARAMETER_KEY + "=" + encodedKeyValue ); if ( getRemoteHttpCacheAttributes().isIncludeRequestTypeasAsParameter() )
/** Verify that we get the default. */ public void testCreateRemoteHttpCacheClient_Bad() { // SETUP ICompositeCacheManager cacheMgr = new MockCompositeCacheManager(); ICacheEventLogger cacheEventLogger = null; IElementSerializer elementSerializer = null; String remoteHttpClientClassName = "junk"; RemoteHttpCacheAttributes cattr = new RemoteHttpCacheAttributes(); cattr.setRemoteHttpClientClassName( remoteHttpClientClassName ); RemoteHttpCacheManager manager = RemoteHttpCacheManager.getInstance( cacheMgr, cacheEventLogger, elementSerializer ); // DO WORK IRemoteHttpCacheClient<String, String> result = manager.createRemoteHttpCacheClientForAttributes( cattr ); // VEIFY assertNotNull( "Should have a cache.", result ); assertTrue( "Wrong default.", result instanceof RemoteHttpCacheClient ); assertTrue( "Should be initialized", ((RemoteHttpCacheClient<String, String>)result).isInitialized() ); }
String url = addParameters( remoteCacheRequest, getRemoteHttpCacheAttributes().getUrl() );
/** * @return String details */ @Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append( "\n RemoteHttpCacheAttributes" ); buf.append( "\n maxConnectionsPerHost = [" + getMaxConnectionsPerHost() + "]" ); buf.append( "\n socketTimeoutMillis = [" + getSocketTimeoutMillis() + "]" ); buf.append( "\n httpVersion = [" + getHttpVersion() + "]" ); buf.append( "\n connectionTimeoutMillis = [" + getConnectionTimeoutMillis() + "]" ); buf.append( "\n includeCacheNameAsParameter = [" + isIncludeCacheNameAsParameter() + "]" ); buf.append( "\n includeKeysAndPatternsAsParameter = [" + isIncludeKeysAndPatternsAsParameter() + "]" ); buf.append( "\n includeRequestTypeasAsParameter = [" + isIncludeRequestTypeasAsParameter() + "]" ); buf.append( "\n url = [" + getUrl() + "]" ); buf.append( "\n remoteHttpClientClassName = [" + getRemoteHttpClientClassName() + "]" ); buf.append( super.toString() ); return buf.toString(); } }
/** Verify that we get a cache no wait. */ public void testGetCache_normal() { // SETUP ICompositeCacheManager cacheMgr = new MockCompositeCacheManager(); ICacheEventLogger cacheEventLogger = null; IElementSerializer elementSerializer = null; RemoteHttpCacheAttributes cattr = new RemoteHttpCacheAttributes(); RemoteHttpCacheManager manager = RemoteHttpCacheManager.getInstance( cacheMgr, cacheEventLogger, elementSerializer ); // DO WORK AuxiliaryCache<String, String> result = manager.getCache( cattr ); // VEIFY assertNotNull( "Should have a cache.", result ); } }
/** Verify that we get the default. */ public void testCreateRemoteHttpCacheClient_deafult() { // SETUP ICompositeCacheManager cacheMgr = new MockCompositeCacheManager(); ICacheEventLogger cacheEventLogger = null; IElementSerializer elementSerializer = null; RemoteHttpCacheAttributes cattr = new RemoteHttpCacheAttributes(); RemoteHttpCacheManager manager = RemoteHttpCacheManager.getInstance( cacheMgr, cacheEventLogger, elementSerializer ); // DO WORK IRemoteHttpCacheClient<String, String> result = manager.createRemoteHttpCacheClientForAttributes( cattr ); // VEIFY assertNotNull( "Should have a cache.", result ); assertTrue( "Wrong default.", result instanceof RemoteHttpCacheClient ); }
/** * Verify get functionality * <p> * @throws IOException */ public void testGetMultiple_normal() throws IOException { // SETUP RemoteHttpCacheAttributes attributes = new RemoteHttpCacheAttributes(); RemoteHttpCacheClient<String, String> client = new RemoteHttpCacheClient<String, String>( attributes ); MockRemoteCacheDispatcher mockDispatcher = new MockRemoteCacheDispatcher(); client.setRemoteDispatcher( mockDispatcher ); String cacheName = "test"; Set<String> keys = Collections.emptySet(); ICacheElement<String, String> expected = new CacheElement<String, String>( cacheName, "key", "value" ); Map<String, ICacheElement<String, String>> expectedMap = new HashMap<String, ICacheElement<String,String>>(); expectedMap.put( "key", expected ); RemoteCacheResponse<Map<String, ICacheElement<String, String>>> remoteHttpCacheResponse = new RemoteCacheResponse<Map<String,ICacheElement<String,String>>>(); remoteHttpCacheResponse.setPayload( expectedMap ); mockDispatcher.setupRemoteCacheResponse = remoteHttpCacheResponse; // DO WORK Map<String, ICacheElement<String, String>> result = client.getMultiple( cacheName, keys ); // VERIFY assertEquals( "Wrong result.", expected, result.get( "key" ) ); assertEquals( "Wrong type.", RemoteRequestType.GET_MULTIPLE, mockDispatcher.lastRemoteCacheRequest.getRequestType() ); }