Author: ron.sigal(a)jboss.com
Date: 2009-09-02 13:23:18 -0400 (Wed, 02 Sep 2009)
New Revision: 5430
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
Log:
JBREM-1146: Added generalized SocketException facility.
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2009-09-02
17:18:25 UTC (rev 5429)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2009-09-02
17:23:18 UTC (rev 5430)
@@ -31,6 +31,7 @@
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
+import java.rmi.MarshalException;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
@@ -40,6 +41,8 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.regex.Pattern;
+
import EDU.oswego.cs.dl.util.concurrent.Semaphore;
/**
@@ -136,6 +139,9 @@
public static long serializeTime = 0;
public static long deserializeTime = 0;
+ private static final String patternString =
"^.*(?:connection.*reset|connection.*closed|broken.*pipe).*$";
+ private static final Pattern RETRIABLE_ERROR_MESSAGE = Pattern.compile(patternString,
Pattern.CASE_INSENSITIVE);
+
/**
* Close all sockets in a specific pool.
*/
@@ -251,6 +257,12 @@
protected int soLingerDuration = -1;
protected int trafficClass = -1;
+ /**
+ * If true, an IOException with message such as "Connection reset by peer: socket
write error" will
+ * be treated like a SocketException.
+ */
+ protected boolean generalizeSocketException;
+
protected int writeTimeout = -1;
// Constructors
---------------------------------------------------------------------------------
@@ -399,6 +411,16 @@
this.writeTimeout = writeTimeout;
}
+ public boolean isGeneralizeSocketException()
+ {
+ return generalizeSocketException;
+ }
+
+ public void setGeneralizeSocketException(boolean generalizeSocketException)
+ {
+ this.generalizeSocketException = generalizeSocketException;
+ }
+
public synchronized void disconnect()
{
log.debug(this + " disconnecting ...");
@@ -776,6 +798,7 @@
for (; retryCount < numberOfCallRetries; retryCount++)
{
+ if (trace) log.trace(this + " retryCount: " + retryCount);
if (0 < tempTimeout)
{
// If a per invocation timeout has been set, the time spent retrying
@@ -905,25 +928,23 @@
sockEx = ex;
continue;
}
- catch (Exception ex)
+ catch (IOException e)
{
- log.debug(this + " got exception: " + socketWrapper, ex);
-
- try
+ if (isGeneralizeSocketException() &&
RETRIABLE_ERROR_MESSAGE.matcher(e.getMessage()).matches())
{
- semaphore.release();
- if (trace) log.trace(this + " released semaphore: " +
semaphore.permits());
- socketWrapper.close();
+ handleRetriableException(socketWrapper, e, retryCount);
+ sockEx = new SocketException(e.getMessage());
+ continue;
}
- catch (Exception ignored)
+ else
{
+ return handleOtherException(e, semaphore, socketWrapper, oneway);
}
-
- if (oneway)
- return null;
- else
- return handleException(ex, socketWrapper);
}
+ catch (Exception ex)
+ {
+ return handleOtherException(ex, semaphore, socketWrapper, oneway);
+ }
// call worked, so no need to retry
break;
@@ -1037,6 +1058,27 @@
}
}
+ protected Object handleOtherException(Exception ex, Semaphore semaphore, SocketWrapper
socketWrapper, boolean oneway)
+ throws ClassNotFoundException, InvocationFailureException
+ {
+ log.debug(this + " got exception: " + socketWrapper, ex);
+
+ try
+ {
+ semaphore.release();
+ if (trace) log.trace(this + " released semaphore: " +
semaphore.permits());
+ socketWrapper.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+
+ if (oneway)
+ return null;
+ else
+ return handleException(ex, socketWrapper);
+ }
+
protected void initPool()
{
synchronized (connectionPools)
Show replies by date