You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by as...@apache.org on 2006/02/24 02:07:33 UTC
svn commit: r380290 - in /jakarta/jcs/trunk/src:
java/org/apache/jcs/auxiliary/remote/
java/org/apache/jcs/auxiliary/remote/server/
test/org/apache/jcs/auxiliary/remote/
Author: asmuts
Date: Thu Feb 23 17:07:31 2006
New Revision: 380290
URL: http://svn.apache.org/viewcvs?rev=380290&view=rev
Log:
improved logging in remote cache server.
Added:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteUtilsUnitTest.java
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteUtils.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactory.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteUtils.java?rev=380290&r1=380289&r2=380290&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteUtils.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteUtils.java Thu Feb 23 17:07:31 2006
@@ -16,15 +16,12 @@
* limitations under the License.
*/
-import java.io.InputStream;
import java.io.IOException;
-
-import java.rmi.RemoteException;
+import java.io.InputStream;
import java.rmi.RMISecurityManager;
-
+import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
-
import java.util.Enumeration;
import java.util.Properties;
@@ -32,8 +29,9 @@
import org.apache.commons.logging.LogFactory;
/**
- * Description of the Class
- *
+ * This class provides some basic utilities for doing things such as starting
+ * the registry properly.
+ *
*/
public class RemoteUtils
{
@@ -47,6 +45,7 @@
/**
* Creates and exports a registry on the specified port of the local host.
+ *
* @param port
* @return
* @throws RemoteException
@@ -54,22 +53,36 @@
public static int createRegistry( int port )
throws RemoteException
{
- log.debug( "createRegistry> setting security manager" );
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "createRegistry> setting security manager" );
+ }
System.setSecurityManager( new RMISecurityManager() );
+
if ( port < 1024 )
{
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "Port chosen was less than 1024, will use default [" + Registry.REGISTRY_PORT + "] instead." );
+ }
port = Registry.REGISTRY_PORT;
}
- log.debug( "createRegistry> creating registry" );
+
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "createRegistry> creating registry on port [" + port + "]" );
+ }
LocateRegistry.createRegistry( port );
return port;
}
- /**
+ /**
* Loads properties for the named props file.
+ *
* @param propFile
* @return
- * @throws IOException*/
+ * @throws IOException
+ */
public static Properties loadProps( String propFile )
throws IOException
{
@@ -105,7 +118,6 @@
}
catch ( Exception ex )
{
-
log.error( "Error loading remote properties, for file name [" + propFile + "]", ex );
// ignore;
}
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java?rev=380290&r1=380289&r2=380290&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java Thu Feb 23 17:07:31 2006
@@ -59,7 +59,7 @@
* several clients to use one remote server and several to use another. The get
* locad will be distributed between the two servers. Since caches are usually
* high get and low put, this should allow you to scale.
- *
+ *
*/
public class RemoteCacheServer
extends UnicastRemoteObject
@@ -85,10 +85,10 @@
// relates listener id with a type
private final Hashtable idTypeMap = new Hashtable();
- //private transient int listenerId = 0;
+ // private transient int listenerId = 0;
private int[] listenerId = new int[1];
- /** Description of the Field */
+ /** Configuration settings. */
protected IRemoteCacheServerAttributes rcsa;
/**
@@ -212,7 +212,7 @@
return cacheListeners;
}
- /////////////////////// Implements the ICacheService interface.
+ // ///////////////////// Implements the ICacheService interface.
// //////////////////
/**
* Puts a cache bean to the remote cache and notifies all listeners which
@@ -225,7 +225,7 @@
*
* @param item
* @throws IOException
- *
+ *
*/
public void put( ICacheElement item )
throws IOException
@@ -322,10 +322,8 @@
CompositeCache c = (CompositeCache) cacheDesc.cache;
// If the source of this request was not from a cluster,
- // then
- // consider it a local update. The cache manager will try to
- // update all
- // auxiliaries.
+ // then consider it a local update. The cache manager will try to
+ // update all auxiliaries.
//
// This requires that two local caches not be connected to
// two clustered remote caches. The failover runner will
@@ -390,7 +388,7 @@
}
catch ( NotBoundException ex )
{
- ex.printStackTrace( System.out );
+ log.error( "NotBoundException caught in update.", ex );
throw new IllegalStateException( ex.getMessage() );
}
catch ( Exception e )
@@ -451,6 +449,7 @@
// All qualified.
return list;
}
+
// Returns only the qualified.
ICacheEventQueue[] qq = new ICacheEventQueue[count];
count = 0;
@@ -488,7 +487,7 @@
}
catch ( Exception e )
{
- log.error( e );
+ log.error( "Problem getting listeners.", e );
}
if ( cacheDesc == null )
@@ -516,7 +515,7 @@
}
catch ( Exception e )
{
- log.error( e );
+ log.error( "Problem getting listeners.", e );
}
if ( cacheDesc == null )
@@ -606,7 +605,6 @@
if ( !fromCluster || ( fromCluster && rcsa.getLocalClusterConsistency() ) )
{
-
ICacheEventQueue[] qlist = getEventQList( cacheDesc, requesterId );
for ( int i = 0; i < qlist.length; i++ )
@@ -656,7 +654,6 @@
// notification.
synchronized ( cacheDesc )
{
-
// No need to broadcast, or notify if it was not cached.
CompositeCache c = (CompositeCache) cacheDesc.cache;
@@ -687,7 +684,6 @@
{
qlist[i].addRemoveAllEvent();
}
-
}
}
}
@@ -761,10 +757,10 @@
return;
}
- /////////////////////// Implements the ICacheObserver interface.
+ // ///////////////////// Implements the ICacheObserver interface.
// //////////////////
/**
- * Removes dead event queues. SHould clean out deregistered listeners.
+ * Removes dead event queues. Should clean out deregistered listeners.
*
* @param eventQMap
*/
@@ -810,9 +806,7 @@
try
{
CacheListeners cacheDesc;
- //if ( cacheName.equals("SYSTEM_CLUSTER") || listener instanceof
- // org.apache.jcs.auxiliary.remote.server.RemoteCacheServerListener
- // ) {
+
IRemoteCacheListener ircl = (IRemoteCacheListener) listener;
int remoteType = ircl.getRemoteType();
if ( remoteType == IRemoteCacheAttributes.CLUSTER )
@@ -827,8 +821,8 @@
}
Map eventQMap = cacheDesc.eventQMap;
cleanupEventQMap( eventQMap );
-
- //synchronized ( listenerId )
+
+ // synchronized ( listenerId )
synchronized ( ICacheListener.class )
{
long id = 0;
@@ -846,13 +840,20 @@
}
listener.setListenerId( listenerIdB );
id = listenerIdB;
+
// in case it needs synchronization
- log.info( "adding vm listener under new id = " + listenerIdB );
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "adding vm listener under new id = " + listenerIdB );
+ }
print( "adding vm listener under new id = " + listenerIdB );
}
else
{
- log.info( "adding listener under existing id = " + id );
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "adding listener under existing id = " + id );
+ }
// should confirm the the host is the same as we have on
// record, just in case
// a client has made a mistake.
@@ -864,7 +865,7 @@
}
catch ( IOException ioe )
{
- log.error( "Problem setting listener id", ioe );
+ log.error( "Problem setting listener id.", ioe );
}
CacheEventQueueFactory fact = new CacheEventQueueFactory();
@@ -972,6 +973,7 @@
}
catch ( NotBoundException ex )
{
+ log.error( "NotBoundException", ex );
ex.printStackTrace();
throw new IllegalStateException( ex.getMessage() );
}
@@ -999,7 +1001,7 @@
return;
}
- /////////////////////// Implements the ICacheServiceAdmin interface.
+ // ///////////////////// Implements the ICacheServiceAdmin interface.
// //////////////////
/**
@@ -1023,11 +1025,14 @@
public void shutdown( String host, int port )
throws IOException
{
- log.debug( "received shutdown request" );
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "Received shutdown request. Shutting down server." );
+ }
RemoteCacheServerFactory.shutdownImpl( host, port );
}
- /////////////////////// Implements the Unreferenced interface.
+ // ///////////////////// Implements the Unreferenced interface.
// //////////////////
/**
@@ -1070,7 +1075,7 @@
id = ++listenerId[0];
}
}
- return id; //( long ) ( id & 0xff );
+ return id; // ( long ) ( id & 0xff );
}
/**
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactory.java?rev=380290&r1=380289&r2=380290&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 Thu Feb 23 17:07:31 2006
@@ -43,7 +43,7 @@
private static String serviceName;
- /** Constructor for the RemoteCacheServerFactory object */
+ /** Constructor for the RemoteCacheServerFactory object. */
private RemoteCacheServerFactory()
{
super();
@@ -248,11 +248,6 @@
try
{
- //if ( args.length > 1 )
- //{
- // port = Integer.parseInt( args[1] );
- //}
-
String serviceName = prop.getProperty( REMOTE_CACHE_SERVICE_NAME, REMOTE_CACHE_SERVICE_VAL ).trim();
String registry = "//:" + port + "/" + serviceName;
log.debug( "looking up server " + registry );
Added: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteUtilsUnitTest.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteUtilsUnitTest.java?rev=380290&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteUtilsUnitTest.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteUtilsUnitTest.java Thu Feb 23 17:07:31 2006
@@ -0,0 +1,49 @@
+package org.apache.jcs.auxiliary.remote;
+
+import java.rmi.RemoteException;
+
+import junit.framework.TestCase;
+
+/**
+ * Simple tests for remote utils. It is difficult to verify most of the things is does.
+ *
+ * @author Aaron Smuts
+ *
+ */
+public class RemoteUtilsUnitTest
+ extends TestCase
+{
+
+ /**
+ * Call create registry twice.
+ *
+ * <p>
+ * The exception is in the security manager setting.
+ *
+ */
+ public void testCreateRegistryTwice()
+ {
+ try
+ {
+ RemoteUtils.createRegistry( 1102 );
+ }
+ catch ( RemoteException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ try
+ {
+ RemoteUtils.createRegistry( 1102 );
+ }
+ catch ( Exception e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java?rev=380290&r1=380289&r2=380290&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java Thu Feb 23 17:07:31 2006
@@ -33,7 +33,6 @@
RemoteUtils.createRegistry( 1101 );
RemoteCacheServerFactory.startup( "localhost", 1101, "/TestRemoteServer.ccf" );
-
}
catch ( Exception e )
{
---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org