jcs-dev@jakarta.apache.org
[Top] [All Lists]

svn commit: r389816 - in /jakarta/jcs/trunk/src/java/org/apache/jcs/auxi

Subject: svn commit: r389816 - in /jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote: RemoteCache.java RemoteCacheAttributes.java
From:
Date: Wed, 29 Mar 2006 16:15:12 -0000
Author: asmuts
Date: Wed Mar 29 08:15:09 2006
New Revision: 389816

URL: http://svn.apache.org/viewcvs?rev=389816&view=rev
Log:
removed the possiblity of a null pointer when the listener id is not registered.

added a special socket factory with timeouts

added the ability to configure the rmi timeout.

Modified:
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java
    
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCacheAttributes.java

Modified: 
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java
URL: 
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/RemoteCache.java?rev=389816&r1=389815&r2=389816&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 Mar 29 08:15:09 2006
@@ -19,6 +19,9 @@
 import java.io.IOException;
 import java.io.Serializable;
 import java.lang.reflect.InvocationTargetException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.rmi.server.RMISocketFactory;
 import java.util.ArrayList;
 import java.util.Set;
 
@@ -47,6 +50,7 @@
 import EDU.oswego.cs.dl.util.concurrent.Callable;
 import EDU.oswego.cs.dl.util.concurrent.FutureResult;
 import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
+import EDU.oswego.cs.dl.util.concurrent.TimeoutException;
 
 /**
  * Client proxy for an RMI remote cache. This handles gets, updates, and
@@ -121,6 +125,33 @@
                 pool.getPool().setThreadFactory( new MyThreadFactory() );
             }
         }
+        
+        try
+        {
+            // TODO make configurable.
+            // use this socket factory to add a timeout.
+            RMISocketFactory.setSocketFactory( new RMISocketFactory()
+            {
+                public Socket createSocket( String host, int port )
+                    throws IOException
+                {
+                    Socket socket = new Socket( host, port );
+                    socket.setSoTimeout( 
irca.getRmiSocketFactoryTimeoutMillis() );
+                    socket.setSoLinger( false, 0 );
+                    return socket;
+                }
+
+                public ServerSocket createServerSocket( int port )
+                    throws IOException
+                {
+                    return new ServerSocket( port );
+                }
+            } );
+        }
+        catch ( Exception e )
+        {
+            log.error( "Problem setting custom RMI Socket Factory.", e );
+        }        
     }
 
     /**
@@ -273,15 +304,20 @@
             }
             return ice;
         }
+        catch( TimeoutException te )
+        {
+            log.warn( "TimeoutException, Get Request timed out after " + 
timeout );
+            throw new IOException( "Get Request timed out after " + timeout );
+        }
         catch ( InterruptedException ex )
         {
-            log.warn( "Get Request timed out after " + timeout );
+            log.warn( "InterruptedException, Get Request timed out after " + 
timeout );
             throw new IOException( "Get Request timed out after " + timeout );
         }
         catch ( InvocationTargetException ex )
         {
             // assume that this is an IOException thrown by the callable.
-            log.error( "Assuming an IO exception thrown in the backfground.", 
ex );
+            log.error( "InvocationTargetException, Assuming an IO exception 
thrown in the background.", ex );
             throw new IOException( "Get Request timed out after " + timeout );
         }
     }

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=389816&r1=389815&r2=389816&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 Mar 29 08:15:09 2006
@@ -68,6 +68,8 @@
     // must be greater than 0 for a pool to be used.
     private int getTimeoutMillis = -1;
 
+    private int rmiSocketFactoryTimeoutMillis = 
DEFAULT_RMI_SOCKET_FACTORY_TIMEOUT_MILLIS;
+    
     /** Default constructor for the RemoteCacheAttributes object */
     public RemoteCacheAttributes()
     {
@@ -420,6 +422,22 @@
     public void setGetTimeoutMillis( int millis )
     {
         getTimeoutMillis = millis;
+    }
+
+    /**
+     * @param rmiSocketFactoryTimeoutMillis The rmiSocketFactoryTimeoutMillis 
to set.
+     */
+    public void setRmiSocketFactoryTimeoutMillis( int 
rmiSocketFactoryTimeoutMillis )
+    {
+        this.rmiSocketFactoryTimeoutMillis = rmiSocketFactoryTimeoutMillis;
+    }
+
+    /**
+     * @return Returns the rmiSocketFactoryTimeoutMillis.
+     */
+    public int getRmiSocketFactoryTimeoutMillis()
+    {
+        return rmiSocketFactoryTimeoutMillis;
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: jcs-dev-help@xxxxxxxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>
  • svn commit: r389816 - in /jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote: RemoteCache.java RemoteCacheAttributes.java, asmuts <=