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/04/10 17:48:22 UTC

svn commit: r392975 - in /jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote: RemoteCacheAttributes.java RemoteCacheManager.java behavior/IRemoteCacheAttributes.java server/RemoteCacheServer.java

Author: asmuts
Date: Mon Apr 10 08:48:21 2006
New Revision: 392975

URL: http://svn.apache.org/viewcvs?rev=392975&view=rev
Log:
I added the ability to not receive from the remote server. 
You might want to do this for one primary reason.  If you 
have an extremely high put low read region, then you don't want lots of chatter.  
This new setting allows you to use the remote cache as an 
easy remote store.  You can set you local memory size to 0 and then 
use the remote cache backed by mysql as a remote store.  SInce you can cluster
the remote servers, you can have MYSQL replication using JCS. . . .

Modified:
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheAttributes.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheManager.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheAttributes.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheAttributes.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheAttributes.java?rev=392975&r1=392974&r2=392975&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheAttributes.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheAttributes.java Mon Apr 10 08:48:21 2006
@@ -38,7 +38,7 @@
     private int remotePort;
 
     /**
-     * failover servers will be used by local caches one at a time. Listeners
+     * Failover servers will be used by local caches one at a time. Listeners
      * will be registered with all cluster servers. If we add a get from cluster
      * attribute we will have the ability to chain clusters and have them get
      * from each other.
@@ -70,6 +70,8 @@
 
     private int rmiSocketFactoryTimeoutMillis = DEFAULT_RMI_SOCKET_FACTORY_TIMEOUT_MILLIS;
     
+    private boolean receive = DEFAULT_RECEIVE;
+    
     /** Default constructor for the RemoteCacheAttributes object */
     public RemoteCacheAttributes()
     {
@@ -441,6 +443,36 @@
     }
 
     /**
+     * By default this option is true. If you set it to false, you will not
+     * receive updates or removes from the remote server.
+     * 
+     * @param receive 
+     */
+    public void setReceive( boolean receive )
+    {
+        this.receive = receive;
+    }
+
+    /**
+     * If RECEIVE is false then the remote cache will not register a listener
+     * with the remote server. This allows you to configure a remote server as a
+     * repository from which you can get and to which you put, but from which
+     * you do not reveive any notifications. That is, you will not receive
+     * updates or removes.
+     * <p>
+     * If you set this option to false, you should set your locl memory size to
+     * 0.
+     * <p>
+     * The remote cache manager uses this value to decide whether or not to register a listener.
+     * 
+     * @return the receive value.
+     */
+    public boolean isReceive()
+    {
+        return this.receive;
+    }
+    
+    /**
      * @return String, all the important values that can be configured
      */
     public String toString()
@@ -452,6 +484,7 @@
         buf.append( "\n cacheName = [" + this.cacheName + "]" );
         buf.append( "\n removeUponRemotePut = [" + this.removeUponRemotePut + "]" );
         buf.append( "\n getOnly = [" + getOnly + "]" );
+        buf.append( "\n receive = [" + isReceive() + "]" );
         buf.append( "\n getTimeoutMillis = [" + getGetTimeoutMillis() + "]" );
         buf.append( "\n threadPoolName = [" + getThreadPoolName() + "]" );
         buf.append( "\n remoteType = [" + remoteType + "]" );

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheManager.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheManager.java?rev=392975&r1=392974&r2=392975&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheManager.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheManager.java Mon Apr 10 08:48:21 2006
@@ -39,7 +39,7 @@
  * specific host and port. All RemoteCacheManager instances are monitored by the
  * singleton RemoteCacheMonitor monitoring daemon for error detection and
  * recovery.
- *  
+ * 
  */
 public class RemoteCacheManager
     implements AuxiliaryCacheManager
@@ -83,7 +83,7 @@
      * The cache manager listeners will need to use to get a cache.
      */
     private ICompositeCacheManager cacheMgr;
-    
+
     /**
      * Constructs an instance to with the given remote connection parameters. If
      * the connection cannot be made, "zombie" services will be temporarily used
@@ -100,7 +100,7 @@
         this.port = port;
         this.service = service;
         this.cacheMgr = cacheMgr;
-        
+
         String registry = "//" + host + ":" + port + "/" + service;
         if ( log.isDebugEnabled() )
         {
@@ -160,9 +160,26 @@
     public void addRemoteCacheListener( IRemoteCacheAttributes cattr, IRemoteCacheListener listener )
         throws IOException
     {
-        synchronized ( caches )
+        if ( cattr.isReceive() )
+        {
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "The remote cache is configured to receive events from the remote server.  "
+                    + "We will register a listener." );
+            }
+
+            synchronized ( caches )
+            {
+                remoteWatch.addCacheListener( cattr.getCacheName(), listener );
+            }
+        }
+        else
         {
-            remoteWatch.addCacheListener( cattr.getCacheName(), listener );
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "The remote cache is configured to NOT receive events from the remote server.  "
+                    + "We will NOT register a listener." );
+            }
         }
         return;
     }
@@ -199,7 +216,6 @@
     {
         synchronized ( caches )
         {
-
             RemoteCacheNoWait cache = (RemoteCacheNoWait) caches.get( cattr.getCacheName() );
             if ( cache != null )
             {
@@ -214,7 +230,18 @@
             }
             else
             {
-                log.warn( "Trying to deregister Cache Listener that was never registered." );
+                if ( cattr.isReceive() )
+                {
+                    log.warn( "Trying to deregister Cache Listener that was never registered." );
+                }
+                else
+                {
+                    if ( log.isDebugEnabled() )
+                    {
+                        log.debug( "Since the remote cache is configured to not receive, "
+                            + "there is no listener to deregister." );
+                    }
+                }
             }
         }
         return;
@@ -231,6 +258,7 @@
      * 
      * If the connection cannot be established, zombie objects will be used for
      * future recovery purposes.
+     * 
      * @param cattr
      * @param cacheMgr
      * 
@@ -286,9 +314,9 @@
         return ins;
     }
 
-
     /**
      * Returns a remote cache for the given cache name.
+     * 
      * @param cacheName
      * 
      * @return The cache value
@@ -345,9 +373,12 @@
         return c;
     }
 
-    /** Description of the Method 
+    /**
+     * Description of the Method
+     * 
      * @param name
-     * @throws IOException*/
+     * @throws IOException
+     */
     public void freeCache( String name )
         throws IOException
     {
@@ -377,8 +408,8 @@
             ICache c = (ICache) allCaches.next();
             if ( c != null )
             {
-                //need to add getStats to ICache
-                //stats.append( "<br>&nbsp;&nbsp;&nbsp;" + c.getStats() );
+                // need to add getStats to ICache
+                // stats.append( "<br>&nbsp;&nbsp;&nbsp;" + c.getStats() );
                 stats.append( c.getCacheName() );
             }
         }
@@ -414,10 +445,11 @@
         }
     }
 
-    //end release()
+    // end release()
 
     /**
      * Fixes up all the caches managed by this cache manager.
+     * 
      * @param remoteService
      * @param remoteWatch
      */
@@ -447,7 +479,7 @@
 
     /**
      * Location of the RMI registry.
-     *  
+     * 
      */
     private final static class Location
     {
@@ -470,7 +502,8 @@
         }
 
         /*
-         *  (non-Javadoc)
+         * (non-Javadoc)
+         * 
          * @see java.lang.Object#equals(java.lang.Object)
          */
         public boolean equals( Object obj )
@@ -491,10 +524,10 @@
             return host.equals( l.host ) && port == l.port;
         }
 
-        /** 
+        /**
          * 
          * @return int
-         */ 
+         */
         public int hashCode()
         {
             return host == null ? port : host.hashCode() ^ port;

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheAttributes.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheAttributes.java?rev=392975&r1=392974&r2=392975&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheAttributes.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheAttributes.java Mon Apr 10 08:48:21 2006
@@ -29,17 +29,29 @@
     /**
      * A remote cache is either a local cache or a cluster cache.
      */
-    public static int LOCAL = 0;
+    public static final int LOCAL = 0;
 
     /**
      * A remote cache is either a local cache or a cluster cache.
      */
-    public static int CLUSTER = 1;
+    public static final int CLUSTER = 1;
 
     /** The default timeout for the custom RMI socket facfory */
     public static final int DEFAULT_RMI_SOCKET_FACTORY_TIMEOUT_MILLIS = 10000;
 
     /**
+     * If RECEIVE is false then the remote cache will not register a listener
+     * with the remote server. This allows you to configure a remote server as a
+     * repository from which you can get and to which you put, but from which
+     * you do not reveive any notifications. That is, you will not receive
+     * updates or removes.
+     * <p>
+     * If you set this option to false, you should set your locl memory size to
+     * 0.
+     */
+    public static final boolean DEFAULT_RECEIVE = true;
+
+    /**
      * Gets the remoteTypeName attribute of the IRemoteCacheAttributes object
      * 
      * @return The remoteTypeName value
@@ -279,7 +291,7 @@
      * This sets a general timeout on the rmi socket factory. By default the
      * socket factory will block forever.
      * <p>
-     * We have a default setting.  The default rmi behavior should never be used.
+     * We have a default setting. The default rmi behavior should never be used.
      * 
      * @return int milliseconds
      */
@@ -292,4 +304,36 @@
      * @param rmiSocketFactoryTimeoutMillis
      */
     public abstract void setRmiSocketFactoryTimeoutMillis( int rmiSocketFactoryTimeoutMillis );
+
+    /**
+     * By default this option is true. If you set it to false, you will not
+     * receive updates or removes from the remote server.
+     * 
+     * @param receive
+     */
+    public void setReceive( boolean receive );
+
+    /**
+     * If RECEIVE is false then the remote cache will not register a listener
+     * with the remote server. This allows you to configure a remote server as a
+     * repository from which you can get and to which you put, but from which
+     * you do not reveive any notifications. That is, you will not receive
+     * updates or removes.
+     * <p>
+     * If you set this option to false, you should set your locl memory size to
+     * 0.
+     * <p>
+     * The remote cache manager uses this value to decide whether or not to
+     * register a listener.
+     * <p>
+     * It makes no sense to configure a cluster remote cache to no receive.
+     * <p>
+     * Since a non-receiving remote cache client will not register a listener,
+     * it will not have a listener id assigned from the server. As such the
+     * remote server cannot determine if it is a cluster or a normal client. It
+     * will assume that it is a normal client.
+     * 
+     * @return the receive value.
+     */
+    public boolean isReceive();
 }

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=392975&r1=392974&r2=392975&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 Mon Apr 10 08:48:21 2006
@@ -97,10 +97,10 @@
      * server with the values from the config file.
      * 
      * @param rcsa
-     * @throws RemoteException 
+     * @throws RemoteException
      * @exception IOException
      */
-    RemoteCacheServer( IRemoteCacheServerAttributes rcsa ) 
+    RemoteCacheServer( IRemoteCacheServerAttributes rcsa )
         throws RemoteException
     {
         super( rcsa.getServicePort() );
@@ -329,7 +329,8 @@
                     {
                         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 );
@@ -338,7 +339,8 @@
                     {
                         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 );
@@ -349,7 +351,8 @@
                     // swallow
                     if ( log.isInfoEnabled() )
                     {
-                        log.info( "Exception caught updating item. requesterId [" + requesterId + "] " + ce.getMessage() );
+                        log.info( "Exception caught updating item. requesterId [" + requesterId + "] "
+                            + ce.getMessage() );
                     }
                 }
 
@@ -493,6 +496,11 @@
                 + remoteTypeL );
         }
 
+        // Since a non-receiving remote cache client will not register a
+        // listener, it will not have a listener id assigned from the server. As
+        // such the remote server cannot determine if it is a cluster or a
+        // normal client. It will assume that it is a normal client.
+
         boolean fromCluster = false;
         if ( remoteTypeL != null && remoteTypeL.intValue() == IRemoteCacheAttributes.CLUSTER )
         {
@@ -526,7 +534,7 @@
         // will not result in any loops.
         //
         // This is the only instance I can think of where we allow a remote get
-        // from a remote call. The putpose is to allow remote cache servers to
+        // from a remote call. The purpose is to allow remote cache servers to
         // 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.
@@ -541,7 +549,8 @@
         else
         {
             // Gets from cluster type remote will end up here.
-            // Gets from all clients will end up here if allow cluster get is false.
+            // 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." );
@@ -613,7 +622,7 @@
 
         Integer remoteTypeL = (Integer) idTypeMap.get( new Long( requesterId ) );
         boolean fromCluster = false;
-        if ( remoteTypeL.intValue() == IRemoteCacheAttributes.CLUSTER )
+        if ( remoteTypeL != null && remoteTypeL.intValue() == IRemoteCacheAttributes.CLUSTER )
         {
             fromCluster = true;
         }
@@ -695,7 +704,7 @@
 
         Integer remoteTypeL = (Integer) idTypeMap.get( new Long( requesterId ) );
         boolean fromCluster = false;
-        if ( remoteTypeL.intValue() == IRemoteCacheAttributes.CLUSTER )
+        if ( remoteTypeL != null && remoteTypeL.intValue() == IRemoteCacheAttributes.CLUSTER )
         {
             fromCluster = true;
         }
@@ -768,7 +777,7 @@
         {
             log.info( "Dispose request received from listener [" + requesterId + "]" );
         }
-        
+
         CacheListeners cacheDesc = (CacheListeners) cacheListenersMap.get( cacheName );
 
         // this is dangerous
@@ -1003,15 +1012,15 @@
         {
             if ( log.isDebugEnabled() )
             {
-                log.debug( "Did not find queue for cache region = [" + cacheName + "] and listenerId ["
-                    + listenerId + "]" );
+                log.debug( "Did not find queue for cache region = [" + cacheName + "] and listenerId [" + listenerId
+                    + "]" );
             }
         }
 
         if ( log.isInfoEnabled() )
         {
-            log.info( "After removing listener [" + listenerId + "] cache region " + cacheName
-                + "'s listener size [" + cacheDesc.eventQMap.size() + "]");
+            log.info( "After removing listener [" + listenerId + "] cache region " + cacheName + "'s listener size ["
+                + cacheDesc.eventQMap.size() + "]" );
         }
     }
 



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