Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java Mon Apr 6 13:54:48 2015 @@ -28,7 +28,6 @@ import org.apache.commons.logging.LogFac import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; @@ -42,16 +41,8 @@ public class LateralTCPSender private static final Log log = LogFactory.getLog( LateralTCPSender.class ); /** Config */ - private ITCPLateralCacheAttributes tcpLateralCacheAttributes; - - /** The hostname of the remote server. */ - private String remoteHost; - - /** The address of the server */ - private InetAddress address; - - /** The port the server is listening to. */ - private int port = 1111; + private int socketOpenTimeOut; + private int socketSoTimeOut; /** The stream from the server connection. */ private ObjectOutputStream oos; @@ -74,26 +65,29 @@ public class LateralTCPSender public LateralTCPSender( ITCPLateralCacheAttributes lca ) throws IOException { - this.setTcpLateralCacheAttributes( lca ); + this.socketOpenTimeOut = lca.getOpenTimeOut(); + this.socketSoTimeOut = lca.getSocketTimeOut(); String p1 = lca.getTcpServer(); - if ( p1 != null ) + if ( p1 == null ) { - String h2 = p1.substring( 0, p1.indexOf( ":" ) ); - int po = Integer.parseInt( p1.substring( p1.indexOf( ":" ) + 1 ) ); - if ( log.isDebugEnabled() ) - { - log.debug( "h2 = " + h2 ); - log.debug( "po = " + po ); - } + throw new IOException( "Invalid server (null)" ); + } - if ( h2.length() == 0 ) - { - throw new IOException( "Cannot connect to invalid address [" + h2 + ":" + po + "]" ); - } + String h2 = p1.substring( 0, p1.indexOf( ":" ) ); + int po = Integer.parseInt( p1.substring( p1.indexOf( ":" ) + 1 ) ); + if ( log.isDebugEnabled() ) + { + log.debug( "h2 = " + h2 ); + log.debug( "po = " + po ); + } - init( h2, po ); + if ( h2.length() == 0 ) + { + throw new IOException( "Cannot connect to invalid address [" + h2 + ":" + po + "]" ); } + + init( h2, po ); } /** @@ -106,22 +100,18 @@ public class LateralTCPSender protected void init( String host, int port ) throws IOException { - this.port = port; - this.address = getAddressByName( host ); - this.setRemoteHost( host ); - try { if ( log.isInfoEnabled() ) { - log.info( "Attempting connection to [" + address.getHostName() + "]" ); + log.info( "Attempting connection to [" + host + "]" ); } // have time out socket open do this for us try { socket = new Socket(); - socket.connect( new InetSocketAddress( host, port ), tcpLateralCacheAttributes.getOpenTimeOut() ); + socket.connect( new InetSocketAddress( host, port ), this.socketOpenTimeOut ); } catch ( IOException ioe ) { @@ -133,7 +123,7 @@ public class LateralTCPSender throw new IOException( "Cannot connect to " + host + ":" + port, ioe ); } - socket.setSoTimeout( tcpLateralCacheAttributes.getSocketTimeOut() ); + socket.setSoTimeout( socketSoTimeOut ); synchronized ( this ) { oos = new ObjectOutputStream( socket.getOutputStream() ); @@ -141,38 +131,17 @@ public class LateralTCPSender } catch ( java.net.ConnectException e ) { - log.debug( "Remote host [" + address.getHostName() + "] refused connection." ); + log.debug( "Remote host [" + host + "] refused connection." ); throw e; } catch ( IOException e ) { - log.debug( "Could not connect to [" + address.getHostName() + "]. Exception is " + e ); + log.debug( "Could not connect to [" + host + "]. Exception is " + e ); throw e; } } /** - * Gets the addressByName attribute of the LateralTCPSender object. - * <p> - * @param host - * @return The addressByName value - * @throws IOException - */ - private InetAddress getAddressByName( String host ) - throws IOException - { - try - { - return InetAddress.getByName( host ); - } - catch ( Exception e ) - { - log.error( "Could not find address of [" + host + "] ", e ); - throw new IOException( "Could not find address of [" + host + "] " + e.getMessage() ); - } - } - - /** * Sends commands to the lateral cache listener. * <p> * @param led @@ -182,12 +151,9 @@ public class LateralTCPSender throws IOException { sendCnt++; - if ( log.isInfoEnabled() ) + if ( log.isInfoEnabled() && sendCnt % 100 == 0 ) { - if ( sendCnt % 100 == 0 ) - { - log.info( "Send Count (port " + port + ") = " + sendCnt ); - } + log.info( "Send Count (port " + socket.getPort() + ") = " + sendCnt ); } if ( log.isDebugEnabled() ) @@ -200,27 +166,15 @@ public class LateralTCPSender return; } - if ( address == null ) + if ( oos == null ) { - throw new IOException( "No remote host is set for LateralTCPSender." ); + throw new IOException( "No remote connection is available for LateralTCPSender." ); } - if ( oos != null ) + synchronized ( this.getLock ) { - synchronized ( this.getLock ) - { - try - { - oos.writeUnshared( led ); - oos.flush(); - } - catch ( IOException e ) - { - oos = null; - log.error( "Detected problem with connection: " + e ); - throw e; - } - } + oos.writeUnshared( led ); + oos.flush(); } } @@ -242,69 +196,56 @@ public class LateralTCPSender return null; } - if ( address == null ) + if ( oos == null ) { - throw new IOException( "No remote host is set for LateralTCPSender." ); + throw new IOException( "No remote connection is available for LateralTCPSender." ); } Object response = null; - if ( oos != null ) + // Synchronized to insure that the get requests to server from this + // sender and the responses are processed in order, else you could + // return the wrong item from the cache. + // This is a big block of code. May need to re-think this strategy. + // This may not be necessary. + // Normal puts, etc to laterals do not have to be synchronized. + synchronized ( this.getLock ) { - // Synchronized to insure that the get requests to server from this - // sender and the responses are processed in order, else you could - // return the wrong item from the cache. - // This is a big block of code. May need to re-think this strategy. - // This may not be necessary. - // Normal puts, etc to laterals do not have to be synchronized. - synchronized ( this.getLock ) + try { - try - { - try - { - // clean up input stream, nothing should be there yet. - if ( socket.getInputStream().available() > 0 ) - { - socket.getInputStream().read( new byte[socket.getInputStream().available()] ); - } - } - catch ( IOException ioe ) - { - log.error( "Problem cleaning socket before send " + socket, ioe ); - throw ioe; - } - - // write object to listener - oos.writeUnshared( led ); - oos.flush(); - - try - { - // TODO make configurable - // socket.setSoTimeout( 2000 ); - ObjectInputStream ois = new ObjectInputStreamClassLoaderAware( socket.getInputStream(), null ); - response = ois.readObject(); - } - catch ( IOException ioe ) - { - String message = "Could not open ObjectInputStream to " + socket; - message += " SoTimeout [" + socket.getSoTimeout() + "] Connected [" + socket.isConnected() + "]"; - log.error( message, ioe ); - throw ioe; - } - catch ( Exception e ) - { - log.error( e ); - } - } - catch ( IOException e ) + // clean up input stream, nothing should be there yet. + if ( socket.getInputStream().available() > 0 ) { - oos = null; - log.error( "Detected problem with connection: " + e ); - throw e; + socket.getInputStream().read( new byte[socket.getInputStream().available()] ); } } + catch ( IOException ioe ) + { + log.error( "Problem cleaning socket before send " + socket, ioe ); + throw ioe; + } + + // write object to listener + oos.writeUnshared( led ); + oos.flush(); + + try + { + socket.setSoTimeout( socketSoTimeOut ); + ObjectInputStream ois = new ObjectInputStreamClassLoaderAware( socket.getInputStream(), null ); + response = ois.readObject(); + } + catch ( IOException ioe ) + { + String message = "Could not open ObjectInputStream to " + socket; + message += " SoTimeout [" + socket.getSoTimeout() + "] Connected [" + socket.isConnected() + "]"; + log.error( message, ioe ); + throw ioe; + } + catch ( Exception e ) + { + log.error( e ); + } } return response; @@ -315,49 +256,17 @@ public class LateralTCPSender * should come into the facade and be sent to all lateral cache services. The lateral cache * service will then call this method. * <p> - * @param cache * @throws IOException */ - public void dispose( String cache ) + public void dispose() throws IOException { if ( log.isInfoEnabled() ) { - log.info( "Dispose called for cache [" + cache + "]" ); + log.info( "Dispose called" ); } // WILL CLOSE CONNECTION USED BY ALL oos.close(); - } - - /** - * @param tcpLateralCacheAttributes The tcpLateralCacheAttributes to set. - */ - public void setTcpLateralCacheAttributes( ITCPLateralCacheAttributes tcpLateralCacheAttributes ) - { - this.tcpLateralCacheAttributes = tcpLateralCacheAttributes; - } - - /** - * @return Returns the tcpLateralCacheAttributes. - */ - public ITCPLateralCacheAttributes getTcpLateralCacheAttributes() - { - return tcpLateralCacheAttributes; - } - - /** - * @param remoteHost The remoteHost to set. - */ - public void setRemoteHost( String remoteHost ) - { - this.remoteHost = remoteHost; - } - - /** - * @return Returns the remoteHost. - */ - public String getRemoteHost() - { - return remoteHost; + socket.close(); } }
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java Mon Apr 6 13:54:48 2015 @@ -21,12 +21,10 @@ package org.apache.commons.jcs.auxiliary import org.apache.commons.jcs.auxiliary.lateral.LateralCommand; import org.apache.commons.jcs.auxiliary.lateral.LateralElementDescriptor; -import org.apache.commons.jcs.auxiliary.lateral.behavior.ILateralCacheObserver; import org.apache.commons.jcs.auxiliary.lateral.socket.tcp.behavior.ITCPLateralCacheAttributes; import org.apache.commons.jcs.engine.CacheElement; import org.apache.commons.jcs.engine.CacheInfo; import org.apache.commons.jcs.engine.behavior.ICacheElement; -import org.apache.commons.jcs.engine.behavior.ICacheListener; import org.apache.commons.jcs.engine.behavior.ICacheServiceNonLocal; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -34,7 +32,6 @@ import org.apache.commons.logging.LogFac import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.io.Serializable; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -42,15 +39,18 @@ import java.util.Set; /** * A lateral cache service implementation. Does not implement getGroupKey + * TODO: Remove generics */ public class LateralTCPService<K, V> - implements ICacheServiceNonLocal<K, V>, ILateralCacheObserver + implements ICacheServiceNonLocal<K, V> { /** The logger. */ private static final Log log = LogFactory.getLog( LateralTCPService.class ); /** special configuration */ - private ITCPLateralCacheAttributes tcpLateralCacheAttributes; + private boolean allowPut; + private boolean allowGet; + private boolean issueRemoveOnPut; /** Sends to another lateral. */ private LateralTCPSender sender; @@ -67,11 +67,12 @@ public class LateralTCPService<K, V> public LateralTCPService( ITCPLateralCacheAttributes lca ) throws IOException { - this.setTcpLateralCacheAttributes( lca ); + this.allowGet = lca.isAllowGet(); + this.allowPut = lca.isAllowPut(); + this.issueRemoveOnPut = lca.isIssueRemoveOnPut(); + try { - log.debug( "creating sender, attributes = " + getTcpLateralCacheAttributes() ); - sender = new LateralTCPSender( lca ); if ( log.isInfoEnabled() ) @@ -114,17 +115,15 @@ public class LateralTCPService<K, V> throws IOException { // if we don't allow put, see if we should remove on put - if ( !this.getTcpLateralCacheAttributes().isAllowPut() ) - { + if ( !this.allowPut && // if we can't remove on put, and we can't put then return - if ( !this.getTcpLateralCacheAttributes().isIssueRemoveOnPut() ) - { - return; - } + !this.issueRemoveOnPut ) + { + return; } // if we shouldn't remove on put, then put - if ( !this.getTcpLateralCacheAttributes().isIssueRemoveOnPut() ) + if ( !this.issueRemoveOnPut ) { LateralElementDescriptor<K, V> led = new LateralElementDescriptor<K, V>( item ); led.requesterId = requesterId; @@ -201,27 +200,7 @@ public class LateralTCPService<K, V> public void dispose( String cacheName ) throws IOException { - sender.dispose( cacheName ); - } - - /** - * The service does not get via this method, so this return null. - * <p> - * @param key - * @return always null. - * @throws IOException - */ - public Serializable get( String key ) - throws IOException - { - if ( log.isDebugEnabled() ) - { - log.debug( "balking at get for key [" + key + "]" ); - } - // p( "junk get" ); - // return get( cattr.cacheName, key, true ); - return null; - // nothing needs to be done + sender.dispose(); } /** @@ -251,7 +230,7 @@ public class LateralTCPService<K, V> throws IOException { // if get is not allowed return - if ( this.getTcpLateralCacheAttributes().isAllowGet() ) + if ( this.allowGet ) { CacheElement<K, V> ce = new CacheElement<K, V>( cacheName, key, null ); LateralElementDescriptor<K, V> led = new LateralElementDescriptor<K, V>( ce ); @@ -304,7 +283,7 @@ public class LateralTCPService<K, V> throws IOException { // if get is not allowed return - if ( this.getTcpLateralCacheAttributes().isAllowGet() ) + if ( this.allowGet ) { CacheElement<String, String> ce = new CacheElement<String, String>( cacheName, pattern, null ); LateralElementDescriptor<String, String> led = new LateralElementDescriptor<String, String>( ce ); @@ -441,7 +420,7 @@ public class LateralTCPService<K, V> while ( notDone ) { - System.out.println( "enter mesage:" ); + System.out.println( "enter message:" ); message = br.readLine(); if (message == null) @@ -461,56 +440,6 @@ public class LateralTCPService<K, V> } } - // ILateralCacheObserver methods, do nothing here since - // the connection is not registered, the udp service is - // is not registered. - - /** - * @param cacheName - * @param obj - * @throws IOException - */ - @Override - public <KK, VV> void addCacheListener( String cacheName, ICacheListener<KK, VV> obj ) - throws IOException - { - // Empty - } - - /** - * @param obj - * @throws IOException - */ - @Override - public <KK, VV> void addCacheListener( ICacheListener<KK, VV> obj ) - throws IOException - { - // Empty - } - - /** - * @param cacheName - * @param obj - * @throws IOException - */ - @Override - public <KK, VV> void removeCacheListener( String cacheName, ICacheListener<KK, VV> obj ) - throws IOException - { - // Empty - } - - /** - * @param obj - * @throws IOException - */ - @Override - public <KK, VV> void removeCacheListener( ICacheListener<KK, VV> obj ) - throws IOException - { - // Empty - } - /** * @param listernId The listernId to set. */ @@ -526,22 +455,4 @@ public class LateralTCPService<K, V> { return listenerId; } - - /** - * @param tcpLateralCacheAttributes The tcpLateralCacheAttributes to set. - */ - public void setTcpLateralCacheAttributes( ITCPLateralCacheAttributes tcpLateralCacheAttributes ) - { - this.tcpLateralCacheAttributes = tcpLateralCacheAttributes; - } - - /** - * @return Returns the tcpLateralCacheAttributes. - */ - public ITCPLateralCacheAttributes getTcpLateralCacheAttributes() - { - return tcpLateralCacheAttributes; - } - - } Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFactory.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFactory.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFactory.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFactory.java Mon Apr 6 13:54:48 2015 @@ -19,9 +19,9 @@ package org.apache.commons.jcs.auxiliary * under the License. */ +import org.apache.commons.jcs.auxiliary.AbstractAuxiliaryCacheFactory; import org.apache.commons.jcs.auxiliary.AuxiliaryCache; import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes; -import org.apache.commons.jcs.auxiliary.AuxiliaryCacheFactory; import org.apache.commons.jcs.auxiliary.remote.server.behavior.RemoteType; import org.apache.commons.jcs.engine.behavior.ICache; import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager; @@ -39,11 +39,8 @@ import java.util.StringTokenizer; * clients. */ public class RemoteCacheFactory - implements AuxiliaryCacheFactory + extends AbstractAuxiliaryCacheFactory { - /** The name of this auxiliary */ - private String name; - /** store reference of facades to initiate failover */ private static final HashMap<String, RemoteCacheNoWaitFacade<?, ?>> facades = new HashMap<String, RemoteCacheNoWaitFacade<?, ?>>(); @@ -159,26 +156,6 @@ public class RemoteCacheFactory // end createCache /** - * Gets the name attribute of the RemoteCacheFactory object - * @return The name value - */ - @Override - public String getName() - { - return this.name; - } - - /** - * Sets the name attribute of the RemoteCacheFactory object - * @param name The new name value - */ - @Override - public void setName( String name ) - { - this.name = name; - } - - /** * The facades are what the cache hub talks to. * @return Returns the facades. */ Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheManager.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheManager.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheManager.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheManager.java Mon Apr 6 13:54:48 2015 @@ -19,13 +19,14 @@ package org.apache.commons.jcs.auxiliary * under the License. */ -import org.apache.commons.jcs.auxiliary.AuxiliaryCacheManager; import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes; import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheClient; import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheListener; -import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheObserver; +import org.apache.commons.jcs.engine.CacheWatchRepairable; import org.apache.commons.jcs.engine.ZombieCacheServiceNonLocal; +import org.apache.commons.jcs.engine.ZombieCacheWatch; import org.apache.commons.jcs.engine.behavior.ICache; +import org.apache.commons.jcs.engine.behavior.ICacheObserver; import org.apache.commons.jcs.engine.behavior.ICacheServiceNonLocal; import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager; import org.apache.commons.jcs.engine.behavior.IElementSerializer; @@ -49,7 +50,7 @@ import java.util.Map; * Listeners are not registered with the server until a cache is requested from the manager. */ public class RemoteCacheManager - implements AuxiliaryCacheManager, IShutdownObserver + implements IShutdownObserver { /** The logger */ private static final Log log = LogFactory.getLog( RemoteCacheManager.class ); @@ -92,7 +93,7 @@ public class RemoteCacheManager * Wrapper of the remote cache watch service; or wrapper of a zombie service if failed to * connect. */ - private RemoteCacheWatchRepairable remoteWatch; + private CacheWatchRepairable remoteWatch; /** The cache manager listeners will need to use to get a cache. */ private final ICompositeCacheManager cacheMgr; @@ -125,7 +126,7 @@ public class RemoteCacheManager // register shutdown observer this.cacheMgr.registerShutdownObserver( this ); - String registry = "//" + host + ":" + port + "/" + service; + String registry = RemoteUtils.getNamingURL(host, port, service); if ( log.isInfoEnabled() ) { log.info( "Looking up server [" + registry + "]" ); @@ -145,8 +146,9 @@ public class RemoteCacheManager log.debug( "remoteService = " + remoteService ); } - remoteWatch = new RemoteCacheWatchRepairable(); - remoteWatch.setCacheWatch( (IRemoteCacheObserver) obj ); + ICacheObserver remoteObserver = (ICacheObserver) obj; + remoteWatch = new CacheWatchRepairable(); + remoteWatch.setCacheWatch( remoteObserver ); } catch ( Exception ex ) { @@ -155,8 +157,8 @@ public class RemoteCacheManager // services. log.error( "Problem finding server at [" + registry + "]", ex ); remoteService = new ZombieCacheServiceNonLocal<String, String>(); - remoteWatch = new RemoteCacheWatchRepairable(); - remoteWatch.setCacheWatch( new ZombieRemoteCacheWatch() ); + remoteWatch = new CacheWatchRepairable(); + remoteWatch.setCacheWatch( new ZombieCacheWatch() ); // Notify the cache monitor about the error, and kick off the // recovery process. @@ -363,7 +365,6 @@ public class RemoteCacheManager * @param cacheName * @return The cache value */ - @Override public <K, V> RemoteCacheNoWait<K, V> getCache( String cacheName ) { IRemoteCacheAttributes ca = (IRemoteCacheAttributes) remoteCacheAttributes.copy(); @@ -506,7 +507,7 @@ public class RemoteCacheManager * @param remoteService * @param remoteWatch */ - public void fixCaches( ICacheServiceNonLocal<?, ?> remoteService, IRemoteCacheObserver remoteWatch ) + public void fixCaches( ICacheServiceNonLocal<?, ?> remoteService, ICacheObserver remoteWatch ) { if ( log.isInfoEnabled() ) { Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheRestore.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheRestore.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheRestore.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheRestore.java Mon Apr 6 13:54:48 2015 @@ -19,7 +19,7 @@ package org.apache.commons.jcs.auxiliary * under the License. */ -import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheObserver; +import org.apache.commons.jcs.engine.behavior.ICacheObserver; import org.apache.commons.jcs.engine.behavior.ICacheRestore; import org.apache.commons.jcs.engine.behavior.ICacheServiceNonLocal; import org.apache.commons.logging.Log; @@ -78,7 +78,7 @@ public class RemoteCacheRestore { return canFix; } - String registry = "//" + remoteCacheManager.host + ":" + remoteCacheManager.port + "/" + remoteCacheManager.service; + String registry = RemoteUtils.getNamingURL(remoteCacheManager.host, remoteCacheManager.port, remoteCacheManager.service); if ( log.isInfoEnabled() ) { log.info( "looking up server [" + registry + "]" ); @@ -115,11 +115,13 @@ public class RemoteCacheRestore { return; } - remoteCacheManager.fixCaches( (ICacheServiceNonLocal<?, ?>) remoteObj, (IRemoteCacheObserver) remoteObj ); + remoteCacheManager.fixCaches( (ICacheServiceNonLocal<?, ?>) remoteObj, (ICacheObserver) remoteObj ); if ( log.isInfoEnabled() ) { - String msg = "Remote connection to " + "//" + remoteCacheManager.host + ":" + remoteCacheManager.port + "/" + remoteCacheManager.service + " resumed."; + String msg = "Remote connection to " + + RemoteUtils.getNamingURL(remoteCacheManager.host, remoteCacheManager.port, remoteCacheManager.service) + + " resumed."; remoteCacheManager.logApplicationEvent( "RemoteCacheRestore", "fix", msg ); log.info( msg ); } Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheFactory.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheFactory.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheFactory.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheFactory.java Mon Apr 6 13:54:48 2015 @@ -19,9 +19,9 @@ package org.apache.commons.jcs.auxiliary * under the License. */ +import org.apache.commons.jcs.auxiliary.AbstractAuxiliaryCacheFactory; import org.apache.commons.jcs.auxiliary.AuxiliaryCache; import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes; -import org.apache.commons.jcs.auxiliary.AuxiliaryCacheFactory; import org.apache.commons.jcs.auxiliary.remote.RemoteCacheNoWait; import org.apache.commons.jcs.auxiliary.remote.RemoteCacheNoWaitFacade; import org.apache.commons.jcs.auxiliary.remote.server.behavior.RemoteType; @@ -40,11 +40,8 @@ import java.util.HashMap; * clients. */ public class RemoteHttpCacheFactory - implements AuxiliaryCacheFactory + extends AbstractAuxiliaryCacheFactory { - /** The name of this auxiliary */ - private String name; - /** store reference of facades to initiate failover */ private static final HashMap<String, RemoteCacheNoWaitFacade<?, ?>> facades = new HashMap<String, RemoteCacheNoWaitFacade<?, ?>>(); @@ -87,28 +84,6 @@ public class RemoteHttpCacheFactory } /** - * Gets the name attribute of the RemoteCacheFactory object - * <p> - * @return The name value - */ - @Override - public String getName() - { - return this.name; - } - - /** - * Sets the name attribute of the RemoteCacheFactory object - * <p> - * @param name The new name value - */ - @Override - public void setName( String name ) - { - this.name = name; - } - - /** * The facades are what the cache hub talks to. * @return Returns the facades. */ Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheManager.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheManager.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheManager.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheManager.java Mon Apr 6 13:54:48 2015 @@ -19,7 +19,6 @@ package org.apache.commons.jcs.auxiliary * under the License. */ -import org.apache.commons.jcs.auxiliary.AuxiliaryCacheManager; import org.apache.commons.jcs.auxiliary.remote.RemoteCacheNoWait; import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes; import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheClient; @@ -39,7 +38,7 @@ import java.util.Map; * This is a very crude copy of the RMI remote manager. It needs a lot of work! */ public class RemoteHttpCacheManager - implements AuxiliaryCacheManager, IShutdownObserver + implements IShutdownObserver { /** The logger */ private static final Log log = LogFactory.getLog( RemoteHttpCacheManager.class ); @@ -142,7 +141,7 @@ public class RemoteHttpCacheManager * @param cacheName * @return The cache value */ - @Override + // @Override public <K, V> RemoteCacheNoWait<K, V> getCache( String cacheName ) { // TODO get some defaults! Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/server/behavior/IRemoteCacheServer.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/server/behavior/IRemoteCacheServer.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/server/behavior/IRemoteCacheServer.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/server/behavior/IRemoteCacheServer.java Mon Apr 6 13:54:48 2015 @@ -1,8 +1,7 @@ package org.apache.commons.jcs.auxiliary.remote.server.behavior; import java.rmi.Remote; - -import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheObserver; +import org.apache.commons.jcs.engine.behavior.ICacheObserver; import org.apache.commons.jcs.engine.behavior.ICacheServiceAdmin; import org.apache.commons.jcs.engine.behavior.ICacheServiceNonLocal; @@ -32,7 +31,7 @@ import org.apache.commons.jcs.engine.beh * */ public interface IRemoteCacheServer<K, V> - extends ICacheServiceNonLocal<K, V>, IRemoteCacheObserver, ICacheServiceAdmin, Remote + extends ICacheServiceNonLocal<K, V>, ICacheObserver, ICacheServiceAdmin, Remote { // empty } Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/behavior/ICompositeCacheManager.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/behavior/ICompositeCacheManager.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/behavior/ICompositeCacheManager.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/behavior/ICompositeCacheManager.java Mon Apr 6 13:54:48 2015 @@ -19,6 +19,7 @@ package org.apache.commons.jcs.engine.be * under the License. */ +import org.apache.commons.jcs.auxiliary.AuxiliaryCache; import org.apache.commons.jcs.engine.control.CompositeCache; import java.util.Properties; @@ -39,6 +40,15 @@ public interface ICompositeCacheManager <K, V> CompositeCache<K, V> getCache( String cacheName ); /** + * Gets the auxiliary cache attribute of the CacheHub object + * + * @param auxName + * @param cacheName + * @return AuxiliaryCache + */ + <K, V> AuxiliaryCache<K, V> getAuxiliaryCache( String auxName, String cacheName ); + + /** * This is exposed so other manager can get access to the props. * <p> * @return the configurationProperties Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java Mon Apr 6 13:54:48 2015 @@ -19,6 +19,16 @@ package org.apache.commons.jcs.engine.co * under the License. */ +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + import org.apache.commons.jcs.access.exception.CacheException; import org.apache.commons.jcs.access.exception.ObjectNotFoundException; import org.apache.commons.jcs.auxiliary.AuxiliaryCache; @@ -49,16 +59,6 @@ import org.apache.commons.jcs.engine.sta import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - /** * This is the primary hub for a single cache/region. It controls the flow of items through the * cache. The auxiliary and memory caches are plugged in here. @@ -1323,7 +1323,7 @@ public class CompositeCache<K, V> { if ( log.isInfoEnabled() ) { - log.info( "In DISPOSE, [" + this.cacheAttr.getCacheName() + "] SKIPPING auxiliary [" + aux + "] fromRemote [" + log.info( "In DISPOSE, [" + this.cacheAttr.getCacheName() + "] SKIPPING auxiliary [" + aux.getCacheName() + "] fromRemote [" + fromRemote + "]" ); } continue; @@ -1331,7 +1331,7 @@ public class CompositeCache<K, V> if ( log.isInfoEnabled() ) { - log.info( "In DISPOSE, [" + this.cacheAttr.getCacheName() + "] auxiliary [" + aux + "]" ); + log.info( "In DISPOSE, [" + this.cacheAttr.getCacheName() + "] auxiliary [" + aux.getCacheName() + "]" ); } // IT USED TO BE THE CASE THAT (If the auxiliary is not a lateral, or the cache @@ -1349,7 +1349,7 @@ public class CompositeCache<K, V> if ( log.isInfoEnabled() ) { - log.info( "In DISPOSE, [" + this.cacheAttr.getCacheName() + "] put " + numToFree + " into auxiliary " + aux ); + log.info( "In DISPOSE, [" + this.cacheAttr.getCacheName() + "] put " + numToFree + " into auxiliary " + aux.getCacheName() ); } } Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheConfigurator.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheConfigurator.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheConfigurator.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheConfigurator.java Mon Apr 6 13:54:48 2015 @@ -530,83 +530,99 @@ public class CompositeCacheConfigurator */ protected <K, V> AuxiliaryCache<K, V> parseAuxiliary( Properties props, String auxName, String regName ) { - AuxiliaryCache<K, V> auxCache; - if ( log.isDebugEnabled() ) { log.debug( "parseAuxiliary " + auxName ); } - // GET FACTORY - AuxiliaryCacheFactory auxFac = compositeCacheManager.registryFacGet( auxName ); - if ( auxFac == null ) + // GET CACHE + @SuppressWarnings("unchecked") // Common map for all caches + AuxiliaryCache<K, V> auxCache = (AuxiliaryCache<K, V>)compositeCacheManager.getAuxiliaryCache(auxName, regName); + + if (auxCache == null) { - // auxFactory was not previously initialized. - String prefix = AUXILIARY_PREFIX + auxName; - auxFac = OptionConverter.instantiateByKey( props, prefix, null ); + // GET FACTORY + AuxiliaryCacheFactory auxFac = compositeCacheManager.registryFacGet( auxName ); if ( auxFac == null ) { - log.error( "Could not instantiate auxFactory named \"" + auxName + "\"." ); - return null; - } + // auxFactory was not previously initialized. + String prefix = AUXILIARY_PREFIX + auxName; + auxFac = OptionConverter.instantiateByKey( props, prefix, null ); + if ( auxFac == null ) + { + log.error( "Could not instantiate auxFactory named \"" + auxName + "\"." ); + return null; + } - auxFac.setName( auxName ); + auxFac.setName( auxName ); + auxFac.initialize(); - compositeCacheManager.registryFacPut( auxFac ); - } + compositeCacheManager.registryFacPut( auxFac ); + } - // GET ATTRIBUTES - AuxiliaryCacheAttributes auxAttr = compositeCacheManager.registryAttrGet( auxName ); - String attrName = AUXILIARY_PREFIX + auxName + ATTRIBUTE_PREFIX; - if ( auxAttr == null ) - { - // auxFactory was not previously initialized. - String prefix = AUXILIARY_PREFIX + auxName + ATTRIBUTE_PREFIX; - auxAttr = OptionConverter.instantiateByKey( props, prefix, null ); + // GET ATTRIBUTES + AuxiliaryCacheAttributes auxAttr = compositeCacheManager.registryAttrGet( auxName ); + String attrName = AUXILIARY_PREFIX + auxName + ATTRIBUTE_PREFIX; if ( auxAttr == null ) { - log.error( "Could not instantiate auxAttr named '" + attrName + "'" ); - return null; + // auxFactory was not previously initialized. + String prefix = AUXILIARY_PREFIX + auxName + ATTRIBUTE_PREFIX; + auxAttr = OptionConverter.instantiateByKey( props, prefix, null ); + if ( auxAttr == null ) + { + log.error( "Could not instantiate auxAttr named '" + attrName + "'" ); + return null; + } + auxAttr.setName( auxName ); + compositeCacheManager.registryAttrPut( auxAttr ); } - auxAttr.setName( auxName ); - compositeCacheManager.registryAttrPut( auxAttr ); - } - auxAttr = auxAttr.copy(); + auxAttr = auxAttr.copy(); - if ( log.isDebugEnabled() ) - { - log.debug( "Parsing options for '" + attrName + "'" ); - } + if ( log.isDebugEnabled() ) + { + log.debug( "Parsing options for '" + attrName + "'" ); + } - PropertySetter.setProperties( auxAttr, props, attrName + "." ); - auxAttr.setCacheName( regName ); + PropertySetter.setProperties( auxAttr, props, attrName + "." ); + auxAttr.setCacheName( regName ); - if ( log.isDebugEnabled() ) - { - log.debug( "End of parsing for '" + attrName + "'" ); - } + if ( log.isDebugEnabled() ) + { + log.debug( "End of parsing for '" + attrName + "'" ); + } - // GET CACHE FROM FACTORY WITH ATTRIBUTES - auxAttr.setCacheName( regName ); + // GET CACHE FROM FACTORY WITH ATTRIBUTES + auxAttr.setCacheName( regName ); - String auxPrefix = AUXILIARY_PREFIX + auxName; + String auxPrefix = AUXILIARY_PREFIX + auxName; - // CONFIGURE THE EVENT LOGGER - ICacheEventLogger cacheEventLogger = AuxiliaryCacheConfigurator.parseCacheEventLogger( props, auxPrefix ); + // CONFIGURE THE EVENT LOGGER + ICacheEventLogger cacheEventLogger = AuxiliaryCacheConfigurator.parseCacheEventLogger( props, auxPrefix ); - // CONFIGURE THE ELEMENT SERIALIZER - IElementSerializer elementSerializer = AuxiliaryCacheConfigurator.parseElementSerializer( props, auxPrefix ); - - // CONFIGURE THE KEYMATCHER - //IKeyMatcher keyMatcher = parseKeyMatcher( props, auxPrefix ); - // TODO add to factory interface - - // Consider putting the compositeCache back in the factory interface - // since the manager may not know about it at this point. - // need to make sure the manager already has the cache - // before the auxiliary is created. - auxCache = auxFac.createCache( auxAttr, compositeCacheManager, cacheEventLogger, elementSerializer ); + // CONFIGURE THE ELEMENT SERIALIZER + IElementSerializer elementSerializer = AuxiliaryCacheConfigurator.parseElementSerializer( props, auxPrefix ); + + // CONFIGURE THE KEYMATCHER + //IKeyMatcher keyMatcher = parseKeyMatcher( props, auxPrefix ); + // TODO add to factory interface + + // Consider putting the compositeCache back in the factory interface + // since the manager may not know about it at this point. + // need to make sure the manager already has the cache + // before the auxiliary is created. + try + { + auxCache = auxFac.createCache( auxAttr, compositeCacheManager, cacheEventLogger, elementSerializer ); + } + catch (Exception e) + { + log.error( "Could not instantiate auxiliary cache named \"" + regName + "\"." ); + return null; + } + + compositeCacheManager.addAuxiliaryCache(auxName, regName, auxCache); + } return auxCache; } Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java Mon Apr 6 13:54:48 2015 @@ -21,6 +21,7 @@ package org.apache.commons.jcs.engine.co import org.apache.commons.jcs.access.exception.CacheException; import org.apache.commons.jcs.admin.JCSAdminBean; +import org.apache.commons.jcs.auxiliary.AuxiliaryCache; import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes; import org.apache.commons.jcs.auxiliary.AuxiliaryCacheFactory; import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheConstants; @@ -45,6 +46,7 @@ import org.apache.commons.logging.LogFac import javax.management.MBeanServer; import javax.management.ObjectName; + import java.io.IOException; import java.io.InputStream; import java.lang.management.ManagementFactory; @@ -97,6 +99,10 @@ public class CompositeCacheManager private final Map<String, AuxiliaryCacheAttributes> auxiliaryAttributeRegistry = new ConcurrentHashMap<String, AuxiliaryCacheAttributes>( 11 ); + /** Used to keep track of configured auxiliaries */ + private final Map<String, AuxiliaryCache<?, ?>> auxiliaryCaches = + new ConcurrentHashMap<String, AuxiliaryCache<?, ?>>( 11 ); + /** Properties with which this manager was configured. This is exposed for other managers. */ private Properties configurationProperties; @@ -686,6 +692,15 @@ public class CompositeCacheManager freeCache( name ); } + // shut down factories + for (AuxiliaryCacheFactory factory : auxiliaryFactoryRegistry.values()) + { + factory.dispose(); + } + + auxiliaryAttributeRegistry.clear(); + auxiliaryFactoryRegistry.clear(); + if (shutdownHook != null) { try @@ -779,7 +794,7 @@ public class CompositeCacheManager /** * @param auxFac */ - void registryFacPut( AuxiliaryCacheFactory auxFac ) + public void registryFacPut( AuxiliaryCacheFactory auxFac ) { auxiliaryFactoryRegistry.put( auxFac.getName(), auxFac ); } @@ -788,7 +803,7 @@ public class CompositeCacheManager * @param name * @return AuxiliaryCacheFactory */ - AuxiliaryCacheFactory registryFacGet( String name ) + public AuxiliaryCacheFactory registryFacGet( String name ) { return auxiliaryFactoryRegistry.get( name ); } @@ -796,7 +811,7 @@ public class CompositeCacheManager /** * @param auxAttr */ - void registryAttrPut( AuxiliaryCacheAttributes auxAttr ) + public void registryAttrPut( AuxiliaryCacheAttributes auxAttr ) { auxiliaryAttributeRegistry.put( auxAttr.getName(), auxAttr ); } @@ -805,7 +820,7 @@ public class CompositeCacheManager * @param name * @return AuxiliaryCacheAttributes */ - AuxiliaryCacheAttributes registryAttrGet( String name ) + public AuxiliaryCacheAttributes registryAttrGet( String name ) { return auxiliaryAttributeRegistry.get( name ); } @@ -816,15 +831,44 @@ public class CompositeCacheManager * @param cacheName the region name * @param cache the cache instance */ - void addCache(String cacheName, ICache<?, ?> cache) + public void addCache(String cacheName, ICache<?, ?> cache) { caches.put(cacheName, cache); } /** + * Add a cache to the map of registered auxiliary caches + * + * @param auxName the auxiliary name + * @param cacheName the region name + * @param cache the cache instance + */ + public void addAuxiliaryCache(String auxName, String cacheName, AuxiliaryCache<?, ?> cache) + { + String key = String.format("aux.%s.region.%s", auxName, cacheName); + auxiliaryCaches.put(key, cache); + } + + /** + * Get a cache from the map of registered auxiliary caches + * + * @param auxName the auxiliary name + * @param cacheName the region name + * + * @return the cache instance + */ + @Override + @SuppressWarnings("unchecked") // because of common map for all auxiliary caches + public <K, V> AuxiliaryCache<K, V> getAuxiliaryCache(String auxName, String cacheName) + { + String key = String.format("aux.%s.region.%s", auxName, cacheName); + return (AuxiliaryCache<K, V>) auxiliaryCaches.get(key); + } + + /** * @param defaultAuxValues the defaultAuxValues to set */ - void setDefaultAuxValues(String defaultAuxValues) + public void setDefaultAuxValues(String defaultAuxValues) { this.defaultAuxValues = defaultAuxValues; } Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/MockAuxiliaryCacheFactory.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/MockAuxiliaryCacheFactory.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/MockAuxiliaryCacheFactory.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/MockAuxiliaryCacheFactory.java Mon Apr 6 13:54:48 2015 @@ -25,7 +25,7 @@ import org.apache.commons.jcs.engine.log /** For testing */ public class MockAuxiliaryCacheFactory - implements AuxiliaryCacheFactory + extends AbstractAuxiliaryCacheFactory { /** the name of the aux */ public String name = "MockAuxiliaryCacheFactory"; Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java Mon Apr 6 13:54:48 2015 @@ -19,20 +19,20 @@ package org.apache.commons.jcs.auxiliary * under the License. */ -import junit.framework.TestCase; -import org.apache.commons.jcs.JCS; -import org.apache.commons.jcs.access.CacheAccess; -import org.apache.commons.jcs.engine.behavior.ICacheElement; - import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import java.util.HashSet; import java.util.Map; -import java.util.Properties; import java.util.Set; +import junit.framework.TestCase; + +import org.apache.commons.jcs.JCS; +import org.apache.commons.jcs.access.CacheAccess; +import org.apache.commons.jcs.engine.behavior.ICacheElement; + /** * Runs basic tests for the JDBC disk cache. * @author Aaron Smuts @@ -52,15 +52,12 @@ public class MySQLDiskCacheHsqlBackedUni System.setProperty( "hsqldb.cache_scale", "8" ); String rafroot = "target"; - Properties p = new Properties(); - String driver = p.getProperty( "driver", "org.hsqldb.jdbcDriver" ); - String url = p.getProperty( "url", "jdbc:hsqldb:" ); - String database = p.getProperty( "database", rafroot + "/MySQLDiskCacheHsqlBackedUnitTest" ); - String user = p.getProperty( "user", "sa" ); - String password = p.getProperty( "password", "" ); + String url = "jdbc:hsqldb:"; + String database = rafroot + "/MySQLDiskCacheHsqlBackedUnitTest"; + String user = "sa"; + String password = ""; new org.hsqldb.jdbcDriver(); - Class.forName( driver ).newInstance(); Connection cConn = DriverManager.getConnection( url + database, user, password ); setupTABLE( cConn ); @@ -100,7 +97,7 @@ public class MySQLDiskCacheHsqlBackedUni //System.out.println( "BEFORE PUT \n" + jcs.getStats() ); // Add items to cache - for ( int i = 0; i <= items; i++ ) + for ( int i = 0; i < items; i++ ) { jcs.put( i + ":key", region + " data " + i ); } @@ -110,7 +107,7 @@ public class MySQLDiskCacheHsqlBackedUni //System.out.println( jcs.getStats() ); // Test that all items are in cache - for ( int i = 0; i <= items; i++ ) + for ( int i = 0; i < items; i++ ) { String value = jcs.get( i + ":key" ); @@ -119,13 +116,13 @@ public class MySQLDiskCacheHsqlBackedUni // Test that getElements returns all the expected values Set<String> keys = new HashSet<String>(); - for ( int i = 0; i <= items; i++ ) + for ( int i = 0; i < items; i++ ) { keys.add( i + ":key" ); } Map<String, ICacheElement<String, String>> elements = jcs.getCacheElements( keys ); - for ( int i = 0; i <= items; i++ ) + for ( int i = 0; i < items; i++ ) { ICacheElement<String, String> element = elements.get( i + ":key" ); assertNotNull( "element " + i + ":key is missing", element ); @@ -133,14 +130,14 @@ public class MySQLDiskCacheHsqlBackedUni } // Remove all the items - for ( int i = 0; i <= items; i++ ) + for ( int i = 0; i < items; i++ ) { jcs.remove( i + ":key" ); } // Verify removal - for ( int i = 0; i <= items; i++ ) + for ( int i = 0; i < items; i++ ) { assertNull( "Removed key should be null: " + i + ":key", jcs.get( i + ":key" ) ); } @@ -161,7 +158,7 @@ public class MySQLDiskCacheHsqlBackedUni // System.out.println( "BEFORE PUT \n" + jcs.getStats() ); // DO WORK - for ( int i = 0; i <= items; i++ ) + for ( int i = 0; i < items; i++ ) { jcs.put( i + ":key", region + " data " + i ); } Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/util/ScheduleParserUtilUnitTest.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/util/ScheduleParserUtilUnitTest.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/util/ScheduleParserUtilUnitTest.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/util/ScheduleParserUtilUnitTest.java Mon Apr 6 13:54:48 2015 @@ -19,10 +19,11 @@ package org.apache.commons.jcs.auxiliary * under the License. */ -import junit.framework.TestCase; - +import java.text.ParseException; import java.util.Date; +import junit.framework.TestCase; + /** * Unit tests for the schedule parser. * <p> @@ -43,7 +44,7 @@ public class ScheduleParserUtilUnitTest fail( "Should have thrown an exception" ); } - catch ( ScheduleFormatException e ) + catch ( ParseException e ) { // expected } @@ -60,7 +61,7 @@ public class ScheduleParserUtilUnitTest fail( "Should have thrown an exception" ); } - catch ( ScheduleFormatException e ) + catch ( ParseException e ) { // expected } @@ -68,10 +69,10 @@ public class ScheduleParserUtilUnitTest /** * Verify that we get one date for one date. - * @throws ScheduleFormatException + * @throws ParseException */ public void testGetsDatesSingle() - throws ScheduleFormatException + throws ParseException { String schedule = "12:34:56"; Date[] dates = ScheduleParser.createDatesForSchedule( schedule ); @@ -80,10 +81,10 @@ public class ScheduleParserUtilUnitTest } /** * Verify that we get one date for one date. - * @throws ScheduleFormatException + * @throws ParseException */ public void testGetsDatesMultiple() - throws ScheduleFormatException + throws ParseException { String schedule = "12:34:56,03:51:00,12:34:12"; Date[] dates = ScheduleParser.createDatesForSchedule( schedule ); @@ -103,7 +104,7 @@ public class ScheduleParserUtilUnitTest fail( "Should have thrown an exception for a malformed date" ); } - catch ( ScheduleFormatException e ) + catch ( ParseException e ) { // expected } @@ -120,7 +121,7 @@ public class ScheduleParserUtilUnitTest fail( "Should have thrown an exception for a malformed date" ); } - catch ( ScheduleFormatException e ) + catch ( ParseException e ) { // expected } Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java Mon Apr 6 13:54:48 2015 @@ -26,7 +26,6 @@ import org.apache.commons.jcs.auxiliary. import org.apache.commons.jcs.auxiliary.lateral.LateralCacheNoWaitFacade; import org.apache.commons.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes; import org.apache.commons.jcs.auxiliary.lateral.socket.tcp.behavior.ITCPLateralCacheAttributes; -import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager; import org.apache.commons.jcs.engine.behavior.IElementSerializer; import org.apache.commons.jcs.engine.control.CompositeCacheManager; import org.apache.commons.jcs.engine.logging.MockCacheEventLogger; @@ -42,8 +41,11 @@ public class LateralTCPDiscoveryListener /** the listener */ private LateralTCPDiscoveryListener listener; + /** the cache factory */ + private LateralTCPCacheFactory factory; + /** The cache manager. */ - private ICompositeCacheManager cacheMgr; + private CompositeCacheManager cacheMgr; /** The event logger. */ protected MockCacheEventLogger cacheEventLogger; @@ -55,11 +57,14 @@ public class LateralTCPDiscoveryListener @Override protected void setUp() throws Exception { + factory = new LateralTCPCacheFactory(); + factory.initialize(); + cacheMgr = CompositeCacheManager.getInstance(); cacheEventLogger = new MockCacheEventLogger(); elementSerializer = new StandardSerializer(); - listener = new LateralTCPDiscoveryListener( cacheMgr, cacheEventLogger, elementSerializer ); + listener = new LateralTCPDiscoveryListener( factory.getName(), cacheMgr ); } /** @@ -224,9 +229,10 @@ public class LateralTCPDiscoveryListener ITCPLateralCacheAttributes lca = new TCPLateralCacheAttributes(); lca.setTransmissionType( LateralCacheAttributes.Type.TCP ); lca.setTcpServer( service.getServiceAddress() + ":" + service.getServicePort() ); - LateralTCPCacheManager lcm = LateralTCPCacheManager.getInstance( lca, cacheMgr, cacheEventLogger, - elementSerializer ); - LateralCacheNoWait<String, String> noWait = lcm.getCache( cacheName ); + lca.setCacheName(cacheName); + LateralCacheNoWait<String, String> noWait = factory.createCacheNoWait(lca, cacheEventLogger, elementSerializer); + // this is the normal process, the discovery service expects it there + cacheMgr.addAuxiliaryCache(factory.getName(), cacheName, noWait); @SuppressWarnings("unchecked") LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0]; @@ -263,9 +269,10 @@ public class LateralTCPDiscoveryListener ITCPLateralCacheAttributes lca = new TCPLateralCacheAttributes(); lca.setTransmissionType( LateralCacheAttributes.Type.TCP ); lca.setTcpServer( service.getServiceAddress() + ":" + service.getServicePort() ); - LateralTCPCacheManager lcm = LateralTCPCacheManager.getInstance( lca, cacheMgr, cacheEventLogger, - elementSerializer ); - LateralCacheNoWait<String, String> noWait = lcm.getCache( cacheName ); + lca.setCacheName(cacheName); + LateralCacheNoWait<String, String> noWait = factory.createCacheNoWait(lca, cacheEventLogger, elementSerializer); + // this is the normal process, the discovery service expects it there + cacheMgr.addAuxiliaryCache(factory.getName(), cacheName, noWait); @SuppressWarnings("unchecked") LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0]; Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/MockCompositeCacheManager.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/MockCompositeCacheManager.java?rev=1671536&r1=1671535&r2=1671536&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/MockCompositeCacheManager.java (original) +++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/control/MockCompositeCacheManager.java Mon Apr 6 13:54:48 2015 @@ -19,6 +19,7 @@ package org.apache.commons.jcs.engine.co * under the License. */ +import org.apache.commons.jcs.auxiliary.AuxiliaryCache; import org.apache.commons.jcs.engine.CompositeCacheAttributes; import org.apache.commons.jcs.engine.ElementAttributes; import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager; @@ -55,6 +56,12 @@ public class MockCompositeCacheManager return (CompositeCache<K, V>)cache; } + @Override + public <K, V> AuxiliaryCache<K, V> getAuxiliaryCache(String auxName, String cacheName) + { + return null; + } + /** * @param cache The cache to set. */