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/05/03 16:59:07 UTC

svn commit: r399324 - in /jakarta/jcs/trunk/src: java/org/apache/jcs/auxiliary/remote/ java/org/apache/jcs/auxiliary/remote/behavior/ java/org/apache/jcs/auxiliary/remote/server/ java/org/apache/jcs/utils/net/ test/org/apache/jcs/auxiliary/remote/

Author: asmuts
Date: Wed May  3 07:58:48 2006
New Revision: 399324

URL: http://svn.apache.org/viewcvs?rev=399324&view=rev
Log:
Added the client hostname to the remote listener, so we can more accurately log what clients are connecting to the remote cache

Added:
    jakarta/jcs/trunk/src/java/org/apache/jcs/utils/net/
    jakarta/jcs/trunk/src/java/org/apache/jcs/utils/net/HostNameUtil.java
Removed:
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerListener.java
Modified:
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheListener.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheListener.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientTester.java

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheListener.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheListener.java?rev=399324&r1=399323&r2=399324&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheListener.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheListener.java Wed May  3 07:58:48 2006
@@ -32,6 +32,7 @@
 import org.apache.jcs.engine.behavior.IElementSerializer;
 import org.apache.jcs.engine.control.CompositeCache;
 import org.apache.jcs.engine.control.CompositeCacheManager;
+import org.apache.jcs.utils.net.HostNameUtil;
 import org.apache.jcs.utils.serialization.SerializationConversionUtil;
 import org.apache.jcs.utils.serialization.StandardSerializer;
 
@@ -50,6 +51,8 @@
 
     private final static Log log = LogFactory.getLog( RemoteCacheListener.class );
 
+    private static String localHostName = HostNameUtil.getLocalHostAddress();
+
     /**
      * The cache manager used to put items in differnt regions. This is set
      * lazily and should not be sent to the remote server.
@@ -69,7 +72,7 @@
     protected long listenerId = 0;
 
     private transient IElementSerializer elementSerializer = new StandardSerializer();
-    
+
     /**
      * Only need one since it does work for all regions, just reference by
      * multiple region names.
@@ -216,7 +219,7 @@
                 try
                 {
                     cb = SerializationConversionUtil.getDeSerializedCacheElement( (ICacheElementSerialized) cb,
-                                                                                     this.elementSerializer );
+                                                                                  this.elementSerializer );
                     if ( log.isDebugEnabled() )
                     {
                         log.debug( "Deserialized result = " + cb );
@@ -230,8 +233,8 @@
                 {
                     log.error( "Received a serialized version of a class that we don't know about.", e );
                 }
-            }            
-            
+            }
+
             cache.localUpdate( cb );
         }
 
@@ -324,6 +327,16 @@
     }
 
     /**
+     * This is for debugging. It allows the remote server to log the address of
+     * clients.
+     */
+    public String getLocalHostAddress()
+        throws IOException
+    {
+        return localHostName;
+    }
+
+    /**
      * For easier debugging.
      * 
      * @return Basic info on this listener.
@@ -337,5 +350,4 @@
         buf.append( "\n ListenerId = " + listenerId );
         return buf.toString();
     }
-
 }

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheListener.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheListener.java?rev=399324&r1=399323&r2=399324&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheListener.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheListener.java Wed May  3 07:58:48 2006
@@ -24,7 +24,7 @@
 
 /**
  * Listens for remote cache event notification ( rmi callback ).
- *  
+ * 
  */
 public interface IRemoteCacheListener
     extends ICacheListener, Remote
@@ -63,6 +63,16 @@
      * @throws IOException
      */
     public int getRemoteType()
+        throws IOException;
+
+    /**
+     * This is for debugging. It allows the remote cache server to log the
+     * address of any listeners that regiser.
+     * 
+     * @return the local host address.
+     * @throws IOException 
+     */
+    public String getLocalHostAddress()
         throws IOException;
 
 }

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=399324&r1=399323&r2=399324&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 Wed May  3 07:58:48 2006
@@ -92,6 +92,9 @@
     /** Configuration settings. */
     protected IRemoteCacheServerAttributes rcsa;
 
+    /** The interval at which we will log updates. */
+    private int logInterval = 100;
+
     /**
      * Constructor for the RemoteCacheServer object. Thiks initializes the
      * server with the values from the config file.
@@ -125,7 +128,6 @@
             String name = list[i];
             cacheListenersMap.put( name, new CacheListeners( cacheManager.getCache( name ) ) );
         }
-
     }
 
     /**
@@ -147,7 +149,6 @@
         {
             hub.configure( prop );
         }
-
         return hub;
     }
 
@@ -277,7 +278,7 @@
         {
             // not thread safe, but it doesn't have to be accurate
             puts++;
-            if ( puts % 100 == 0 )
+            if ( puts % logInterval == 0 )
             {
                 log.info( "puts = " + puts );
             }
@@ -285,7 +286,7 @@
 
         if ( log.isDebugEnabled() )
         {
-            log.debug( "in update, put " + item.getKey() + " in " + item.getCacheName() );
+            log.debug( "In update, put " + item.getKey() + " in " + item.getCacheName() );
         }
 
         try
@@ -329,20 +330,18 @@
                     {
                         if ( log.isDebugEnabled() )
                         {
-                            log.debug( "Put FROM cluster, NOT updating other auxiliaries for region. requesterId ["
-                                + requesterId + "]" );
+                            log.debug( "Put FROM cluster, NOT updating other auxiliaries for region. "
+                                + " requesterId [" + requesterId + "]" );
                         }
-
                         c.localUpdate( item );
                     }
                     else
                     {
                         if ( log.isDebugEnabled() )
                         {
-                            log.debug( "Put NOT from cluster, updating other auxiliaries for region. requesterId ["
-                                + requesterId + "]" );
+                            log.debug( "Put NOT from cluster, updating other auxiliaries for region. "
+                                + " requesterId [" + requesterId + "]" );
                         }
-
                         c.update( item );
                     }
                 }
@@ -360,7 +359,6 @@
                 // IF LOCAL CLUSTER CONSISTENCY IS CONFIGURED
                 if ( !fromCluster || ( fromCluster && rcsa.getLocalClusterConsistency() ) )
                 {
-
                     ICacheEventQueue[] qlist = getEventQList( cacheDesc, requesterId );
 
                     if ( qlist != null )
@@ -538,6 +536,7 @@
         // talk to each other. If one goes down, you want it to be able to get
         // data from those that were up when the failed server comes back o
         // line.
+
         if ( !fromCluster && this.rcsa.getAllowClusterGet() )
         {
             if ( log.isDebugEnabled() )
@@ -551,6 +550,7 @@
             // Gets from cluster type remote will end up here.
             // Gets from all clients will end up here if allow cluster get is
             // false.
+
             if ( log.isDebugEnabled() )
             {
                 log.debug( "Allowing a get from other auxiliaries for the region." );
@@ -854,6 +854,9 @@
 
     /**
      * Subscribes to the specified remote cache.
+     * <p>
+     * If the client id is 0, then the remote cache server will increment it's
+     * local count and assign an id to the client.
      * 
      * @param cacheName
      *            the specified remote cache.
@@ -872,15 +875,18 @@
         CacheListeners cacheDesc;
 
         IRemoteCacheListener ircl = (IRemoteCacheListener) listener;
+
+        String listenerAddress = ircl.getLocalHostAddress();
+
         int remoteType = ircl.getRemoteType();
         if ( remoteType == IRemoteCacheAttributes.CLUSTER )
         {
-            log.debug( "adding cluster listener" );
+            log.debug( "adding cluster listener, listenerAddress [" + listenerAddress + "]" );
             cacheDesc = getClusterListeners( cacheName );
         }
         else
         {
-            log.debug( "adding normal listener" );
+            log.debug( "adding normal listener, listenerAddress [" + listenerAddress + "]" );
             cacheDesc = getCacheListeners( cacheName );
         }
         Map eventQMap = cacheDesc.eventQMap;
@@ -900,7 +906,8 @@
                     long listenerIdB = nextListenerId();
                     if ( log.isDebugEnabled() )
                     {
-                        log.debug( "listener id=" + ( listenerIdB & 0xff ) + " addded for cache " + cacheName );
+                        log.debug( "listener id=" + ( listenerIdB & 0xff ) + " addded for cache [" + cacheName
+                            + "], listenerAddress [" + listenerAddress + "]" );
                     }
                     listener.setListenerId( listenerIdB );
                     id = listenerIdB;
@@ -908,14 +915,16 @@
                     // in case it needs synchronization
                     if ( log.isInfoEnabled() )
                     {
-                        log.info( "adding vm listener under new id = " + listenerIdB );
+                        log.info( "adding vm listener under new id = [" + listenerIdB + "], listenerAddress ["
+                            + listenerAddress + "]" );
                     }
                 }
                 else
                 {
                     if ( log.isInfoEnabled() )
                     {
-                        log.info( "adding listener under existing id = " + id );
+                        log.info( "adding listener under existing id = [" + id + "], listenerAddress ["
+                            + listenerAddress + "]" );
                     }
                     // should confirm the the host is the same as we have on
                     // record, just in case
@@ -927,7 +936,7 @@
             }
             catch ( IOException ioe )
             {
-                log.error( "Problem setting listener id.", ioe );
+                log.error( "Problem setting listener id, listenerAddress [" + listenerAddress + "]", ioe );
             }
 
             CacheEventQueueFactory fact = new CacheEventQueueFactory();
@@ -936,9 +945,9 @@
 
             eventQMap.put( new Long( listener.getListenerId() ), q );
 
-            if ( log.isDebugEnabled() )
+            if ( log.isInfoEnabled() )
             {
-                log.debug( "****** Cache " + cacheName + "'s listener size=" + cacheDesc.eventQMap.size() );
+                log.info( "Region " + cacheName + "'s listener size = " + cacheDesc.eventQMap.size() );
             }
         }
         // end sync
@@ -962,7 +971,7 @@
 
             if ( log.isDebugEnabled() )
             {
-                log.debug( "adding listener for cache " + cacheName );
+                log.debug( "Adding listener for cache [" + cacheName + "]" );
             }
         }
         return;
@@ -981,7 +990,8 @@
     }
 
     /**
-     * Unsibscribe this region.
+     * Unsibscribe this listener from this region. If the listener is
+     * registered, it will be removed from the event queue map list.
      * 
      * @param cacheName
      * @param listenerId
@@ -1088,7 +1098,10 @@
     // TODO: test out the DGC.
     public void unreferenced()
     {
-        log.debug( "*** Warning: Server now unreferenced and subject to GC. ***" );
+        if ( log.isInfoEnabled() )
+        {
+            log.info( "*** Server now unreferenced and subject to GC. ***" );
+        }
     }
 
     /**
@@ -1120,7 +1133,8 @@
                 id = ++listenerId[0];
             }
         }
-        return id; // ( long ) ( id & 0xff );
+        // ( long ) ( id & 0xff );
+        return id;
     }
 
     /**

Added: jakarta/jcs/trunk/src/java/org/apache/jcs/utils/net/HostNameUtil.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/net/HostNameUtil.java?rev=399324&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/utils/net/HostNameUtil.java (added)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/utils/net/HostNameUtil.java Wed May  3 07:58:48 2006
@@ -0,0 +1,44 @@
+package org.apache.jcs.utils.net;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Simple utility for getting hte local host name.
+ * 
+ * @author Aaron Smuts
+ * 
+ */
+public class HostNameUtil
+{
+    private final static Log log = LogFactory.getLog( HostNameUtil.class );
+
+    /**
+     * Gets the address for the local machine.
+     * 
+     * 
+     * @return InetAddress.getLocalHost().getHostAddress(), or unknown if there
+     *         is an error.
+     */
+    public static String getLocalHostAddress()
+    {
+        String hostAddress = "unknown";
+        try
+        {
+            // todo, you should be able to set this
+            hostAddress = InetAddress.getLocalHost().getHostAddress();
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "hostAddress = [" + hostAddress + "]" );
+            }
+        }
+        catch ( UnknownHostException e1 )
+        {
+            log.error( "Couldn't get localhost address", e1 );
+        }
+        return hostAddress;
+    }
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientTester.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientTester.java?rev=399324&r1=399323&r2=399324&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientTester.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientTester.java Wed May  3 07:58:48 2006
@@ -299,4 +299,11 @@
     {
         System.out.println( s );
     }
+
+    public String getLocalHostAddress()
+        throws IOException
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org