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 2008/08/14 00:14:48 UTC

svn commit: r685702 [2/5] - in /jakarta/jcs/trunk: ./ src/java/org/apache/jcs/auxiliary/ src/java/org/apache/jcs/auxiliary/disk/ src/java/org/apache/jcs/auxiliary/disk/block/ src/java/org/apache/jcs/auxiliary/disk/indexed/ src/java/org/apache/jcs/auxil...

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java?rev=685702&r1=685701&r2=685702&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java Wed Aug 13 15:14:46 2008
@@ -41,6 +41,7 @@
 import org.apache.jcs.engine.CacheConstants;
 import org.apache.jcs.engine.behavior.ICacheElement;
 import org.apache.jcs.engine.behavior.ICacheElementSerialized;
+import org.apache.jcs.engine.behavior.ICacheEventLogger;
 import org.apache.jcs.engine.behavior.IElementAttributes;
 import org.apache.jcs.engine.behavior.IElementSerializer;
 import org.apache.jcs.engine.behavior.IZombie;
@@ -72,6 +73,7 @@
 
     private IRemoteCacheAttributes irca;
 
+    /** This is a handle on the remote server. In zombie mode it is replaced with a balking facade. */
     private IRemoteCacheService remote;
 
     private IRemoteCacheListener listener;
@@ -82,8 +84,12 @@
 
     private boolean usePoolForGet = false;
 
+    /** The object serializer */
     private IElementSerializer elementSerializer = new StandardSerializer();
 
+    /** An optional event logger */
+    private ICacheEventLogger cacheEventLogger;
+
     /**
      * Constructor for the RemoteCache object. This object communicates with a remote cache server.
      * One of these exists for each region. This also holds a reference to a listener. The same
@@ -157,7 +163,7 @@
         catch ( Exception e )
         {
             // TODO change this so that we only try to do it once. Otherwise we
-            // genreate errors for each region on construction.
+            // Generate errors for each region on construction.
             log.info( e.getMessage() );
         }
     }
@@ -187,47 +193,65 @@
      * byte array is wrapped in a ICacheElementSerialized. This allows the remote server to operate
      * without any knowledge of caches classes.
      * <p>
-     * (non-Javadoc)
-     * @see org.apache.jcs.engine.behavior.ICache#update(org.apache.jcs.engine.behavior.ICacheElement)
+     * @param ce
+     * @throws IOException
      */
     public void update( ICacheElement ce )
         throws IOException
     {
-        if ( true )
+        logEventStart( ce, ICacheEventLogger.UPDATE_EVENT );
+        try
         {
-            if ( !this.irca.getGetOnly() )
+            processUpdate( ce );
+        }
+        finally
+        {
+            logEventFinish( ce, ICacheEventLogger.UPDATE_EVENT );
+        }
+    }
+
+    /**
+     * Serializes the object and then calls update on the remote server with the byte array. The
+     * byte array is wrapped in a ICacheElementSerialized. This allows the remote server to operate
+     * without any knowledge of caches classes.
+     * <p>
+     * @param ce
+     * @throws IOException
+     */
+    private void processUpdate( ICacheElement ce )
+        throws IOException
+    {
+        if ( !this.irca.getGetOnly() )
+        {
+            ICacheElementSerialized serialized = null;
+            try
             {
-                ICacheElementSerialized serialized = null;
-                try
+                if ( log.isDebugEnabled() )
                 {
-                    if ( log.isDebugEnabled() )
-                    {
-                        log.debug( "sending item to remote server" );
-                    }
+                    log.debug( "sending item to remote server" );
+                }
 
-                    // convert so we don't have to know about the object on the
-                    // other end.
-                    serialized = SerializationConversionUtil.getSerializedCacheElement( ce, this.elementSerializer );
+                // convert so we don't have to know about the object on the
+                // other end.
+                serialized = SerializationConversionUtil.getSerializedCacheElement( ce, this.elementSerializer );
 
-                    remote.update( serialized, getListenerId() );
-                }
-                catch ( NullPointerException npe )
-                {
-                    log.error( "npe for ce = " + ce + "ce.attr = " + ce.getElementAttributes(), npe );
-                    return;
-                }
-                catch ( Exception ex )
-                {
-                    // event queue will wait and retry
-                    handleException( ex, "Failed to put [" + ce.getKey() + "] to " + ce.getCacheName() );
-                }
+                remote.update( serialized, getListenerId() );
             }
-            else
+            catch ( NullPointerException npe )
             {
-                if ( log.isDebugEnabled() )
-                {
-                    log.debug( "get only mode, not sending to remote server" );
-                }
+                log.error( "npe for ce = " + ce + "ce.attr = " + ce.getElementAttributes(), npe );
+            }
+            catch ( Exception ex )
+            {
+                // event queue will wait and retry
+                handleException( ex, "Failed to put [" + ce.getKey() + "] to " + ce.getCacheName() );
+            }
+        }
+        else
+        {
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "get only mode, not sending to remote server" );
             }
         }
     }
@@ -237,8 +261,8 @@
      * <p>
      * Use threadpool to timeout if a value is set for GetTimeoutMillis
      * <p>
-     * If we are a cluster client, we need to leave the Element in its serilaized form. Cluster
-     * cients cannot deserialize objects. Cluster clients get ICacheElementSerialized objects from
+     * If we are a cluster client, we need to leave the Element in its serialized form. Cluster
+     * clients cannot deserialize objects. Cluster clients get ICacheElementSerialized objects from
      * other remote servers.
      * <p>
      * @param key
@@ -249,7 +273,34 @@
         throws IOException
     {
         ICacheElement retVal = null;
+        logEventStart( cacheName, key, ICacheEventLogger.GET_EVENT );
+        try
+        {
+            retVal = processGet( key, retVal );
+        }
+        finally
+        {
+            logEventFinish( retVal, ICacheEventLogger.GET_EVENT );
+        }
+        return retVal;
+    }
 
+    /**
+     * Synchronously get from the remote cache; if failed, replace the remote handle with a zombie.
+     * <p>
+     * Use threadpool to timeout if a value is set for GetTimeoutMillis
+     * <p>
+     * If we are a cluster client, we need to leave the Element in its serialized form. Cluster
+     * clients cannot deserialize objects. Cluster clients get ICacheElementSerialized objects from
+     * other remote servers.
+     * <p>
+     * @param key
+     * @return ICacheElement, a wrapper around the key, value, and attributes
+     * @throws IOException
+     */
+    private ICacheElement processGet( Serializable key, ICacheElement retVal )
+        throws IOException
+    {
         try
         {
             if ( usePoolForGet )
@@ -278,7 +329,6 @@
         {
             handleException( ex, "Failed to get [" + key + "] from [" + cacheName + "]" );
         }
-
         return retVal;
     }
 
@@ -286,14 +336,35 @@
      * Gets multiple items from the cache based on the given set of keys.
      * <p>
      * @param keys
-     * @return a map of Serializable key to ICacheElement element, or an empty map if there is no data in cache for any of these keys
-     * @throws IOException 
+     * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+     *         data in cache for any of these keys
+     * @throws IOException
      */
     public Map getMultiple( Set keys )
         throws IOException
     {
-        Map elements = new HashMap();
+        logEventStart( cacheName, (Serializable) keys, ICacheEventLogger.GETMULTIPLE_EVENT );
+        try
+        {
+            return processGetMultiple( keys );
+        }
+        finally
+        {
+            logEventEnd( cacheName, (Serializable) keys, ICacheEventLogger.GETMULTIPLE_EVENT );
+        }
+    }
 
+    /**
+     * Gets multiple items from the cache based on the given set of keys.
+     * <p>
+     * @param keys
+     * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+     *         data in cache for any of these keys
+     */
+    private Map processGetMultiple( Set keys )
+        throws IOException
+    {
+        Map elements = new HashMap();
         if ( keys != null && !keys.isEmpty() )
         {
             Iterator iterator = keys.iterator();
@@ -310,7 +381,6 @@
                 }
             }
         }
-
         return elements;
     }
 
@@ -398,23 +468,43 @@
     public boolean remove( Serializable key )
         throws IOException
     {
-        if ( true )
+        logEventStart( cacheName, key, ICacheEventLogger.REMOVE_EVENT );
+        try
         {
-            if ( !this.irca.getGetOnly() )
+            return processRemove( key );
+        }
+        finally
+        {
+            logEventEnd( cacheName, key, ICacheEventLogger.REMOVE_EVENT );
+        }
+    }
+
+    /**
+     * Synchronously remove from the remote cache; if failed, replace the remote handle with a
+     * zombie.
+     * <p>
+     * @param key
+     * @return boolean, whether or not the item was removed
+     * @throws IOException
+     */
+    private boolean processRemove( Serializable key )
+        throws IOException
+    {
+        if ( !this.irca.getGetOnly() )
+        {
+            if ( log.isDebugEnabled() )
             {
-                if ( log.isDebugEnabled() )
-                {
-                    log.debug( "remove> key=" + key );
-                }
-                try
-                {
-                    remote.remove( cacheName, key, getListenerId() );
-                }
-                catch ( Exception ex )
-                {
-                    handleException( ex, "Failed to remove " + key + " from " + cacheName );
-                }
+                log.debug( "remove> key=" + key );
+            }
+            try
+            {
+                remote.remove( cacheName, key, getListenerId() );
+            }
+            catch ( Exception ex )
+            {
+                handleException( ex, "Failed to remove " + key + " from " + cacheName );
             }
+            return true;
         }
         return false;
     }
@@ -428,7 +518,8 @@
     public void removeAll()
         throws IOException
     {
-        if ( true )
+        logEventStart( cacheName, "all", ICacheEventLogger.REMOVEALL_EVENT );
+        try
         {
             if ( !this.irca.getGetOnly() )
             {
@@ -442,6 +533,10 @@
                 }
             }
         }
+        finally
+        {
+            logEventEnd( cacheName, "all", ICacheEventLogger.REMOVEALL_EVENT );
+        }
     }
 
     /**
@@ -452,18 +547,26 @@
     public void dispose()
         throws IOException
     {
-        if ( log.isInfoEnabled() )
-        {
-            log.info( "Disposing of remote cache" );
-        }
+        logEventStart( cacheName, "none", ICacheEventLogger.DISPOSE_EVENT );
         try
         {
-            listener.dispose();
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "Disposing of remote cache" );
+            }
+            try
+            {
+                listener.dispose();
+            }
+            catch ( Exception ex )
+            {
+                log.error( "Couldn't dispose", ex );
+                handleException( ex, "Failed to dispose [" + cacheName + "]" );
+            }
         }
-        catch ( Exception ex )
+        finally
         {
-            log.error( "Couldn't dispose", ex );
-            handleException( ex, "Failed to dispose [" + cacheName + "]" );
+            logEventEnd( cacheName, "none", ICacheEventLogger.DISPOSE_EVENT );
         }
     }
 
@@ -501,7 +604,7 @@
 
         se = new StatElement();
         se.setName( "Remote Host:Port" );
-        se.setData( this.irca.getRemoteHost() + ":" + this.irca.getRemotePort() );
+        se.setData( getIPAddressForService() );
         elems.add( se );
 
         se = new StatElement();
@@ -578,9 +681,8 @@
     }
 
     /**
-     * Replaces the current remote cache service handle with the given handle.
-     * If the current remote is a Zombie, the propagate teh events that may be
-     * queued to the restored service.
+     * Replaces the current remote cache service handle with the given handle. If the current remote
+     * is a Zombie, the propagate teh events that may be queued to the restored service.
      * <p>
      * @param remote IRemoteCacheService -- the remote server or proxy to the remote server
      */
@@ -624,7 +726,8 @@
     private void handleException( Exception ex, String msg )
         throws IOException
     {
-        log.error( "Disabling remote cache due to error: " + msg, ex );
+        String message = "Disabling remote cache due to error: " + msg;
+        log.error( message, ex );
 
         // we should not switch if the existing is a zombie.
         if ( remote == null || !( remote instanceof ZombieRemoteCacheService ) )
@@ -673,9 +776,10 @@
     }
 
     /**
-     * let the remote cache set a listener_id. Since there is only one listerenr for all the regions
+     * let the remote cache set a listener_id. Since there is only one listener for all the regions
      * and every region gets registered? the id shouldn't be set if it isn't zero. If it is we
      * assume that it is a reconnect.
+     * <p>
      * @param id The new listenerId value
      */
     public void setListenerId( long id )
@@ -718,7 +822,7 @@
 
     /**
      * Allows other member of this package to access the listerner. This is mainly needed for
-     * deregistering alistener.
+     * deregistering a listener.
      * <p>
      * @return IRemoteCacheListener, the listener for this remote server
      */
@@ -728,11 +832,16 @@
     }
 
     /**
+     * Never sets to null;
+     * <p>
      * @param elementSerializer The elementSerializer to set.
      */
     public void setElementSerializer( IElementSerializer elementSerializer )
     {
-        this.elementSerializer = elementSerializer;
+        if ( elementSerializer != null )
+        {
+            this.elementSerializer = elementSerializer;
+        }
     }
 
     /**
@@ -744,11 +853,103 @@
     }
 
     /**
+     * Allows it to be injected.
+     * <p>
+     * @param cacheEventLogger
+     */
+    public void setCacheEventLogger( ICacheEventLogger cacheEventLogger )
+    {
+        this.cacheEventLogger = cacheEventLogger;
+    }
+
+    /**
      * Debugging info.
+     * <p>
      * @return basic info about the RemoteCache
      */
     public String toString()
     {
         return "RemoteCache: " + cacheName + " attributes = " + irca;
     }
+
+    /**
+     * Logs an event if an event logger is configured.
+     * <p>
+     * @param item
+     * @param requesterId
+     */
+    private void logEventStart( ICacheElement item, String eventName )
+    {
+        if ( cacheEventLogger != null )
+        {
+            String ipAddress = getIPAddressForService();
+            cacheEventLogger.logStartICacheEvent( "RemoteCacheClient", item.getCacheName(), eventName, ipAddress, item );
+        }
+    }
+
+    /**
+     * Logs an event if an event logger is configured.
+     * <p>
+     * @param cacheName
+     * @param key
+     * @param requesterId
+     */
+    private void logEventStart( String cacheName, Serializable key, String eventName )
+    {
+        if ( cacheEventLogger != null )
+        {
+            String ipAddress = getIPAddressForService();
+            cacheEventLogger.logStartICacheEvent( "RemoteCacheClient", cacheName, eventName, ipAddress, key );
+        }
+    }
+
+    /**
+     * Logs an event if an event logger is configured.
+     * <p>
+     * @param item
+     * @param requesterId
+     */
+    private void logEventFinish( ICacheElement item, String eventName )
+    {
+        if ( cacheEventLogger != null )
+        {
+            String ipAddress = getIPAddressForService();
+            String cacheName = null;
+            if ( item != null )
+            {
+                cacheName = item.getCacheName();
+            }
+            cacheEventLogger.logEndICacheEvent( "RemoteCacheClient", cacheName, eventName, ipAddress, item );
+        }
+    }
+
+    /**
+     * Logs an event if an event logger is configured.
+     * <p>
+     * @param cacheName
+     * @param key
+     * @param requesterId
+     */
+    private void logEventEnd( String cacheName, Serializable key, String eventName )
+    {
+        if ( cacheEventLogger != null )
+        {
+            String ipAddress = getIPAddressForService();
+            cacheEventLogger.logEndICacheEvent( "RemoteCacheClient", cacheName, eventName, ipAddress, key );
+        }
+    }
+
+    /**
+     * Ip address for the service, if one is stored.
+     * <p>
+     * Protected for testing.
+     * <p>
+     * @param requesterId
+     * @return String
+     */
+    protected String getIPAddressForService()
+    {
+        String ipAddress = this.irca.getRemoteHost() + ":" + this.irca.getRemotePort();
+        return ipAddress;
+    }
 }

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheAttributes.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheAttributes.java?rev=685702&r1=685701&r2=685702&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 Wed Aug 13 15:14:46 2008
@@ -31,12 +31,16 @@
     extends AbstractAuxiliaryCacheAttributes
     implements IRemoteCacheAttributes
 {
+    /** Don't change */
     private static final long serialVersionUID = -1555143736942374000L;
 
+    /** The service name */
     private String remoteServiceName = IRemoteCacheConstants.REMOTE_CACHE_SERVICE_VAL;
 
+    /** server host */
     private String remoteHost;
 
+    /** server port */
     private int remotePort;
 
     /**
@@ -176,9 +180,8 @@
         this.remoteType = p;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.jcs.auxiliary.AuxiliaryCacheAttributes#copy()
+    /**
+     * @return AuxiliaryCacheAttributes
      */
     public AuxiliaryCacheAttributes copy()
     {
@@ -371,36 +374,32 @@
         this.localClusterConsistency = r;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes#getThreadPoolName()
+    /**
+     * @return the name of the pool
      */
     public String getThreadPoolName()
     {
         return threadPoolName;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes#setThreadPoolName(java.lang.String)
+    /**
+     * @param name
      */
     public void setThreadPoolName( String name )
     {
         threadPoolName = name;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes#getGetTimeoutMillis()
+    /**
+     * @return getTimeoutMillis
      */
     public int getGetTimeoutMillis()
     {
         return getTimeoutMillis;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes#setGetTimeoutMillis(int)
+    /**
+     * @param millis
      */
     public void setGetTimeoutMillis( int millis )
     {
@@ -492,5 +491,4 @@
         buf.append( "\n zombieQueueMaxSize = [" + getZombieQueueMaxSize() + "]" );
         return buf.toString();
     }
-
 }

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFactory.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFactory.java?rev=685702&r1=685701&r2=685702&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFactory.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFactory.java Wed Aug 13 15:14:46 2008
@@ -29,7 +29,9 @@
 import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
 import org.apache.jcs.auxiliary.AuxiliaryCacheFactory;
 import org.apache.jcs.engine.behavior.ICache;
+import org.apache.jcs.engine.behavior.ICacheEventLogger;
 import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+import org.apache.jcs.engine.behavior.IElementSerializer;
 
 /**
  * The RemoteCacheFactory creates remote caches for the cache hub. It returns a no wait facade which
@@ -53,11 +55,14 @@
      * will get a cache from the manager. When the primary is restored it will tell the manager for
      * the failover to deregister the listener.
      * <p>
-     * (non-Javadoc)
-     * @see org.apache.jcs.auxiliary.AuxiliaryCacheFactory#createCache(org.apache.jcs.auxiliary.AuxiliaryCacheAttributes,
-     *      org.apache.jcs.engine.behavior.ICompositeCacheManager)
+     * @param iaca 
+     * @param cacheMgr 
+     * @param cacheEventLogger 
+     * @param elementSerializer 
+     * @return AuxiliaryCache
      */
-    public AuxiliaryCache createCache( AuxiliaryCacheAttributes iaca, ICompositeCacheManager cacheMgr )
+    public AuxiliaryCache createCache( AuxiliaryCacheAttributes iaca, ICompositeCacheManager cacheMgr,
+                                       ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
     {
         RemoteCacheAttributes rca = (RemoteCacheAttributes) iaca;
 
@@ -66,7 +71,7 @@
         // if LOCAL
         if ( rca.getRemoteType() == RemoteCacheAttributes.LOCAL )
         {
-            // a list toi be turned into an array of failover server information
+            // a list to be turned into an array of failover server information
             ArrayList failovers = new ArrayList();
 
             // not necessary if a failover list is defined
@@ -79,7 +84,7 @@
 
                 failovers.add( rca.getRemoteHost() + ":" + rca.getRemotePort() );
 
-                RemoteCacheManager rcm = RemoteCacheManager.getInstance( rca, cacheMgr );
+                RemoteCacheManager rcm = RemoteCacheManager.getInstance( rca, cacheMgr, cacheEventLogger, elementSerializer );
                 ICache ic = rcm.getCache( rca );
                 if ( ic != null )
                 {
@@ -106,7 +111,7 @@
 
                     rca.setRemoteHost( server.substring( 0, server.indexOf( ":" ) ) );
                     rca.setRemotePort( Integer.parseInt( server.substring( server.indexOf( ":" ) + 1 ) ) );
-                    RemoteCacheManager rcm = RemoteCacheManager.getInstance( rca, cacheMgr );
+                    RemoteCacheManager rcm = RemoteCacheManager.getInstance( rca, cacheMgr, cacheEventLogger, elementSerializer );
                     // add a listener if there are none, need to tell rca what
                     // number it is at
                     if ( ( !primayDefined && fCnt == 1 ) || noWaits.size() <= 0 )
@@ -141,7 +146,7 @@
                 // p( "tcp server = " + server );
                 rca.setRemoteHost( server.substring( 0, server.indexOf( ":" ) ) );
                 rca.setRemotePort( Integer.parseInt( server.substring( server.indexOf( ":" ) + 1 ) ) );
-                RemoteCacheManager rcm = RemoteCacheManager.getInstance( rca, cacheMgr );
+                RemoteCacheManager rcm = RemoteCacheManager.getInstance( rca, cacheMgr, cacheEventLogger, elementSerializer );
                 rca.setRemoteType( RemoteCacheAttributes.CLUSTER );
                 ICache ic = rcm.getCache( rca );
                 if ( ic != null )
@@ -158,7 +163,7 @@
         // end if CLUSTER
 
         RemoteCacheNoWaitFacade rcnwf = new RemoteCacheNoWaitFacade( (RemoteCacheNoWait[]) noWaits
-            .toArray( new RemoteCacheNoWait[0] ), rca, cacheMgr );
+            .toArray( new RemoteCacheNoWait[0] ), rca, cacheMgr, cacheEventLogger, elementSerializer );
 
         getFacades().put( rca.getCacheName(), rcnwf );
 
@@ -193,5 +198,4 @@
     {
         return facades;
     }
-
 }

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java?rev=685702&r1=685701&r2=685702&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java Wed Aug 13 15:14:46 2008
@@ -23,7 +23,9 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.jcs.engine.CacheConstants;
 import org.apache.jcs.engine.behavior.ICache;
+import org.apache.jcs.engine.behavior.ICacheEventLogger;
 import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+import org.apache.jcs.engine.behavior.IElementSerializer;
 
 /**
  * The RemoteCacheFailoverRunner tries to establish a connection with a failover
@@ -32,15 +34,15 @@
  * <p>
  * It works by switching out the RemoteCacheNoWait inside the Facade.
  * <p>
- * Client (i.e.) the CompositeCache has refernce to a RemoteCacheNoWaitFacade.
+ * Client (i.e.) the CompositeCache has reference to a RemoteCacheNoWaitFacade.
  * This facade is created by the RemoteCacheFactory. The factory maintains a set
  * of managers, one for each remote server. Typically, there will only be one
  * manager.
  * <p>
- * If you use multipleremote servesr, you may want to set one or more as
+ * If you use multiple remote servers, you may want to set one or more as
  * failovers. If a local cache cannot connect to the primary server, or looses
  * its connection to the primary server, it will attempt to restore that
- * connectin in the background. If failovers are defined, the Failover runner
+ * Connection in the background. If failovers are defined, the Failover runner
  * will try to connect to a failover until the primary is restored.
  *
  */
@@ -55,7 +57,14 @@
 
     private boolean alright = true;
 
+    /** The cache manager */
     private ICompositeCacheManager cacheMgr;
+    
+    /** The event logger. */
+    private ICacheEventLogger cacheEventLogger;
+
+    /** The serializer. */
+    private IElementSerializer elementSerializer;
 
     /**
      * Constructor for the RemoteCacheFailoverRunner object. This allows the
@@ -64,11 +73,16 @@
      * @param facade
      *            the facade the CompositeCache talks to.
      * @param cacheMgr
+     * @param cacheEventLogger 
+     * @param elementSerializer 
      */
-    public RemoteCacheFailoverRunner( RemoteCacheNoWaitFacade facade, ICompositeCacheManager cacheMgr )
+    public RemoteCacheFailoverRunner( RemoteCacheNoWaitFacade facade, ICompositeCacheManager cacheMgr,
+                                      ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
     {
         this.facade = facade;
         this.cacheMgr = cacheMgr;
+        this.cacheEventLogger = cacheEventLogger;
+        this.elementSerializer = elementSerializer;
     }
 
     /**
@@ -183,7 +197,7 @@
                         rca = (RemoteCacheAttributes) facade.remoteCacheAttributes.copy();
                         rca.setRemoteHost( server.substring( 0, server.indexOf( ":" ) ) );
                         rca.setRemotePort( Integer.parseInt( server.substring( server.indexOf( ":" ) + 1 ) ) );
-                        RemoteCacheManager rcm = RemoteCacheManager.getInstance( rca, cacheMgr );
+                        RemoteCacheManager rcm = RemoteCacheManager.getInstance( rca, cacheMgr, cacheEventLogger, elementSerializer );
 
                         if ( log.isDebugEnabled() )
                         {
@@ -332,7 +346,7 @@
             RemoteCacheAttributes rca = (RemoteCacheAttributes) facade.remoteCacheAttributes.copy();
             rca.setRemoteHost( server.substring( 0, server.indexOf( ":" ) ) );
             rca.setRemotePort( Integer.parseInt( server.substring( server.indexOf( ":" ) + 1 ) ) );
-            RemoteCacheManager rcm = RemoteCacheManager.getInstance( rca, cacheMgr );
+            RemoteCacheManager rcm = RemoteCacheManager.getInstance( rca, cacheMgr, cacheEventLogger, elementSerializer );
 
             // add a listener if there are none, need to tell rca what number it
             // is at
@@ -376,7 +390,7 @@
                                     rcaOld.setRemoteHost( serverOld.substring( 0, serverOld.indexOf( ":" ) ) );
                                     rcaOld.setRemotePort( Integer.parseInt( serverOld.substring( serverOld
                                         .indexOf( ":" ) + 1 ) ) );
-                                    RemoteCacheManager rcmOld = RemoteCacheManager.getInstance( rcaOld, cacheMgr );
+                                    RemoteCacheManager rcmOld = RemoteCacheManager.getInstance( rcaOld, cacheMgr, cacheEventLogger, elementSerializer );
 
                                     if ( rcmOld != null )
                                     {
@@ -427,7 +441,14 @@
 
                     if ( log.isInfoEnabled() )
                     {
-                        log.info( "Successfully reconnected to PRIMARY remote server.  Substituted primary for failoverNoWait [" + failoverNoWait + "]" );
+                        String message = "Successfully reconnected to PRIMARY remote server.  Substituted primary for failoverNoWait [" + failoverNoWait + "]";
+                        log.info( message );
+                        
+                        if ( facade.getCacheEventLogger() != null )
+                        {
+                            facade.getCacheEventLogger().logApplicationEvent( "RemoteCacheFailoverRunner", "RestoredPrimary",
+                                                                              message );
+                        }                        
                     }
                     return true;
                 }

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheListener.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheListener.java?rev=685702&r1=685701&r2=685702&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 Aug 13 15:14:46 2008
@@ -41,7 +41,7 @@
 
 /**
  * Registered with RemoteCache server. The server updates the local caches via this listener. Each
- * server asings a unique listener id for a listener.
+ * server assigns a unique listener id for a listener.
  * <p>
  * One listener is used per remote cache server. The same listener is used for all the regions that
  * talk to a particular server.
@@ -81,7 +81,7 @@
      * Only need one since it does work for all regions, just reference by multiple region names.
      * <p>
      * The constructor exports this object, making it available to receive incoming calls. The
-     * calback port is anonymous unless a local port vlaue was specified in the configurtion.
+     * calback port is anonymous unless a local port value was specified in the configuration.
      * @param irca
      * @param cacheMgr
      */
@@ -95,7 +95,7 @@
         // calls, using an anonymous port unless the local port is specified.
         try
         {
-            if ( irca.getLocalPort() != 0 )
+            if ( irca.getLocalPort() > 0 )
             {
                 UnicastRemoteObject.exportObject( this, irca.getLocalPort() );
             }
@@ -112,7 +112,7 @@
     }
 
     /**
-     * Deregisters itself.
+     * Deregister itself.
      * <p>
      * @throws IOException
      */
@@ -157,8 +157,9 @@
     }
 
     /**
-     * Gets the listenerId attribute of the RemoteCacheListener object. This is stored int he
+     * Gets the listenerId attribute of the RemoteCacheListener object. This is stored in the
      * object. The RemoteCache object contains a reference to the listener and get the id this way.
+     * <p>
      * @return The listenerId value
      * @throws IOException
      */
@@ -174,7 +175,7 @@
     }
 
     /**
-     * Gets the remoteType attribute of the RemoteCacheListener object
+     * Gets the remoteType attribute of the RemoteCacheListener object <p.
      * @return The remoteType value
      * @throws IOException
      */
@@ -194,7 +195,7 @@
      * invalidation. The next time it is used the local cache will get the new version from the
      * remote store.
      * <p>
-     * If remove on put is not ocnfigured, then update the item.
+     * If remove on put is not configured, then update the item.
      * @param cb
      * @throws IOException
      */
@@ -261,9 +262,9 @@
     /**
      * Calls localRemove on the CompositeCache.
      * <p>
-     * (non-Javadoc)
-     * @see org.apache.jcs.engine.behavior.ICacheListener#handleRemove(java.lang.String,
-     *      java.io.Serializable)
+     * @param cacheName
+     * @param key
+     * @throws IOException
      */
     public void handleRemove( String cacheName, Serializable key )
         throws IOException
@@ -288,8 +289,8 @@
     /**
      * Calls localRemoveAll on the CompositeCache.
      * <p>
-     * (non-Javadoc)
-     * @see org.apache.jcs.engine.behavior.ICacheListener#handleRemoveAll(java.lang.String)
+     * @param cacheName
+     * @throws IOException
      */
     public void handleRemoveAll( String cacheName )
         throws IOException
@@ -303,9 +304,9 @@
         cache.localRemoveAll();
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.jcs.engine.behavior.ICacheListener#handleDispose(java.lang.String)
+    /**
+     * @param cacheName
+     * @throws IOException
      */
     public void handleDispose( String cacheName )
         throws IOException
@@ -346,6 +347,9 @@
 
     /**
      * This is for debugging. It allows the remote server to log the address of clients.
+     * <p>
+     * @return String
+     * @throws IOException 
      */
     public String getLocalHostAddress()
         throws IOException

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheManager.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheManager.java?rev=685702&r1=685701&r2=685702&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 Wed Aug 13 15:14:46 2008
@@ -36,7 +36,9 @@
 import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheObserver;
 import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService;
 import org.apache.jcs.engine.behavior.ICache;
+import org.apache.jcs.engine.behavior.ICacheEventLogger;
 import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+import org.apache.jcs.engine.behavior.IElementSerializer;
 import org.apache.jcs.engine.behavior.IShutdownObserver;
 import org.apache.jcs.engine.control.CompositeCacheManager;
 
@@ -55,15 +57,14 @@
 
     private final static Log log = LogFactory.getLog( RemoteCacheManager.class );
 
-    // Contains mappings of Location instance to RemoteCacheManager instance.
+    /** Contains mappings of Location instance to RemoteCacheManager instance. */
     final static Map instances = new HashMap();
 
     private static RemoteCacheMonitor monitor;
 
     private int clients;
 
-    // Contains instances of RemoteCacheNoWait managed by a RemoteCacheManager
-    // instance.
+    /** Contains instances of RemoteCacheNoWait managed by a RemoteCacheManager instance. */
     final Map caches = new HashMap();
 
     final String host;
@@ -72,11 +73,16 @@
 
     final String service;
 
-    private IRemoteCacheAttributes irca;
+    /** The configuration attributes. */
+    private IRemoteCacheAttributes remoteCacheAttributes;
 
-    /**
-     * Handle to the remote cache service; or a zombie handle if failed to connect.
-     */
+    /** The event logger. */
+    private ICacheEventLogger cacheEventLogger;
+
+    /** The serializer. */
+    private IElementSerializer elementSerializer;
+
+    /** Handle to the remote cache service; or a zombie handle if failed to connect. */
     private IRemoteCacheService remoteService;
 
     /**
@@ -85,9 +91,7 @@
      */
     private RemoteCacheWatchRepairable remoteWatch;
 
-    /**
-     * The cache manager listeners will need to use to get a cache.
-     */
+    /** The cache manager listeners will need to use to get a cache. */
     private ICompositeCacheManager cacheMgr;
 
     private String registry;
@@ -101,13 +105,18 @@
      * @param port
      * @param service
      * @param cacheMgr
+     * @param cacheEventLogger
+     * @param elementSerializer
      */
-    private RemoteCacheManager( String host, int port, String service, ICompositeCacheManager cacheMgr )
+    private RemoteCacheManager( String host, int port, String service, ICompositeCacheManager cacheMgr,
+                                ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
     {
         this.host = host;
         this.port = port;
         this.service = service;
         this.cacheMgr = cacheMgr;
+        this.cacheEventLogger = cacheEventLogger;
+        this.elementSerializer = elementSerializer;
 
         // register shutdown observer
         // TODO add the shutdown observable methods to the interface
@@ -160,7 +169,7 @@
      */
     public IRemoteCacheAttributes getDefaultCattr()
     {
-        return this.irca;
+        return this.remoteCacheAttributes;
     }
 
     /**
@@ -298,10 +307,13 @@
      * <p>
      * @param cattr
      * @param cacheMgr
+     * @param cacheEventLogger
+     * @param elementSerializer
      * @return The instance value
-     * @parma port port of the registry.
      */
-    public static RemoteCacheManager getInstance( IRemoteCacheAttributes cattr, ICompositeCacheManager cacheMgr )
+    public static RemoteCacheManager getInstance( IRemoteCacheAttributes cattr, ICompositeCacheManager cacheMgr,
+                                                  ICacheEventLogger cacheEventLogger,
+                                                  IElementSerializer elementSerializer )
     {
         String host = cattr.getRemoteHost();
         int port = cattr.getRemotePort();
@@ -316,19 +328,16 @@
         }
         Location loc = new Location( host, port );
 
-        RemoteCacheManager ins = (RemoteCacheManager) instances.get( loc );
+        RemoteCacheManager ins = null;
         synchronized ( instances )
         {
+            ins = (RemoteCacheManager) instances.get( loc );
             if ( ins == null )
             {
-                ins = (RemoteCacheManager) instances.get( loc );
-                if ( ins == null )
-                {
-                    // cahnge to use cattr and to set defaults
-                    ins = new RemoteCacheManager( host, port, service, cacheMgr );
-                    ins.irca = cattr;
-                    instances.put( loc, ins );
-                }
+                // Change to use cattr and to set defaults
+                ins = new RemoteCacheManager( host, port, service, cacheMgr, cacheEventLogger, elementSerializer );
+                ins.remoteCacheAttributes = cattr;
+                instances.put( loc, ins );
             }
         }
 
@@ -357,7 +366,7 @@
      */
     public AuxiliaryCache getCache( String cacheName )
     {
-        IRemoteCacheAttributes ca = (IRemoteCacheAttributes) irca.copy();
+        IRemoteCacheAttributes ca = (IRemoteCacheAttributes) remoteCacheAttributes.copy();
         ca.setCacheName( cacheName );
         return getCache( ca );
     }
@@ -374,12 +383,12 @@
      */
     public AuxiliaryCache getCache( IRemoteCacheAttributes cattr )
     {
-        RemoteCacheNoWait c = null;
+        RemoteCacheNoWait remoteCacheNoWait = null;
 
         synchronized ( caches )
         {
-            c = (RemoteCacheNoWait) caches.get( cattr.getCacheName() );
-            if ( c == null )
+            remoteCacheNoWait = (RemoteCacheNoWait) caches.get( cattr.getCacheName() );
+            if ( remoteCacheNoWait == null )
             {
                 // create a listener first and pass it to the remotecache
                 // sender.
@@ -398,14 +407,21 @@
                     log.error( e.getMessage() );
                 }
 
-                c = new RemoteCacheNoWait( new RemoteCache( cattr, remoteService, listener ) );
-                caches.put( cattr.getCacheName(), c );
+                IRemoteCacheClient remoteCacheClient = new RemoteCache( cattr, remoteService, listener );
+                remoteCacheClient.setCacheEventLogger( cacheEventLogger );
+                remoteCacheClient.setElementSerializer( elementSerializer );
+                
+                remoteCacheNoWait = new RemoteCacheNoWait( remoteCacheClient );
+                remoteCacheNoWait.setCacheEventLogger( cacheEventLogger );
+                remoteCacheNoWait.setElementSerializer( elementSerializer );
+                
+                caches.put( cattr.getCacheName(), remoteCacheNoWait );
             }
 
             // might want to do some listener sanity checking here.
         }
 
-        return c;
+        return remoteCacheNoWait;
     }
 
     /**

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java?rev=685702&r1=685701&r2=685702&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWait.java Wed Aug 13 15:14:46 2008
@@ -39,28 +39,32 @@
 import org.apache.jcs.engine.CacheConstants;
 import org.apache.jcs.engine.CacheEventQueueFactory;
 import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.ICacheEventLogger;
 import org.apache.jcs.engine.behavior.ICacheEventQueue;
 import org.apache.jcs.engine.behavior.ICacheType;
+import org.apache.jcs.engine.behavior.IElementSerializer;
 import org.apache.jcs.engine.stats.StatElement;
 import org.apache.jcs.engine.stats.Stats;
 import org.apache.jcs.engine.stats.behavior.IStatElement;
 import org.apache.jcs.engine.stats.behavior.IStats;
 
 /**
+ * The RemoteCacheNoWait wraps the RemoteCacheClient.  The client holds a handle on the RemoteCacheService.
+ * <p>
  * Used to queue up update requests to the underlying cache. These requests will be processed in
  * their order of arrival via the cache event queue processor.
  * <p>
  * Typically errors will be handled down stream. We only need to kill the queue if an error makes it
  * to this level from the queue. That can only happen if the queue is damaged, since the events are
- * procesed asynchronously.
+ * Processed asynchronously.
  * <p>
  * There is no reason to create a queue on startup if the remote is not healthy.
  * <p>
- * If the remote cache encounters an error it will zombie--create a blaking facade for the service.
- * The Zombie will queue up items until the conenction is restored. An alternative way to accomplish
+ * If the remote cache encounters an error it will zombie--create a balking facade for the service.
+ * The Zombie will queue up items until the connection is restored. An alternative way to accomplish
  * the same thing would be to stop, not destroy the queue at this level. That way items would be
  * added to the queue and then when the connection is restored, we could start the worker threads
- * again. This is a better long term solution, but it requires some significnat changes to the
+ * again. This is a better long term solution, but it requires some significant changes to the
  * complicated worker queues.
  */
 public class RemoteCacheNoWait
@@ -73,7 +77,7 @@
     private final static Log log = LogFactory.getLog( RemoteCacheNoWait.class );
 
     /** The remote cache client */
-    private final IRemoteCacheClient cache;
+    private final IRemoteCacheClient remoteCacheClient;
 
     /** Event queue for queueing up calls like put and remove. */
     private ICacheEventQueue cacheEventQueue;
@@ -90,21 +94,28 @@
     /** how many times put has been called. */
     private int putCount = 0;
 
+    /** An optional event logger */
+    private ICacheEventLogger cacheEventLogger;
+
+    /** The serializer. */
+    private IElementSerializer elementSerializer;
+
     /**
-     * Constructs with the given remote cache, and fires up an event queue for aysnchronous
+     * Constructs with the given remote cache, and fires up an event queue for asynchronous
      * processing.
      * <p>
      * @param cache
      */
     public RemoteCacheNoWait( IRemoteCacheClient cache )
     {
-        this.cache = cache;
+        remoteCacheClient = cache;
+
         CacheEventQueueFactory factory = new CacheEventQueueFactory();
-        this.cacheEventQueue = factory.createCacheEventQueue( new CacheAdaptor( cache ), cache.getListenerId(), cache
-            .getCacheName(), cache.getAuxiliaryCacheAttributes().getEventQueuePoolName(), cache
-            .getAuxiliaryCacheAttributes().getEventQueueTypeFactoryCode() );
+        this.cacheEventQueue = factory.createCacheEventQueue( new CacheAdaptor( remoteCacheClient ), remoteCacheClient
+            .getListenerId(), remoteCacheClient.getCacheName(), remoteCacheClient.getAuxiliaryCacheAttributes()
+            .getEventQueuePoolName(), remoteCacheClient.getAuxiliaryCacheAttributes().getEventQueueTypeFactoryCode() );
 
-        if ( cache.getStatus() == CacheConstants.STATUS_ERROR )
+        if ( remoteCacheClient.getStatus() == CacheConstants.STATUS_ERROR )
         {
             cacheEventQueue.destroy();
         }
@@ -113,8 +124,8 @@
     /**
      * Adds a put event to the queue.
      * <p>
-     * (non-Javadoc)
-     * @see org.apache.jcs.engine.behavior.ICache#update(org.apache.jcs.engine.behavior.ICacheElement)
+     * @param element
+     * @throws IOException
      */
     public void update( ICacheElement element )
         throws IOException
@@ -145,7 +156,7 @@
         getCount++;
         try
         {
-            return cache.get( key );
+            return remoteCacheClient.get( key );
         }
         catch ( UnmarshalException ue )
         {
@@ -156,7 +167,7 @@
 
             try
             {
-                return cache.get( key );
+                return remoteCacheClient.get( key );
             }
             catch ( IOException ex )
             {
@@ -178,12 +189,13 @@
     }
 
     /**
-     * Gets multiple items from the cache based on the given set of keys.  
-     * Sends the getMultiple request on to the server rather than looping through the requested keys.
+     * Gets multiple items from the cache based on the given set of keys. Sends the getMultiple
+     * request on to the server rather than looping through the requested keys.
      * <p>
      * @param keys
-     * @return a map of Serializable key to ICacheElement element, or an empty map if there is no data in cache for any of these keys
-     * @throws IOException 
+     * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+     *         data in cache for any of these keys
+     * @throws IOException
      */
     public Map getMultiple( Set keys )
         throws IOException
@@ -191,7 +203,7 @@
         getMultipleCount++;
         try
         {
-            return cache.getMultiple( keys );
+            return remoteCacheClient.getMultiple( keys );
         }
         catch ( UnmarshalException ue )
         {
@@ -202,7 +214,7 @@
 
             try
             {
-                return cache.getMultiple( keys );
+                return remoteCacheClient.getMultiple( keys );
             }
             catch ( IOException ex )
             {
@@ -224,14 +236,14 @@
     }
 
     /**
-     * @param groupName 
+     * @param groupName
      * @return the keys for the group name
-     * @throws IOException 
+     * @throws IOException
      */
     public Set getGroupKeys( String groupName )
         throws IOException
     {
-        return cache.getGroupKeys( groupName );
+        return remoteCacheClient.getGroupKeys( groupName );
     }
 
     /**
@@ -299,11 +311,11 @@
      */
     public int getSize()
     {
-        return cache.getSize();
+        return remoteCacheClient.getSize();
     }
 
     /**
-     * No remote invokation.
+     * No remote invocation.
      * <p>
      * @return The cacheType value
      */
@@ -320,7 +332,7 @@
      */
     public int getStatus()
     {
-        return cacheEventQueue.isWorking() ? cache.getStatus() : CacheConstants.STATUS_ERROR;
+        return cacheEventQueue.isWorking() ? remoteCacheClient.getStatus() : CacheConstants.STATUS_ERROR;
     }
 
     /**
@@ -330,7 +342,7 @@
      */
     public String getCacheName()
     {
-        return cache.getCacheName();
+        return remoteCacheClient.getCacheName();
     }
 
     /**
@@ -341,7 +353,7 @@
      */
     public void fixCache( IRemoteCacheService remote )
     {
-        cache.fixCache( remote );
+        remoteCacheClient.fixCache( remote );
         resetEventQ();
         return;
     }
@@ -351,16 +363,16 @@
      * <p>
      * There may be no good reason to kill the existing queue. We will sometimes need to set a new
      * listener id, so we should create a new queue. We should let the old queue drain. If we were
-     * conencted to the failover, it would be best to finish sending items.
+     * Connected to the failover, it would be best to finish sending items.
      */
     public void resetEventQ()
     {
         ICacheEventQueue previousQueue = cacheEventQueue;
 
         CacheEventQueueFactory fact = new CacheEventQueueFactory();
-        this.cacheEventQueue = fact.createCacheEventQueue( new CacheAdaptor( cache ), cache.getListenerId(), cache
-            .getCacheName(), cache.getAuxiliaryCacheAttributes().getEventQueuePoolName(), cache
-            .getAuxiliaryCacheAttributes().getEventQueueTypeFactoryCode() );
+        this.cacheEventQueue = fact.createCacheEventQueue( new CacheAdaptor( remoteCacheClient ), remoteCacheClient
+            .getListenerId(), remoteCacheClient.getCacheName(), remoteCacheClient.getAuxiliaryCacheAttributes()
+            .getEventQueuePoolName(), remoteCacheClient.getAuxiliaryCacheAttributes().getEventQueueTypeFactoryCode() );
 
         if ( previousQueue.isWorking() )
         {
@@ -380,7 +392,7 @@
      */
     protected IRemoteCacheClient getRemoteCache()
     {
-        return cache;
+        return remoteCacheClient;
     }
 
     /**
@@ -388,11 +400,11 @@
      */
     public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
     {
-        return cache.getAuxiliaryCacheAttributes();
+        return remoteCacheClient.getAuxiliaryCacheAttributes();
     }
 
     /**
-     * This is for testing only.  It allows you to take a look at the event queue.
+     * This is for testing only. It allows you to take a look at the event queue.
      * <p>
      * @return ICacheEventQueue
      */
@@ -402,6 +414,27 @@
     }
 
     /**
+     * Allows it to be injected.
+     * <p>
+     * @param cacheEventLogger
+     */
+    public void setCacheEventLogger( ICacheEventLogger cacheEventLogger )
+    {
+        this.cacheEventLogger = cacheEventLogger;
+    }
+
+    /**
+     * Allows you to inject a custom serializer. A good example would be a compressing standard
+     * serializer.
+     * <p>
+     * @param elementSerializer
+     */
+    public void setElementSerializer( IElementSerializer elementSerializer )
+    {
+        this.elementSerializer = elementSerializer;
+    }
+
+    /**
      * Returns the stats and the cache.toString().
      * <p>
      * (non-Javadoc)
@@ -409,7 +442,7 @@
      */
     public String toString()
     {
-        return getStats() + "\n" + cache.toString();
+        return getStats() + "\n" + remoteCacheClient.toString();
     }
 
     /**
@@ -423,7 +456,7 @@
     }
 
     /**
-     * @return statistics about this communication 
+     * @return statistics about this communication
      */
     public IStats getStatistics()
     {
@@ -459,7 +492,7 @@
 
         // get the stats from the cache queue too
         // get as array, convert to list, add list to our outer list
-        IStats cStats = this.cache.getStatistics();
+        IStats cStats = this.remoteCacheClient.getStatistics();
         if ( cStats != null )
         {
             IStatElement[] cSEs = cStats.getStatElements();
@@ -500,5 +533,4 @@
 
         return stats;
     }
-
 }

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java?rev=685702&r1=685701&r2=685702&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java Wed Aug 13 15:14:46 2008
@@ -35,8 +35,10 @@
 import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
 import org.apache.jcs.engine.CacheConstants;
 import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.ICacheEventLogger;
 import org.apache.jcs.engine.behavior.ICacheType;
 import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+import org.apache.jcs.engine.behavior.IElementSerializer;
 import org.apache.jcs.engine.stats.StatElement;
 import org.apache.jcs.engine.stats.Stats;
 import org.apache.jcs.engine.stats.behavior.IStatElement;
@@ -47,12 +49,13 @@
  * NoWaitFacade to give to the composite cache out of caches it constructs from the varies manager
  * to lateral services.
  * <p>
- * Typically, we only connect to one remote server per facade.  We use a list of one RemoteCacheNoWait.
+ * Typically, we only connect to one remote server per facade. We use a list of one
+ * RemoteCacheNoWait.
  */
 public class RemoteCacheNoWaitFacade
     implements AuxiliaryCache
 {
-    /** For serialization. Don't change.*/
+    /** For serialization. Don't change. */
     private static final long serialVersionUID = -4529970797620747110L;
 
     /** log instance */
@@ -71,6 +74,15 @@
     private ICompositeCacheManager cacheMgr;
 
     /**
+     * An optional event logger. Only errors are logged here. We don't want to log ICacheEvents
+     * since the noWaits do this.
+     */
+    private ICacheEventLogger cacheEventLogger;
+
+    /** The serializer. */
+    private IElementSerializer elementSerializer;
+
+    /**
      * Gets the remoteCacheAttributes attribute of the RemoteCacheNoWaitFacade object
      * <p>
      * @return The remoteCacheAttributes value
@@ -96,9 +108,12 @@
      * @param noWaits
      * @param rca
      * @param cacheMgr
+     * @param cacheEventLogger 
+     * @param elementSerializer 
      */
     public RemoteCacheNoWaitFacade( RemoteCacheNoWait[] noWaits, RemoteCacheAttributes rca,
-                                    ICompositeCacheManager cacheMgr )
+                                    ICompositeCacheManager cacheMgr,
+                                    ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
     {
         if ( log.isDebugEnabled() )
         {
@@ -108,6 +123,8 @@
         this.remoteCacheAttributes = rca;
         this.cacheName = rca.getCacheName();
         this.cacheMgr = cacheMgr;
+        this.cacheEventLogger = cacheEventLogger;
+        this.elementSerializer = elementSerializer;
     }
 
     /**
@@ -137,7 +154,15 @@
         }
         catch ( Exception ex )
         {
-            log.error( ex );
+            String message = "Problem updating no wait.  Will initiate failover if the noWait is in error.";
+            log.error( message, ex );
+
+            if ( getCacheEventLogger() != null )
+            {
+                getCacheEventLogger().logError( "RemoteCacheNoWaitFacade", ce.getCacheName(),
+                                                ICacheEventLogger.UPDATE_EVENT, message + ":" + ex.getMessage(), ce );
+            }
+
             // can handle failover here? Is it safe to try the others?
             // check to see it the noWait is now a zombie
             // if it is a zombie, then move to the next in the failover list
@@ -183,7 +208,8 @@
      * Gets multiple items from the cache based on the given set of keys.
      * <p>
      * @param keys
-     * @return a map of Serializable key to ICacheElement element, or an empty map if there is no data in cache for any of these keys
+     * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+     *         data in cache for any of these keys
      */
     public Map getMultiple( Set keys )
     {
@@ -334,7 +360,7 @@
     }
 
     /**
-     * String form of some of the configuratin information for the remote cache.
+     * String form of some of the configuration information for the remote cache.
      * <p>
      * @return Some info for logging.
      */
@@ -360,7 +386,7 @@
             if ( noWaits[i].getStatus() == CacheConstants.STATUS_ERROR )
             {
                 // start failover, primary recovery process
-                RemoteCacheFailoverRunner runner = new RemoteCacheFailoverRunner( this, cacheMgr );
+                RemoteCacheFailoverRunner runner = new RemoteCacheFailoverRunner( this, cacheMgr, cacheEventLogger, elementSerializer );
                 // If the returned monitor is null, it means it's already
                 // started elsewhere.
                 if ( runner != null )
@@ -370,6 +396,12 @@
                     t.setDaemon( true );
                     t.start();
                 }
+
+                if ( getCacheEventLogger() != null )
+                {
+                    getCacheEventLogger().logApplicationEvent( "RemoteCacheNoWaitFacade", "InitiatedFailover",
+                                                               noWaits[i] + " was in error." );
+                }
             }
             else
             {
@@ -434,4 +466,35 @@
 
         return stats;
     }
+
+    /**
+     * Allows it to be injected.
+     * <p>
+     * @param cacheEventLogger
+     */
+    public void setCacheEventLogger( ICacheEventLogger cacheEventLogger )
+    {
+        this.cacheEventLogger = cacheEventLogger;
+    }      
+
+    /**
+     * Allows the failover runner to use this event logger.
+     * <p>
+     * @return ICacheEventLogger
+     */
+    protected ICacheEventLogger getCacheEventLogger()
+    {
+        return cacheEventLogger;
+    }
+    
+    /**
+     * Allows you to inject a custom serializer. A good example would be a compressing standard
+     * serializer.
+     * <p>
+     * @param elementSerializer
+     */
+    public void setElementSerializer( IElementSerializer elementSerializer )
+    {
+        this.elementSerializer = elementSerializer;
+    }    
 }

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheClient.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheClient.java?rev=685702&r1=685701&r2=685702&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheClient.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/behavior/IRemoteCacheClient.java Wed Aug 13 15:14:46 2008
@@ -34,7 +34,7 @@
 {
     /**
      * Replaces the current remote cache service handle with the given handle. If the current remote
-     * is a Zombie, the propagate teh events that may be queued to the restored service.
+     * is a Zombie, the propagate the events that may be queued to the restored service.
      * <p>
      * @param remote IRemoteCacheService -- the remote server or proxy to the remote server
      */



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