Author: asmuts Date: Fri Sep 19 10:38:04 2008 New Revision: 697160 URL: http://svn.apache.org/viewvc?rev=697160&view=rev Log: adding automatic remote cache server attribute config
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheConstants.java jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributes.java jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactory.java jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/behavior/IRemoteCacheServerAttributes.java jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactoryUnitTest.java Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheConstants.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheConstants.java?rev=697160&r1=697159&r2=697160&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheConstants.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheConstants.java Fri Sep 19 10:38:04 2008 @@ -27,12 +27,18 @@ /** Mapping to props file value */ public final static String REMOTE_CACHE_SERVICE_VAL = IRemoteCacheService.class.getName(); + /** + * I'm trying to migrate everything to use this prefix. All those below will be replaced. Any of + * the RemoteCacheServerAttributes can be configured this way. + */ + public final static String CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX = "jcs.remotecache.serverattributes"; + /** Property prefix, should be jcs.remote but this would break existing config. */ public final static String PROPERTY_PREFIX = "remote"; - + /** Mapping to props file value */ public final static String SOCKET_TIMEOUT_MILLIS = PROPERTY_PREFIX + ".cache.rmiSocketFactoryTimeoutMillis"; - + /** Mapping to props file value */ public final static String REMOTE_CACHE_SERVICE_NAME = PROPERTY_PREFIX + ".cache.service.name"; Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributes.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributes.java?rev=697160&r1=697159&r2=697160&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributes.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerAttributes.java Fri Sep 19 10:38:04 2008 @@ -59,7 +59,7 @@ private boolean getOnly = false; /** Can a cluster remote put to other remotes */ - private boolean localClusterConsistency = false; + private boolean localClusterConsistency = true; /** Can a cluster remote get from other remotes */ private boolean allowClusterGet = true; @@ -314,12 +314,22 @@ */ public boolean getLocalClusterConsistency() { - return localClusterConsistency; + return isLocalClusterConsistency(); } /** * Should cluster updates be propagated to the locals * <p> + * @return The localClusterConsistency value + */ + public boolean isLocalClusterConsistency() + { + return localClusterConsistency; + } + + /** + * Should cluster updates be propagated to the locals + * <p> * @param r The new localClusterConsistency value */ public void setLocalClusterConsistency( boolean r ) @@ -334,10 +344,20 @@ */ public boolean getAllowClusterGet() { - return allowClusterGet; + return isAllowClusterGet(); } /** + * Should gets from non-cluster clients be allowed to get from other remote auxiliaries. + * <p> + * @return The localClusterConsistency value + */ + public boolean isAllowClusterGet() + { + return allowClusterGet; + } + + /** * Should we try to get from other cluster servers if we don't find the items locally. * <p> * @param r The new localClusterConsistency value Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactory.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactory.java?rev=697160&r1=697159&r2=697160&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactory.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactory.java Fri Sep 19 10:38:04 2008 @@ -35,6 +35,7 @@ import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheConstants; import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheServiceAdmin; import org.apache.jcs.engine.logging.behavior.ICacheEventLogger; +import org.apache.jcs.utils.config.PropertySetter; import EDU.oswego.cs.dl.util.concurrent.ClockDaemon; import EDU.oswego.cs.dl.util.concurrent.ThreadFactory; @@ -234,59 +235,88 @@ /** * Configure. * <p> + * jcs.remotecache.serverattributes.ATTRIBUTENAME=ATTRIBUTEVALUE + * <p> * @param prop * @return RemoteCacheServerAttributesconfigureRemoteCacheServerAttributes */ protected static RemoteCacheServerAttributes configureRemoteCacheServerAttributes( Properties prop ) { - // TODO: make automatic RemoteCacheServerAttributes rcsa = new RemoteCacheServerAttributes(); + // configure automatically + PropertySetter.setProperties( rcsa, prop, CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + "." ); + + configureManuallyIfValuesArePresent( prop, rcsa ); + + return rcsa; + } + + /** + * This looks for the old config values. + * <p> + * @param prop + * @param rcsa + */ + private static void configureManuallyIfValuesArePresent( Properties prop, RemoteCacheServerAttributes rcsa ) + { + // DEPRECATED CONFIG String servicePortStr = prop.getProperty( REMOTE_CACHE_SERVICE_PORT ); - try + if ( servicePortStr != null ) { - int servicePort = Integer.parseInt( servicePortStr ); - rcsa.setServicePort( servicePort ); - log.debug( "Remote cache service uses port number " + servicePort + "." ); - } - catch ( NumberFormatException ignore ) - { - log.debug( "Remote cache service port property " + REMOTE_CACHE_SERVICE_PORT - + " not specified. An anonymous port will be used." ); + try + { + int servicePort = Integer.parseInt( servicePortStr ); + rcsa.setServicePort( servicePort ); + log.debug( "Remote cache service uses port number " + servicePort + "." ); + } + catch ( NumberFormatException ignore ) + { + log.debug( "Remote cache service port property " + REMOTE_CACHE_SERVICE_PORT + + " not specified. An anonymous port will be used." ); + } } String socketTimeoutMillisStr = prop.getProperty( SOCKET_TIMEOUT_MILLIS ); - try + if ( socketTimeoutMillisStr != null ) { - int rmiSocketFactoryTimeoutMillis = Integer.parseInt( socketTimeoutMillisStr ); - rcsa.setRmiSocketFactoryTimeoutMillis( rmiSocketFactoryTimeoutMillis ); - log.debug( "Remote cache socket timeout " + rmiSocketFactoryTimeoutMillis + "ms." ); - } - catch ( NumberFormatException ignore ) - { - log.debug( "Remote cache socket timeout property " + SOCKET_TIMEOUT_MILLIS - + " not specified. The default will be used." ); + try + { + int rmiSocketFactoryTimeoutMillis = Integer.parseInt( socketTimeoutMillisStr ); + rcsa.setRmiSocketFactoryTimeoutMillis( rmiSocketFactoryTimeoutMillis ); + log.debug( "Remote cache socket timeout " + rmiSocketFactoryTimeoutMillis + "ms." ); + } + catch ( NumberFormatException ignore ) + { + log.debug( "Remote cache socket timeout property " + SOCKET_TIMEOUT_MILLIS + + " not specified. The default will be used." ); + } } String lccStr = prop.getProperty( REMOTE_LOCAL_CLUSTER_CONSISTENCY ); - if ( lccStr == null ) + if ( lccStr != null ) { - lccStr = "true"; + if ( lccStr == null ) + { + lccStr = "true"; + } + boolean lcc = Boolean.valueOf( lccStr ).booleanValue(); + rcsa.setLocalClusterConsistency( lcc ); } - boolean lcc = Boolean.valueOf( lccStr ).booleanValue(); - rcsa.setLocalClusterConsistency( lcc ); String acgStr = prop.getProperty( REMOTE_ALLOW_CLUSTER_GET ); - if ( acgStr == null ) + if ( acgStr != null ) { - acgStr = "true"; + if ( acgStr == null ) + { + acgStr = "true"; + } + boolean acg = Boolean.valueOf( acgStr ).booleanValue(); + rcsa.setAllowClusterGet( acg ); } - boolean acg = Boolean.valueOf( acgStr ).booleanValue(); - rcsa.setAllowClusterGet( acg ); // Register the RemoteCacheServer remote object in the registry. rcsa.setRemoteServiceName( prop.getProperty( REMOTE_CACHE_SERVICE_NAME, REMOTE_CACHE_SERVICE_VAL ).trim() ); - return rcsa; } /** Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/behavior/IRemoteCacheServerAttributes.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/behavior/IRemoteCacheServerAttributes.java?rev=697160&r1=697159&r2=697160&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/behavior/IRemoteCacheServerAttributes.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/behavior/IRemoteCacheServerAttributes.java Fri Sep 19 10:38:04 2008 @@ -205,4 +205,52 @@ * The new clusterServers value */ public void setConfigFileName( String s ); + + /** + * @param rmiSocketFactoryTimeoutMillis The rmiSocketFactoryTimeoutMillis to set. + */ + public void setRmiSocketFactoryTimeoutMillis( int rmiSocketFactoryTimeoutMillis ); + + /** + * @return Returns the rmiSocketFactoryTimeoutMillis. + */ + public int getRmiSocketFactoryTimeoutMillis(); + + /** + * Should we try to keep the registry alive + * <p> + * @param useRegistryKeepAlive the useRegistryKeepAlive to set + */ + public void setUseRegistryKeepAlive( boolean useRegistryKeepAlive ); + + /** + * Should we start the registry + * <p> + * @param startRegistry the startRegistry to set + */ + public void setStartRegistry( boolean startRegistry ); + + /** + * Should we start the registry + * <p> + * @return the startRegistry + */ + public boolean isStartRegistry(); + + /** + * Should we try to keep the registry alive + * <p> + * @return the useRegistryKeepAlive + */ + public boolean isUseRegistryKeepAlive(); + + /** + * @param registryKeepAliveDelayMillis the registryKeepAliveDelayMillis to set + */ + public void setRegistryKeepAliveDelayMillis( long registryKeepAliveDelayMillis ); + + /** + * @return the registryKeepAliveDelayMillis + */ + public long getRegistryKeepAliveDelayMillis(); } Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactoryUnitTest.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactoryUnitTest.java?rev=697160&r1=697159&r2=697160&view=diff ============================================================================== --- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactoryUnitTest.java (original) +++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactoryUnitTest.java Fri Sep 19 10:38:04 2008 @@ -37,4 +37,94 @@ // VERIFY assertEquals( "Wrong timeout", RemoteCacheServerAttributes.DEFAULT_RMI_SOCKET_FACTORY_TIMEOUT_MS, result.getRmiSocketFactoryTimeoutMillis() ); } + + /** verify that we get the registryKeepAliveDelayMillis value */ + public void testConfigureRemoteCacheServerAttributes_registryKeepAliveDelayMillisPresent() + { + // SETUP + int registryKeepAliveDelayMillis = 123245; + Properties props = new Properties(); + props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".registryKeepAliveDelayMillis", String.valueOf( registryKeepAliveDelayMillis ) ); + + // DO WORK + RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props ); + + // VERIFY + assertEquals( "Wrong registryKeepAliveDelayMillis", registryKeepAliveDelayMillis, result.getRegistryKeepAliveDelayMillis() ); + } + + /** verify that we get the useRegistryKeepAlive value */ + public void testConfigureRemoteCacheServerAttributes_useRegistryKeepAlivePresent() + { + // SETUP + boolean useRegistryKeepAlive = false; + Properties props = new Properties(); + props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".useRegistryKeepAlive", String.valueOf( useRegistryKeepAlive ) ); + + // DO WORK + RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props ); + + // VERIFY + assertEquals( "Wrong useRegistryKeepAlive", useRegistryKeepAlive, result.isUseRegistryKeepAlive() ); + } + + /** verify that we get the startRegistry value */ + public void testConfigureRemoteCacheServerAttributes_startRegistryPresent() + { + // SETUP + boolean startRegistry = false; + Properties props = new Properties(); + props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".startRegistry", String.valueOf( startRegistry ) ); + + // DO WORK + RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props ); + + // VERIFY + assertEquals( "Wrong startRegistry", startRegistry, result.isStartRegistry() ); + } + + /** verify that we get the registryKeepAliveDelayMillis value */ + public void testConfigureRemoteCacheServerAttributes_rmiSocketFactoryTimeoutMillisPresent() + { + // SETUP + int rmiSocketFactoryTimeoutMillis = 123245; + Properties props = new Properties(); + props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".rmiSocketFactoryTimeoutMillis", String.valueOf( rmiSocketFactoryTimeoutMillis ) ); + + // DO WORK + RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props ); + + // VERIFY + assertEquals( "Wrong rmiSocketFactoryTimeoutMillis", rmiSocketFactoryTimeoutMillis, result.getRmiSocketFactoryTimeoutMillis() ); + } + + /** verify that we get the startRegistry value */ + public void testConfigureRemoteCacheServerAttributes_allowClusterGetPresent() + { + // SETUP + boolean allowClusterGet = false; + Properties props = new Properties(); + props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".allowClusterGet", String.valueOf( allowClusterGet ) ); + + // DO WORK + RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props ); + + // VERIFY + assertEquals( "Wrong allowClusterGet", allowClusterGet, result.isAllowClusterGet() ); + } + + /** verify that we get the startRegistry value */ + public void testConfigureRemoteCacheServerAttributes_localClusterConsistencyPresent() + { + // SETUP + boolean localClusterConsistency = false; + Properties props = new Properties(); + props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".localClusterConsistency", String.valueOf( localClusterConsistency ) ); + + // DO WORK + RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props ); + + // VERIFY + assertEquals( "Wrong localClusterConsistency", localClusterConsistency, result.isLocalClusterConsistency() ); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]