JBoss Remoting SVN: r5556 - in remoting2/branches/2.2.2-SP7_JBREM-1120/src: main/org/jboss/remoting/transport/sslbisocket and 4 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: jbertram(a)redhat.com
Date: 2009-10-09 16:35:17 -0400 (Fri, 09 Oct 2009)
New Revision: 5556
Added:
remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java
remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/timeout/SSLBisocketWriteTimeoutTestCase.java
remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/bisocket/timeout/BisocketWriteTimeoutTestCase.java
remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketWriteTimeoutTestCase.java
remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java
remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketWriteTimeoutTestCase.java
remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java
Modified:
remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/ClientSocketWrapper.java
remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/ServerThread.java
remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java
remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/SocketWrapper.java
remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketServerInvoker.java
Log:
[JBPAPP-2899]
Modified: remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/ClientSocketWrapper.java
===================================================================
--- remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/ClientSocketWrapper.java 2009-10-08 19:58:47 UTC (rev 5555)
+++ remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/ClientSocketWrapper.java 2009-10-09 20:35:17 UTC (rev 5556)
@@ -51,6 +51,7 @@
private InputStream in;
private OutputStream out;
+ private int writeTimeout = -1;
// Constructors ---------------------------------------------------------------------------------
@@ -78,6 +79,16 @@
return in;
}
+ public int getWriteTimeout()
+ {
+ return writeTimeout;
+ }
+
+ public void setWriteTimeout(int writeTimeout)
+ {
+ this.writeTimeout = writeTimeout;
+ }
+
public void checkConnection() throws IOException
{
// Test to see if socket is alive by send ACK message
@@ -98,7 +109,7 @@
public void checkOpenConnection() throws IOException
{
- log.trace("checking open connection");
+ if (trace) log.trace("checking open connection");
if (in.available() > 1)
{
log.debug("remote endpoint has closed");
@@ -156,6 +167,15 @@
log.debug("set temp timeout to: " + tempTimeout);
}
}
+ o = metadata.get(WRITE_TIMEOUT);
+ if (o instanceof Integer)
+ {
+ writeTimeout = ((Integer) o).intValue();
+ if (writeTimeout != -1)
+ {
+ log.trace("set writeTimeout to: " + writeTimeout);
+ }
+ }
}
try
@@ -198,6 +218,12 @@
log.warn("got null marshaller");
OutputStream os = socket.getOutputStream();
+ if (writeTimeout > 0)
+ {
+ os = new TimedOutputStream(os, writeTimeout);
+ if (trace) log.trace(this + " created TimedOutputStream: " + os);
+ }
+
if (marshaller instanceof PreferredStreamMarshaller)
{
PreferredStreamMarshaller psm = (PreferredStreamMarshaller) marshaller;
Modified: remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
===================================================================
--- remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2009-10-08 19:58:47 UTC (rev 5555)
+++ remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2009-10-09 20:35:17 UTC (rev 5556)
@@ -70,7 +70,10 @@
* used, which may also be a requirement.
*/
public static final String CLIENT_SOCKET_CLASS_FLAG = "clientSocketClass";
-
+
+ /** Key for setting socket write timeout */
+ public static final String WRITE_TIMEOUT = "writeTimeout";
+
/**
* Default value for enable TCP nodelay. Value is false.
*/
@@ -215,6 +218,14 @@
//public long usedPooled;
public Object usedPoolLock;
+
+ /**
+ * If true, an IOException with message "Connection reset by peer: socket write error" will
+ * be treated like a SocketException.
+ */
+ protected boolean generalizeSocketException;
+
+ protected int writeTimeout = -1;
// Constructors ---------------------------------------------------------------------------------
@@ -281,6 +292,38 @@
reuseAddress = reuse;
}
+ public int getWriteTimeout()
+ {
+ return writeTimeout;
+ }
+
+ public void setWriteTimeout(int writeTimeout)
+ {
+ this.writeTimeout = writeTimeout;
+ }
+
+ /**
+ * Get the generalizeSocketException.
+ *
+ * @return the generalizeSocketException.
+ */
+
+ public synchronized boolean isGeneralizeSocketException()
+ {
+ return generalizeSocketException;
+ }
+
+ /**
+ * Set the generalizeSocketException.
+ *
+ * @param generalizeSocketException The generalizeSocketException to set.
+ */
+
+ public synchronized void setGeneralizeSocketException(boolean generalizeSocketException)
+ {
+ this.generalizeSocketException = generalizeSocketException;
+ }
+
public synchronized void disconnect()
{
log.debug(this + " disconnecting ...");
@@ -456,6 +499,22 @@
shouldCheckConnection = true;
log.debug(this + " setting shouldCheckConnection to " + shouldCheckConnection);
}
+
+ // look for writeTimeout param
+ val = params.get(WRITE_TIMEOUT);
+ if (val != null)
+ {
+ try
+ {
+ writeTimeout = Integer.valueOf((String)val).intValue();
+ log.debug(this + " setting writeTimeout to " + writeTimeout);
+ }
+ catch (Exception e)
+ {
+ log.warn(this + " could not convert " + WRITE_TIMEOUT + " value of " +
+ val + " to an int value");
+ }
+ }
}
protected ServerAddress createServerAddress()
@@ -627,47 +686,27 @@
}
catch (SocketException sex)
{
- log.debug(this + " got SocketException " + sex);
-
- try
- {
- semaphore.release();
- if (trace) log.trace(this + " released semaphore: " + semaphore.permits());
- socketWrapper.close();
- }
- catch (Exception ex)
- {
- if (trace) { log.trace(this + " couldn't successfully close its socketWrapper", ex); }
- }
-
- /**
- * About to run out of retries and
- * pool may be full of timed out sockets,
- * so want to flush the pool and try with
- * fresh socket as a last effort.
- */
- if (retryCount == (numberOfCallRetries - 2))
- {
- flushConnectionPool();
- }
+ handleSocketException(sex, socketWrapper, semaphore, retryCount);
sockEx = sex;
continue;
}
- catch (Exception ex)
+ catch (IOException e)
{
- log.debug(this + " got exception " + ex);
-
- try
+ if (isGeneralizeSocketException() && e.getMessage().startsWith("Connection reset"))
{
- semaphore.release();
- if (trace) log.trace(this + " released semaphore: " + semaphore.permits());
- socketWrapper.close();
+ handleSocketException(e, socketWrapper, semaphore, retryCount);
+ sockEx = new SocketException(e.getMessage());
+ continue;
}
- catch (Exception ignored)
+ else
{
+ return handleOtherException(e, semaphore, socketWrapper);
}
- return handleException(ex, socketWrapper);
}
+ catch (Exception ex)
+ {
+ return handleOtherException(ex, semaphore, socketWrapper);
+ }
// call worked, so no need to retry
break;
@@ -706,6 +745,51 @@
return response;
}
+
+ protected void handleSocketException(Exception sex, SocketWrapper socketWrapper, Semaphore semaphore, int retryCount)
+ {
+ log.debug(this + " got SocketException " + sex);
+
+ try
+ {
+ semaphore.release();
+ if (trace) log.trace(this + " released semaphore: " + semaphore.permits());
+ socketWrapper.close();
+ }
+ catch (Exception ex)
+ {
+ if (trace) { log.trace(this + " couldn't successfully close its socketWrapper", ex); }
+ }
+
+ /**
+ * About to run out of retries and
+ * pool may be full of timed out sockets,
+ * so want to flush the pool and try with
+ * fresh socket as a last effort.
+ */
+ if (retryCount == (numberOfCallRetries - 2))
+ {
+ flushConnectionPool();
+ }
+ }
+
+ protected Object handleOtherException(Exception ex, Semaphore semaphore, SocketWrapper socketWrapper)
+ throws ClassNotFoundException, MarshalException
+ {
+ log.debug(this + " got exception " + ex);
+
+ try
+ {
+ semaphore.release();
+ if (trace) log.trace(this + " released semaphore: " + semaphore.permits());
+ socketWrapper.close();
+ }
+ catch (Exception ignored)
+ {
+ }
+ return handleException(ex, socketWrapper);
+ }
+
protected Object handleException(Exception ex, SocketWrapper socketWrapper)
throws ClassNotFoundException, MarshalException
{
@@ -814,7 +898,10 @@
}
metadata.put(SocketWrapper.MARSHALLER, marshaller);
metadata.put(SocketWrapper.UNMARSHALLER, unmarshaller);
-
+ if (writeTimeout > 0)
+ {
+ metadata.put(SocketWrapper.WRITE_TIMEOUT, new Integer(writeTimeout));
+ }
if (timeAllowed > 0)
{
timeRemaining = (int) (timeAllowed - (System.currentTimeMillis() - start));
Modified: remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/ServerThread.java
===================================================================
--- remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/ServerThread.java 2009-10-08 19:58:47 UTC (rev 5555)
+++ remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/ServerThread.java 2009-10-09 20:35:17 UTC (rev 5556)
@@ -100,6 +100,7 @@
private Socket socket;
private int timeout;
+ private int writeTimeout;
protected SocketServerInvoker invoker;
private Constructor serverSocketConstructor;
protected SocketWrapper socketWrapper;
@@ -122,7 +123,7 @@
// Constructors ---------------------------------------------------------------------------------
public ServerThread(Socket socket, SocketServerInvoker invoker, LRUPool clientpool,
- LinkedList threadpool, int timeout, String serverSocketClassName)
+ LinkedList threadpool, int timeout, int writeTimeout, String serverSocketClassName)
throws Exception
{
super();
@@ -134,6 +135,7 @@
this.socket = socket;
this.timeout = timeout;
+ this.writeTimeout = writeTimeout;
this.serverSocketClassName = serverSocketClassName;
this.invoker = invoker;
this.clientpool = clientpool;
@@ -715,7 +717,11 @@
}
localMetadata.put(SocketWrapper.MARSHALLER, marshaller);
localMetadata.put(SocketWrapper.UNMARSHALLER, unmarshaller);
-
+ if (writeTimeout > 0)
+ {
+ localMetadata.put(SocketWrapper.WRITE_TIMEOUT, new Integer(writeTimeout));
+ }
+
serverSocketWrapper = (SocketWrapper)serverSocketConstructor.
newInstance(new Object[]{socket, localMetadata, new Integer(timeout)});
}
Modified: remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java
===================================================================
--- remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java 2009-10-08 19:58:47 UTC (rev 5555)
+++ remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java 2009-10-09 20:35:17 UTC (rev 5556)
@@ -95,6 +95,8 @@
// defaults to -1 as to not have idle timeouts
protected int idleTimeout = -1;
protected IdleTimerTask idleTimerTask = null;
+
+ protected int writeTimeout = -1;
public SocketServerInvoker(InvokerLocator locator)
{
@@ -376,7 +378,7 @@
}
/**
- * @return Value of property serverBindPort.
+ * @return Number of idle ServerThreads
* @jmx:managed-attribute
*/
public int getCurrentThreadPoolSize()
@@ -385,7 +387,7 @@
}
/**
- * @return Value of property serverBindPort.
+ * @return Number of ServerThreads current executing or waiting on an invocation
* @jmx:managed-attribute
*/
public int getCurrentClientPoolSize()
@@ -498,7 +500,17 @@
}
}
}
+
+ public int getWriteTimeout()
+ {
+ return writeTimeout;
+ }
+ public void setWriteTimeout(int writeTimeout)
+ {
+ this.writeTimeout = writeTimeout;
+ }
+
public void run()
{
if(trace) { log.trace(this + " started execution of method run()"); }
@@ -594,7 +606,7 @@
if(trace) { log.trace(this + " creating new worker thread"); }
worker = new ServerThread(socket, this, clientpool, threadpool,
- getTimeout(), serverSocketClass);
+ getTimeout(), writeTimeout, serverSocketClass);
if(trace) { log.trace(this + " created " + worker); }
Modified: remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/SocketWrapper.java
===================================================================
--- remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/SocketWrapper.java 2009-10-08 19:58:47 UTC (rev 5555)
+++ remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/SocketWrapper.java 2009-10-09 20:35:17 UTC (rev 5556)
@@ -42,6 +42,7 @@
public static final String MARSHALLER = "marshaller";
public static final String UNMARSHALLER = "unmarshaller";
public static final String TEMP_TIMEOUT = "temptimeout";
+ public static final String WRITE_TIMEOUT = "writeTimeout";
protected static final int CLOSING = 254;
@@ -51,7 +52,7 @@
// Attributes -----------------------------------------------------------------------------------
- private Socket socket;
+ protected Socket socket;
private int timeout;
// Constructors ---------------------------------------------------------------------------------
Copied: remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java (from rev 5370, remoting2/branches/2.2/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java)
===================================================================
--- remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java (rev 0)
+++ remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java 2009-10-09 20:35:17 UTC (rev 5556)
@@ -0,0 +1,160 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.remoting.transport.socket;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright April 22, 2009
+ * </p>
+ */
+public class TimedOutputStream extends OutputStream
+{
+ static private Timer timer = new Timer(true);
+ static private Logger log = Logger.getLogger(TimedOutputStream.class);
+
+ private OutputStream os;
+ private int outputTimeout;
+ private OutputTimerTask timerTask;
+ private Object lock = new Object();
+
+ public TimedOutputStream(OutputStream os, int outputTimeout)
+ {
+ this.os = os;
+ this.outputTimeout = outputTimeout;
+ }
+
+ public void close() throws IOException
+ {
+ os.close();
+ }
+
+ public void write(int b) throws IOException
+ {
+ synchronized (lock)
+ {
+ if (timerTask == null)
+ {
+ try
+ {
+ timerTask = new OutputTimerTask(this);
+ timer.schedule(timerTask, outputTimeout);
+ if (log.isTraceEnabled()) log.trace("scheduled OutputTimerTask: " + outputTimeout);
+ }
+ catch (IllegalStateException e)
+ {
+ timer = new Timer(true);
+ timer.schedule(new OutputTimerTask(this), outputTimeout);
+ if (log.isTraceEnabled()) log.trace("scheduled OutputTimerTask: " + outputTimeout);
+ }
+ }
+ }
+
+ try
+ {
+ os.write(b);
+ }
+ finally
+ {
+ synchronized (lock)
+ {
+ timerTask.cancel();
+ timerTask = null;
+ }
+ }
+ }
+
+ public void write(byte b[], int off, int len) throws IOException
+ {
+ synchronized (lock)
+ {
+ if (timerTask == null)
+ {
+ try
+ {
+ timerTask = new OutputTimerTask(this);
+ timer.schedule(timerTask, outputTimeout);
+ if (log.isTraceEnabled()) log.trace(this + " scheduled " + timerTask + ": " + outputTimeout);
+ }
+ catch (IllegalStateException e)
+ {
+// timer = new Timer("TimedOutputStreamTimer", true);
+ timer = new Timer(true);
+ timer.schedule(new OutputTimerTask(this), outputTimeout);
+ if (log.isTraceEnabled()) log.trace(this + " scheduled " + timerTask + ": " + outputTimeout);
+ }
+ }
+ }
+
+ try
+ {
+ os.write(b, off, len);
+ }
+ finally
+ {
+ synchronized (lock)
+ {
+ timerTask.cancel();
+ timerTask = null;
+ }
+ }
+ }
+
+ static class OutputTimerTask extends TimerTask
+ {
+ private TimedOutputStream tos;
+
+ public OutputTimerTask(TimedOutputStream tos)
+ {
+ this.tos = tos;
+ }
+
+ public void run()
+ {
+ try
+ {
+ log.debug(this + " closing: " + tos);
+ tos.close();
+ tos = null;
+ }
+ catch (IOException e)
+ {
+ log.debug("unable to close " + tos);
+ }
+ }
+
+ public boolean cancel()
+ {
+ tos = null;
+ return super.cancel();
+ }
+ }
+}
Modified: remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketServerInvoker.java
===================================================================
--- remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketServerInvoker.java 2009-10-08 19:58:47 UTC (rev 5555)
+++ remoting2/branches/2.2.2-SP7_JBREM-1120/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketServerInvoker.java 2009-10-09 20:35:17 UTC (rev 5556)
@@ -74,10 +74,6 @@
protected void setup() throws Exception
{
super.setup();
- if (isCallbackServer)
- {
- socketFactory = createSocketFactory(configuration);
- }
}
protected SocketFactory createSocketFactory(Map configuration)
Copied: remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/timeout/SSLBisocketWriteTimeoutTestCase.java (from rev 5374, remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/timeout/SSLBisocketWriteTimeoutTestCase.java)
===================================================================
--- remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/timeout/SSLBisocketWriteTimeoutTestCase.java (rev 0)
+++ remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/timeout/SSLBisocketWriteTimeoutTestCase.java 2009-10-09 20:35:17 UTC (rev 5556)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.bisocket.ssl.timeout;
+
+import org.jboss.test.remoting.transport.socket.timeout.SSLWriteTimeoutTestParent;
+
+/**
+ * Unit tests for JBREM-1120.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 22, 2009
+ * </p>
+ */
+public class SSLBisocketWriteTimeoutTestCase extends SSLWriteTimeoutTestParent
+{
+ protected String getTransport()
+ {
+ return "sslbisocket";
+ }
+}
Copied: remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/bisocket/timeout/BisocketWriteTimeoutTestCase.java (from rev 5374, remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/timeout/BisocketWriteTimeoutTestCase.java)
===================================================================
--- remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/bisocket/timeout/BisocketWriteTimeoutTestCase.java (rev 0)
+++ remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/bisocket/timeout/BisocketWriteTimeoutTestCase.java 2009-10-09 20:35:17 UTC (rev 5556)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.bisocket.timeout;
+
+import org.jboss.test.remoting.transport.socket.timeout.WriteTimeoutTestParent;
+
+/**
+ * Unit tests for JBREM-1120.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 22, 2009
+ * </p>
+ */
+public class BisocketWriteTimeoutTestCase extends WriteTimeoutTestParent
+{
+ protected String getTransport()
+ {
+ return "bisocket";
+ }
+}
Copied: remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketWriteTimeoutTestCase.java (from rev 5374, remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketWriteTimeoutTestCase.java)
===================================================================
--- remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketWriteTimeoutTestCase.java (rev 0)
+++ remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/ssl/timeout/SSLSocketWriteTimeoutTestCase.java 2009-10-09 20:35:17 UTC (rev 5556)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.socket.ssl.timeout;
+
+import org.jboss.test.remoting.transport.socket.timeout.SSLWriteTimeoutTestParent;
+
+/**
+ * Unit tests for JBREM-1120.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 22, 2009
+ * </p>
+ */
+public class SSLSocketWriteTimeoutTestCase extends SSLWriteTimeoutTestParent
+{
+ protected String getTransport()
+ {
+ return "sslsocket";
+ }
+}
Copied: remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java (from rev 5374, remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java)
===================================================================
--- remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java (rev 0)
+++ remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java 2009-10-09 20:35:17 UTC (rev 5556)
@@ -0,0 +1,580 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.socket.timeout;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.UnknownHostException;
+import java.util.Map;
+
+import javax.net.ServerSocketFactory;
+import javax.net.SocketFactory;
+import javax.net.ssl.HandshakeCompletedListener;
+import javax.net.ssl.SSLServerSocket;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSocket;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.security.SSLSocketBuilder;
+import org.jboss.remoting.transport.Connector;
+
+
+/**
+ * Unit tests for JBREM-1120.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 22, 2009
+ * </p>
+ */
+public abstract class SSLWriteTimeoutTestParent extends WriteTimeoutTestParent
+{
+ private static Logger log = Logger.getLogger(SSLWriteTimeoutTestParent.class);
+
+ private static boolean firstTime = true;
+
+ protected static int SECONDARY_SERVER_SOCKET_PORT = 8765;
+ protected static String SECONDARY_SERVER_SOCKET_PORT_STRING = "8765";
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ String keyStoreFilePath = getClass().getResource("../.keystore").getFile();
+ System.setProperty("javax.net.ssl.keyStore", keyStoreFilePath);
+ System.setProperty("javax.net.ssl.keyStorePassword", "unit-tests-server");
+ String trustStoreFilePath = getClass().getResource("../.truststore").getFile();
+ System.setProperty("javax.net.ssl.trustStore", trustStoreFilePath);
+ System.setProperty("javax.net.ssl.trustStorePassword", "unit-tests-client");
+ }
+ super.setUp();
+ }
+
+
+ protected String getServerSocketFactoryClassName()
+ {
+ return SSLTestServerSocketFactory.class.getName();
+ }
+
+ protected Constructor getServerSocketFactoryConstructor() throws NoSuchMethodException
+ {
+ return SSLTestServerSocketFactory.class.getConstructor(new Class[]{int.class, int.class});
+ }
+
+ protected String getSocketFactoryClassName()
+ {
+ return SSLTestSocketFactory.class.getName();
+ }
+
+ protected Constructor getSocketFactoryConstructor() throws NoSuchMethodException
+ {
+ return SSLTestSocketFactory.class.getConstructor(new Class[]{int.class, int.class});
+ }
+
+ static public class SSLTestServerSocketFactory extends ServerSocketFactory
+ {
+ int timeout;
+ ServerSocketFactory factory;
+ int initialWrites;
+
+ public SSLTestServerSocketFactory() throws IOException
+ {
+ this.timeout = 5000;
+ this.initialWrites = -1;
+ setupFactory();
+ }
+ public SSLTestServerSocketFactory(int timeout, int initialWrites) throws IOException
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ setupFactory();
+ }
+ public ServerSocket createServerSocket() throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket();
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+ public ServerSocket createServerSocket(int port) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != secondaryServerSocketPort)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket(port);
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(port, timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != secondaryServerSocketPort)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket(port, backlog);
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(port, backlog, timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != secondaryServerSocketPort)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket(port, backlog, ifAddress);
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(port, backlog, ifAddress, timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ protected void setupFactory() throws IOException
+ {
+ SSLSocketBuilder sslSocketBuilder = new SSLSocketBuilder();
+ sslSocketBuilder.setUseSSLServerSocketFactory(false);
+ factory = sslSocketBuilder.createSSLServerSocketFactory();
+ }
+ }
+
+
+ static class SSLTestServerSocket extends SSLServerSocket
+ {
+ int timeout;
+ int initialWrites;
+ SSLServerSocket serverSocket;
+
+ public SSLTestServerSocket(int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super();
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ }
+ public SSLTestServerSocket(int port, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super(port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ bind(new InetSocketAddress(port), 50);
+ }
+ public SSLTestServerSocket(int port, int backlog, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super(port, backlog);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ bind(new InetSocketAddress(port), backlog);
+ }
+ public SSLTestServerSocket(int port, int backlog, InetAddress bindAddr, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super(port, backlog, bindAddr);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ bind(new InetSocketAddress(bindAddr, port), 50);
+ }
+ public Socket accept() throws IOException
+ {
+ SSLSocket s1 = (SSLSocket) serverSocket.accept();
+ Socket s2 = new SSLTestSocket(timeout, initialWrites, s1);
+ return s2;
+ }
+ public void bind(SocketAddress endpoint, int backlog) throws IOException
+ {
+ log.info("serverSocket: " + serverSocket);
+ if (serverSocket != null) log.info("bound: " + serverSocket.isBound());
+ if (serverSocket != null && !serverSocket.isBound())
+ {
+ log.info("binding " + serverSocket);
+ serverSocket.bind(endpoint, backlog);
+ }
+ }
+ public String toString()
+ {
+ return "SSLTestServerSocket[" + serverSocket.toString() + "]";
+ }
+ public boolean getEnableSessionCreation()
+ {
+ return serverSocket.getEnableSessionCreation();
+ }
+ public String[] getEnabledCipherSuites()
+ {
+ return serverSocket.getEnabledCipherSuites();
+ }
+ public String[] getEnabledProtocols()
+ {
+ return serverSocket.getEnabledProtocols();
+ }
+ public InetAddress getInetAddress()
+ {
+ return serverSocket.getInetAddress();
+ }
+ public boolean getNeedClientAuth()
+ {
+ return serverSocket.getNeedClientAuth();
+ }
+ public String[] getSupportedCipherSuites()
+ {
+ return serverSocket.getSupportedCipherSuites();
+ }
+ public String[] getSupportedProtocols()
+ {
+ return serverSocket.getSupportedProtocols();
+ }
+ public boolean getUseClientMode()
+ {
+ return serverSocket.getUseClientMode();
+ }
+ public boolean getWantClientAuth()
+ {
+ return serverSocket.getWantClientAuth();
+ }
+ public void setEnableSessionCreation(boolean arg0)
+ {
+ serverSocket.setEnableSessionCreation(arg0);
+ }
+ public void setEnabledCipherSuites(String[] arg0)
+ {
+ serverSocket.setEnabledCipherSuites(arg0);
+ }
+ public void setEnabledProtocols(String[] arg0)
+ {
+ serverSocket.setEnabledProtocols(arg0);
+ }
+ public void setNeedClientAuth(boolean arg0)
+ {
+ serverSocket.setNeedClientAuth(arg0);
+ }
+ public void setUseClientMode(boolean arg0)
+ {
+ serverSocket.setUseClientMode(arg0);
+ }
+ public void setWantClientAuth(boolean arg0)
+ {
+ serverSocket.setWantClientAuth(arg0);
+ }
+ }
+
+
+ public static class SSLTestSocketFactory extends SocketFactory
+ {
+ int timeout;
+ int initialWrites;
+ SocketFactory factory;
+
+ public SSLTestSocketFactory() throws IOException
+ {
+ timeout = 5000;
+ initialWrites = -1;
+ setupFactory();
+ }
+ public SSLTestSocketFactory(int timeout, int initialWrites) throws IOException
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ setupFactory();
+ }
+ public Socket createSocket() throws IOException
+ {
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest)
+ {
+ s = factory.createSocket();
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ s = new SSLTestSocket(timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+ public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
+ {
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = factory.createSocket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ s = new SSLTestSocket(arg0, arg1, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1) throws IOException
+ {
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = factory.createSocket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ s = new SSLTestSocket(arg0, arg1, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
+ {
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = factory.createSocket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ s = new SSLTestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
+ {
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = factory.createSocket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ s = new SSLTestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+
+ protected void setupFactory() throws IOException
+ {
+ SSLSocketBuilder sslSocketBuilder = new SSLSocketBuilder();
+ sslSocketBuilder.setUseSSLServerSocketFactory(false);
+ factory = sslSocketBuilder.createSSLSocketFactory();
+ }
+ }
+
+ static class SSLTestSocket extends SSLSocket
+ {
+ int timeout;
+ int initialWrites;
+ SSLSocket socket;
+ SocketAddress endpoint;
+
+ public SSLTestSocket(int timeout, int initialWrites, SSLSocket socket)
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ }
+ public SSLTestSocket(String host, int port, int timeout, int initialWrites, SSLSocket socket) throws UnknownHostException, IOException
+ {
+ super(host, port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ connect(new InetSocketAddress(host, port), timeout);
+ }
+ public SSLTestSocket(InetAddress address, int port, int timeout, int initialWrites, SSLSocket socket) throws IOException
+ {
+ super(address, port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ connect(new InetSocketAddress(address, port), timeout);
+ }
+ public SSLTestSocket(String host, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites, SSLSocket socket) throws IOException
+ {
+ super(host, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ bind(new InetSocketAddress(localAddr, localPort));
+ connect(new InetSocketAddress(host, port), timeout);
+ }
+ public SSLTestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites, SSLSocket socket) throws IOException
+ {
+ super(address, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ bind(new InetSocketAddress(localAddr, localPort));
+ connect(new InetSocketAddress(address, port), timeout);
+ }
+ public String toString()
+ {
+ return "SSLTestSocket[" + socket.toString() + "]";
+ }
+ public InputStream getInputStream() throws IOException
+ {
+ return socket.getInputStream();
+ }
+ public OutputStream getOutputStream() throws IOException
+ {
+ return new TestOutputStream(socket.getOutputStream(), timeout, initialWrites);
+ }
+ public void addHandshakeCompletedListener(HandshakeCompletedListener listener)
+ {
+ socket.addHandshakeCompletedListener(listener);
+ }
+ public void bind(SocketAddress bindpoint) throws IOException
+ {
+ if (socket != null)
+ socket.bind(bindpoint);
+ }
+ public void connect(SocketAddress endpoint) throws IOException
+ {
+ if (socket != null)
+ socket.connect(endpoint);
+ }
+ public void connect(SocketAddress endpoint, int timeout) throws IOException
+ {
+ socket.connect(endpoint, timeout);
+ }
+ public boolean getEnableSessionCreation()
+ {
+ return socket.getEnableSessionCreation();
+ }
+ public String[] getEnabledCipherSuites()
+ {
+ return socket.getEnabledCipherSuites();
+ }
+ public String[] getEnabledProtocols()
+ {
+ return socket.getEnabledProtocols();
+ }
+ public InetAddress getInetAddress()
+ {
+ return socket.getInetAddress();
+ }
+ public boolean getNeedClientAuth()
+ {
+ return socket.getNeedClientAuth();
+ }
+ public SSLSession getSession()
+ {
+ return socket.getSession();
+ }
+ public String[] getSupportedCipherSuites()
+ {
+ return socket.getSupportedCipherSuites();
+ }
+ public String[] getSupportedProtocols()
+ {
+ return socket.getSupportedProtocols();
+ }
+ public boolean getUseClientMode()
+ {
+ return socket.getUseClientMode();
+ }
+ public boolean getWantClientAuth()
+ {
+ return socket.getWantClientAuth();
+ }
+ public void removeHandshakeCompletedListener(HandshakeCompletedListener listener)
+ {
+ socket.removeHandshakeCompletedListener(listener);
+ }
+ public void setEnableSessionCreation(boolean flag)
+ {
+ socket.setEnableSessionCreation(flag);
+ }
+ public void setEnabledCipherSuites(String[] suites)
+ {
+ socket.setEnabledCipherSuites(suites);
+ }
+ public void setEnabledProtocols(String[] protocols)
+ {
+ socket.setEnabledProtocols(protocols);
+ }
+ public void setNeedClientAuth(boolean need)
+ {
+ socket.setNeedClientAuth(need);
+ }
+ public void setUseClientMode(boolean mode)
+ {
+ socket.setUseClientMode(mode);
+ }
+ public void setWantClientAuth(boolean want)
+ {
+ socket.setWantClientAuth(want);
+ }
+ public void startHandshake() throws IOException
+ {
+ socket.startHandshake();
+ }
+ }
+}
\ No newline at end of file
Copied: remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketWriteTimeoutTestCase.java (from rev 5374, remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketWriteTimeoutTestCase.java)
===================================================================
--- remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketWriteTimeoutTestCase.java (rev 0)
+++ remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/timeout/SocketWriteTimeoutTestCase.java 2009-10-09 20:35:17 UTC (rev 5556)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.socket.timeout;
+
+/**
+ * Unit tests for JBREM-1120.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 22, 2009
+ * </p>
+ */
+public class SocketWriteTimeoutTestCase extends WriteTimeoutTestParent
+{
+ protected String getTransport()
+ {
+ return "socket";
+ }
+}
Copied: remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java (from rev 5374, remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java)
===================================================================
--- remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java (rev 0)
+++ remoting2/branches/2.2.2-SP7_JBREM-1120/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java 2009-10-09 20:35:17 UTC (rev 5556)
@@ -0,0 +1,845 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.transport.socket.timeout;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.rmi.MarshalException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.net.ServerSocketFactory;
+import javax.net.SocketFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.CannotConnectException;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.Remoting;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.bisocket.Bisocket;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+import org.jboss.remoting.transport.socket.SocketWrapper;
+
+
+/**
+ * Unit tests for JBREM-1120.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 22, 2009
+ * </p>
+ */
+public abstract class WriteTimeoutTestParent extends TestCase
+{
+ private static Logger log = Logger.getLogger(WriteTimeoutTestParent.class);
+
+ private static boolean firstTime = true;
+ protected static int secondaryServerSocketPort;
+ protected static boolean callbackTest;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+
+ TestOutputStream.counter = 0;
+ callbackTest = false;
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testClientWriteTimeout() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(false, false, "", -1, -1);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(SocketWrapper.WRITE_TIMEOUT, "1000");
+ SocketFactory sf = (SocketFactory) getSocketFactoryConstructor().newInstance(new Object[]{new Integer(5000), new Integer(1)});
+ clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, sf);
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ log.info("**************************************");
+ log.info("*** WorkerThread error is expected ***");
+ log.info("**************************************");
+
+ // Test client side write timeout.
+ try
+ {
+ client.invoke("abc");
+ }
+ catch (MarshalException e)
+ {
+ log.info(e.getMessage());
+ assertNotNull(e.getMessage());
+ log.info("e.getMessage(): " + e.getMessage());
+ assertTrue(e.getMessage().startsWith("Failed to communicate. Problem during marshalling/unmarshalling"));
+ assertTrue(e.getCause() instanceof IOException);
+ IOException ioe = (IOException) e.getCause();
+ assertEquals("closed", ioe.getMessage());
+ log.info("got expected Exception");
+ }
+ catch (Throwable t)
+ {
+ log.error("got unexpected Exception", t);
+ fail("got unexpected Exception");
+ }
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testServerWriteTimeout() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, false, "1000", 5000, 1);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("numberOfCallRetries", "1");
+ clientConfig.put("timeout", "10000");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ log.info("**************************************");
+ log.info("*** WorkerThread error is expected ***");
+ log.info("**************************************");
+
+ // Test server side write timeout.
+ try
+ {
+ client.invoke("abc");
+ }
+ catch (MarshalException e)
+ {
+ log.info(e.getMessage());
+// assertNotNull(e.getMessage());
+// assertTrue(e.getMessage().startsWith("Unable to perform invocation"));
+// assertTrue(e.getCause() instanceof EOFException);
+ log.info("got expected Exception");
+ }
+ catch (Throwable t)
+ {
+ log.error("got unexpected Exception", t);
+ fail("got unexpected Exception");
+ }
+
+ // Test server invoker state.
+ Thread.sleep(4000);
+ SocketServerInvoker serverInvoker = (SocketServerInvoker) connector.getServerInvoker();
+ assertEquals(0, serverInvoker.getCurrentClientPoolSize());
+ assertEquals(1, serverInvoker.getCurrentThreadPoolSize());
+ log.info("used ServerThread has returned to threadPool");
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testClientCallbackWriteTimeout() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ if (isBisocket(getTransport()))
+ {
+ callbackTest = true;
+ }
+ setupServer(false, false, "", -1, -1);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(SocketWrapper.WRITE_TIMEOUT, "1000");
+ if (isBisocket(getTransport()))
+ {
+ SocketFactory sf = (SocketFactory) getSocketFactoryConstructor().newInstance(new Object[]{new Integer(5000), new Integer(1)});
+ clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, sf);
+ }
+ else
+ {
+ ServerSocketFactory ssf = (ServerSocketFactory) getServerSocketFactoryConstructor().newInstance(new Object[]{new Integer(5000), new Integer(-1)});
+ clientConfig.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, ssf);
+ }
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection
+ client.invoke("abc");
+ log.info("connection is good");
+
+ // Test client callback write timeout.
+ log.info("registering callback handler");
+ log.info("**************************************");
+ log.info("*** WorkerThread error is expected ***");
+ log.info("**************************************");
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ HashMap metadata = new HashMap();
+ if (isBisocket(getTransport()))
+ {
+// metadata.put(SocketWrapper.WRITE_TIMEOUT, "1000");
+ metadata.put(Remoting.SOCKET_FACTORY_NAME, getSocketFactoryClassName());
+ metadata.put("numberOfCallRetries", "1");
+ metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ metadata.put(Bisocket.PING_FREQUENCY, "11111111");
+ }
+ else
+ {
+// metadata.put(SocketWrapper.WRITE_TIMEOUT, "1000");
+ metadata.put(ServerInvoker.SERVER_SOCKET_FACTORY, getServerSocketFactoryClassName());
+ metadata.put("numberOfCallRetries", "1");
+ }
+ client.addListener(callbackHandler, metadata, null, true);
+ log.info("called Client.addListener()");
+
+ // Test server invoker state.
+ // Wait for local ServerThread to time out. Might take a while in bisocket transports, since
+ // the request to get a socket for the callback client invoker needs its own write on the
+ // control socket.
+ Thread.sleep(20000);
+ log.info("back from sleep");
+ Set callbackConnectors = client.getCallbackConnectors(callbackHandler);
+ assertEquals(1, callbackConnectors.size());
+ Connector callbackConnector = (Connector) callbackConnectors.iterator().next();
+ SocketServerInvoker serverInvoker = (SocketServerInvoker) callbackConnector.getServerInvoker();
+ assertEquals(0, serverInvoker.getCurrentClientPoolSize());
+ assertEquals(1, serverInvoker.getCurrentThreadPoolSize());
+ log.info("used ServerThread has returned to threadPool");
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testServerCallbackWriteTimeout() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ if (isBisocket(getTransport()))
+ {
+ callbackTest = true;
+ setupServer(true, false, "1000", 5000, 1);
+ }
+ else
+ {
+ setupServer(false, true, "1000", 5000, 1);
+ }
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put("numberOfCallRetries", "1");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection
+ client.invoke("abc");
+ log.info("connection is good");
+
+ // Test server callback write timeout.
+ log.info("registering callback handler");
+ log.info("**************************************");
+ log.info("*** WorkerThread error is expected ***");
+ log.info("**************************************");
+ HashMap metadata = new HashMap();
+ if (isBisocket(getTransport()))
+ {
+ metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ }
+ TestCallbackHandler callbackHandler = new TestCallbackHandler();
+ client.addListener(callbackHandler, metadata, null, true);
+ log.info("added listener");
+
+ // Test server invoker state.
+ Thread.sleep(20000);
+ log.info("waking up");
+ Throwable t = invocationHandler.t;
+ assertTrue(t instanceof HandleCallbackException);
+ log.info("t.getCause:", t.getCause());
+ if (t.getCause() instanceof MarshalException)
+ {
+ MarshalException e = (MarshalException) t.getCause();
+ assertNotNull(e.getMessage());
+ assertTrue(e.getMessage().startsWith("Failed to communicate. Problem during marshalling/unmarshalling"));
+ assertTrue(e.getCause() instanceof IOException);
+ IOException ioe = (IOException) e.getCause();
+ assertEquals("closed", ioe.getMessage());
+ }
+ else
+ {
+ assertTrue(t.getCause() instanceof CannotConnectException);
+ log.info("t.getCause().getCause(): ", t.getCause().getCause());
+ assertTrue(t.getCause().getCause() instanceof InvocationTargetException);
+ log.info("t.getCause().getCause().getCause(): ", t.getCause().getCause().getCause());
+// assertTrue(t.getCause().getCause().getCause() instanceof SSLProtocolException);
+ assertTrue(t.getCause().getCause().getCause() instanceof IOException);
+ assertEquals("closed", t.getCause().getCause().getCause().getMessage());
+ }
+ log.info("got expected Exception");
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected abstract String getTransport();
+
+ protected boolean isBisocket(String transport)
+ {
+ return transport.indexOf("bisocket") >= 0;
+ }
+
+ protected String getServerSocketFactoryClassName()
+ {
+ return TestServerSocketFactory.class.getName();
+ }
+
+ protected Constructor getServerSocketFactoryConstructor() throws NoSuchMethodException
+ {
+ return TestServerSocketFactory.class.getConstructor(new Class[]{int.class, int.class});
+ }
+
+ protected String getSocketFactoryClassName()
+ {
+ return TestSocketFactory.class.getName();
+ }
+
+ protected Constructor getSocketFactoryConstructor() throws NoSuchMethodException
+ {
+ return TestSocketFactory.class.getConstructor(new Class[]{int.class, int.class});
+ }
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(boolean setWriteTimeout, boolean setCallbackWriteTimeout,
+ String writeTimeout, int blockingTime, int initialWrites) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "/?" + metadata;
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ if (isBisocket(getTransport()))
+ {
+ secondaryServerSocketPort = PortUtil.findFreePort(host);
+ config.put(Bisocket.SECONDARY_BIND_PORT, Integer.toString(secondaryServerSocketPort));
+ config.put(Bisocket.PING_FREQUENCY, "11111111");
+ }
+ if (setWriteTimeout)
+ {
+ config.put(SocketWrapper.WRITE_TIMEOUT, writeTimeout);
+ ServerSocketFactory ssf = (ServerSocketFactory) getServerSocketFactoryConstructor().newInstance(new Object[]{new Integer(blockingTime), new Integer(initialWrites)});
+ config.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, ssf);
+ }
+ if (setCallbackWriteTimeout)
+ {
+ config.put(SocketWrapper.WRITE_TIMEOUT, writeTimeout);
+ SocketFactory sf = (SocketFactory) getSocketFactoryConstructor().newInstance(new Object[]{new Integer(blockingTime), new Integer(initialWrites)});
+ config.put(Remoting.CUSTOM_SOCKET_FACTORY, sf);
+ }
+ if (callbackTest)
+ {
+ config.put("numberOfCallRetries", "1");
+ }
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ Throwable t;
+
+ public void addListener(final InvokerCallbackHandler callbackHandler)
+ {
+ new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ log.info("sending callback");
+ callbackHandler.handleCallback(new Callback("callback"));
+ }
+ catch (Throwable t)
+ {
+ log.info("throwable: ", t);
+ TestInvocationHandler.this.t = t;
+ }
+ }
+ }.start();
+ }
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback");
+ }
+ }
+
+
+ static public class TestServerSocketFactory extends ServerSocketFactory
+ {
+ int timeout;
+ int initialWrites;
+
+ public TestServerSocketFactory()
+ {
+ this.timeout = 5000;
+ this.initialWrites = -1;
+ }
+ public TestServerSocketFactory(int timeout, int initialWrites)
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public ServerSocket createServerSocket() throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest)
+ {
+ ss = ServerSocketFactory.getDefault().createServerSocket();
+ }
+ else
+ {
+ ss = new TestServerSocket(timeout, initialWrites);
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+ public ServerSocket createServerSocket(int port) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != secondaryServerSocketPort)
+ {
+ ss = ServerSocketFactory.getDefault().createServerSocket(port);
+ }
+ else
+ {
+ ss = new TestServerSocket(port, timeout, initialWrites);
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != secondaryServerSocketPort)
+ {
+ ss = ServerSocketFactory.getDefault().createServerSocket(port, backlog);
+ }
+ else
+ {
+ ss = new TestServerSocket(port, backlog, timeout, initialWrites);
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException
+ {
+ ServerSocket ss = null;
+ if (callbackTest && port != secondaryServerSocketPort)
+ {
+ ss = ServerSocketFactory.getDefault().createServerSocket(port, backlog, ifAddress);
+ }
+ else
+ {
+ ss = new TestServerSocket(port, backlog, ifAddress, timeout, initialWrites);
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+ }
+
+
+ static class TestServerSocket extends ServerSocket
+ {
+ int timeout;
+ int initialWrites;
+
+ public TestServerSocket(int timeout, int initialWrites) throws IOException
+ {
+ super();
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestServerSocket(int port, int timeout, int initialWrites) throws IOException
+ {
+ super(port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestServerSocket(int port, int backlog, int timeout, int initialWrites) throws IOException
+ {
+ super(port, backlog);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestServerSocket(int port, int backlog, InetAddress bindAddr, int timeout, int initialWrites) throws IOException
+ {
+ super(port, backlog, bindAddr);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public Socket accept() throws IOException
+ {
+ Socket s = new TestSocket(timeout, initialWrites);
+ implAccept(s);
+ return s;
+ }
+ public String toString()
+ {
+ return "TestServerSocket[" + getLocalPort() + "]";
+ }
+ }
+
+
+ public static class TestSocketFactory extends SocketFactory
+ {
+ int timeout;
+ int initialWrites = -1;
+
+ public TestSocketFactory()
+ {
+ timeout = 5000;
+ }
+ public TestSocketFactory(int timeout, int initialWrites)
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public Socket createSocket()
+ {
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest)
+ {
+ s = new Socket();
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+ public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
+ {
+ log.info("callbackTest: " + callbackTest + ", port: " + arg1);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = new Socket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(arg0, arg1, timeout, initialWrites);
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1) throws IOException
+ {
+ log.info("callbackTest: " + callbackTest + ", port: " + arg1);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = new Socket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(arg0, arg1, timeout, initialWrites);
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
+ {
+ log.info("callbackTest: " + callbackTest + ", port: " + arg1);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = new Socket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites);
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
+ {
+ log.info("callbackTest: " + callbackTest + ", port: " + arg1);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = new Socket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites);
+ }
+ log.info(this + " returning " + s);
+ return s;
+ }
+ }
+
+ static class TestSocket extends Socket
+ {
+ int timeout;
+ int initialWrites;
+
+ public TestSocket(int timeout, int initialWrites)
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestSocket(String host, int port, int timeout, int initialWrites) throws UnknownHostException, IOException
+ {
+ super(host, port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestSocket(InetAddress address, int port, int timeout, int initialWrites) throws IOException
+ {
+ super(address, port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestSocket(String host, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites) throws IOException
+ {
+ super(host, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites) throws IOException
+ {
+ super(address, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public OutputStream getOutputStream() throws IOException
+ {
+ return new TestOutputStream(super.getOutputStream(), timeout, initialWrites);
+ }
+ public String toString()
+ {
+ return "TestSocket[" + getLocalPort() + "->" + getPort() + "]";
+ }
+ }
+
+ static class TestOutputStream extends OutputStream
+ {
+ OutputStream os;
+ int timeout;
+ boolean closed;
+ int initialWrites;
+ boolean doWait = true;
+ public static int counter;
+
+ public TestOutputStream(OutputStream os, int timeout, int initialWrites)
+ {
+ this.os = os;
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public void close()throws IOException
+ {
+ closed = true;
+ super.close();
+ log.info(this + " closed");
+ }
+ public void write(int b) throws IOException
+ {
+ System.out.print("b: " + b);
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ if (doWait && ++counter > initialWrites)
+ {
+ try
+ {
+ log.info("TestOutputStream.write() sleeping: " + timeout);
+ Thread.sleep(timeout);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ os.write(b);
+ }
+ public void write(byte b[], int off, int len) throws IOException
+ {
+ System.out.print("b: ");
+ for (int i = 0; i < len; i++)
+ {
+ System.out.print(b[i] + " ");
+ }
+ System.out.println("");
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ log.info("TestOutputStream: counter = " + counter + ", initialWrites = " + initialWrites);
+ if (++counter > initialWrites)
+ {
+ try
+ {
+ log.info("TestOutputStream.write() sleeping: " + timeout);
+ Thread.sleep(timeout);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
+ try
+ {
+ log.info(this + " calling write()");
+ doWait = false;
+ os.write(b, off, len);
+ os.flush();
+ doWait = true;
+ log.info(this + " back from write()");
+ }
+ catch (IOException e)
+ {
+ log.info("exception: ", e);
+ throw e;
+ }
+ }
+ }
+}
\ No newline at end of file
15 years, 2 months
JBoss Remoting SVN: r5555 - remoting2/branches.
by jboss-remoting-commits@lists.jboss.org
Author: jbertram(a)redhat.com
Date: 2009-10-08 15:58:47 -0400 (Thu, 08 Oct 2009)
New Revision: 5555
Added:
remoting2/branches/2.2.2-SP7_JBREM-1120/
Log:
[JBPAPP-2899]
Copied: remoting2/branches/2.2.2-SP7_JBREM-1120 (from rev 5554, remoting2/tags/2.2.2-SP7)
15 years, 2 months
JBoss Remoting SVN: r5554 - remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-10-02 12:22:27 -0400 (Fri, 02 Oct 2009)
New Revision: 5554
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java
Log:
javadocs
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java 2009-10-01 20:56:19 UTC (rev 5553)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Options.java 2009-10-02 16:22:27 UTC (rev 5554)
@@ -41,31 +41,31 @@
/**
* Request that the marshalling layer require the presense of one of the listed user-defined class tables, in order of decreasing preference. If
- * not specified, no user class table should be used.
+ * not specified, no user class table should be used. The string {@code "none"} indicates no class table.
*/
public static final Option<Sequence<String>> MARSHALLING_CLASS_TABLES = Option.sequence(Options.class, "MARSHALLING_CLASS_TABLES", String.class);
/**
* Request that the marshalling layer require the presense of one of the listed user-defined object tables, in order of decreasing preference. If
- * not specified, no user object table should be used.
+ * not specified, no user object table should be used. The string {@code "none"} indicates no object table.
*/
public static final Option<Sequence<String>> MARSHALLING_OBJECT_TABLES = Option.sequence(Options.class, "MARSHALLING_OBJECT_TABLES", String.class);
/**
* Request that the marshalling layer require the presense of one of the listed class resolvers, in order of decreasing preference. If
- * not specified, classes are resolved on the remote side using a default strategy.
+ * not specified, classes are resolved on the remote side using a default strategy. The string {@code "default"} indicates the default class resolver.
*/
public static final Option<Sequence<String>> MARSHALLING_CLASS_RESOLVERS = Option.sequence(Options.class, "MARSHALLING_CLASS_RESOLVERS", String.class);
/**
* Request that the marshalling layer require the presense of one of the listed object resolvers, in order of decreasing preference. If
- * not specified, no object substitution will take place.
+ * not specified, no object substitution will take place. The string {@code "none"} indicates no object resolver.
*/
public static final Option<Sequence<String>> MARSHALLING_OBJECT_RESOLVERS = Option.sequence(Options.class, "MARSHALLING_OBJECT_RESOLVERS", String.class);
/**
* Request that the marshalling layer require the presense of one of the listed user-defined externalizer factories, in order of decreasing preference. If
- * not specified, no user externalizer factory should be used.
+ * not specified, no user externalizer factory should be used. The string {@code "none"} indicates no externalizer factory.
*/
public static final Option<Sequence<String>> MARSHALLING_EXTERNALIZER_FACTORIES = Option.sequence(Options.class, "MARSHALLING_EXTERNALIZER_FACTORIES", String.class);
15 years, 2 months
JBoss Remoting SVN: r5553 - in remoting3/trunk/jboss-remoting: src/main/java/org/jboss/remoting3 and 2 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-10-01 16:56:19 -0400 (Thu, 01 Oct 2009)
New Revision: 5553
Modified:
remoting3/trunk/jboss-remoting/pom.xml
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Client.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientImpl.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractHandleableCloseable.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/stream/InputStreamHandlerFactory.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/stream/OutputStreamHandlerFactory.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/stream/StreamHandler.java
Log:
Bring API up to XNIO 2 compatibility
Modified: remoting3/trunk/jboss-remoting/pom.xml
===================================================================
--- remoting3/trunk/jboss-remoting/pom.xml 2009-10-01 20:18:15 UTC (rev 5552)
+++ remoting3/trunk/jboss-remoting/pom.xml 2009-10-01 20:56:19 UTC (rev 5553)
@@ -34,7 +34,7 @@
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-api</artifactId>
- <version>1.2.0.GA</version>
+ <version>2.0.0.CR3-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Client.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Client.java 2009-10-01 20:18:15 UTC (rev 5552)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Client.java 2009-10-01 20:56:19 UTC (rev 5553)
@@ -108,7 +108,7 @@
*
* @return a future representing the result of the request
*
- * @throws ObjectStreamException if marshalling or unmarshalling some part of the request failed
+ * @throws ObjectStreamException if marshalling some part of the request failed
* @throws IOException if some other I/O error occurred while sending the request
*/
IoFuture<? extends O> send(I request) throws IOException;
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientImpl.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientImpl.java 2009-10-01 20:18:15 UTC (rev 5552)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientImpl.java 2009-10-01 20:56:19 UTC (rev 5553)
@@ -75,7 +75,7 @@
final ReplyHandler replyHandler = futureReply.getReplyHandler();
final RemoteRequestContext requestContext = handler.receiveRequest(actualRequest, replyHandler);
futureReply.setRemoteRequestContext(requestContext);
- futureReply.addNotifier(IoUtils.<O>attachmentClosingNotifier(), executor);
+ futureReply.addNotifier(IoUtils.attachmentClosingNotifier(), executor);
executor.runQueue();
try {
final O reply = futureReply.getInterruptibly();
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractHandleableCloseable.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractHandleableCloseable.java 2009-10-01 20:18:15 UTC (rev 5552)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractHandleableCloseable.java 2009-10-01 20:56:19 UTC (rev 5553)
@@ -115,7 +115,7 @@
log.trace("Closed %s", this);
if (closeHandlers != null) {
for (final CloseHandler<? super T> handler : closeHandlers.values()) {
- runCloseTask(executor, new CloseHandlerTask<T>(handler));
+ runCloseTask(executor, new CloseHandlerTask(handler));
}
}
closeAction();
@@ -143,11 +143,11 @@
return key;
}
}
- runCloseTask(executor, new CloseHandlerTask<T>(handler));
+ runCloseTask(executor, new CloseHandlerTask(handler));
return new NullKey();
}
- private static <T extends HandleableCloseable<T>> void runCloseTask(final Executor executor, final CloseHandlerTask<T> task) {
+ private static void runCloseTask(final Executor executor, final Runnable task) {
try {
executor.execute(task);
} catch (RejectedExecutionException ree) {
@@ -232,7 +232,7 @@
}
}
- private final class CloseHandlerTask<T extends HandleableCloseable<T>> implements Runnable {
+ private final class CloseHandlerTask implements Runnable {
private final CloseHandler<? super T> handler;
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/stream/InputStreamHandlerFactory.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/stream/InputStreamHandlerFactory.java 2009-10-01 20:18:15 UTC (rev 5552)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/stream/InputStreamHandlerFactory.java 2009-10-01 20:56:19 UTC (rev 5553)
@@ -27,8 +27,8 @@
import java.nio.ByteBuffer;
import java.nio.channels.Channel;
import org.jboss.xnio.IoFuture;
-import org.jboss.xnio.IoHandler;
import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.ChannelListener;
import org.jboss.xnio.channels.StreamChannel;
import org.jboss.xnio.log.Logger;
@@ -56,26 +56,21 @@
streamContext = context;
}
- public IoHandler<StreamChannel> getLocalHandler() {
- return new IoHandler<StreamChannel>() {
- public void handleOpened(final StreamChannel channel) {
+ public ChannelListener<StreamChannel> getLocalHandler() {
+ return new ChannelListener<StreamChannel>() {
+ public void handleEvent(final StreamChannel channel) {
+ channel.getCloseSetter().set(new ChannelListener<StreamChannel>() {
+ public void handleEvent(final StreamChannel channel) {
+ IoUtils.safeClose(localInstance);
+ }
+ });
streamContext.execute(new LocalRunnable(channel, localInstance));
}
-
- public void handleClosed(final StreamChannel channel) {
- IoUtils.safeClose(localInstance);
- }
-
- public void handleReadable(final StreamChannel channel) {
- }
-
- public void handleWritable(final StreamChannel channel) {
- }
};
}
- public IoHandler<Channel> getRemoteHandler() {
- return IoUtils.nullHandler();
+ public ChannelListener<Channel> getRemoteHandler() {
+ return IoUtils.nullChannelListener();
}
public InputStream getRemoteProxy(final IoFuture<? extends StreamChannel> futureChannel) {
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/stream/OutputStreamHandlerFactory.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/stream/OutputStreamHandlerFactory.java 2009-10-01 20:18:15 UTC (rev 5552)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/stream/OutputStreamHandlerFactory.java 2009-10-01 20:56:19 UTC (rev 5553)
@@ -33,8 +33,8 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.jboss.xnio.IoFuture;
-import org.jboss.xnio.IoHandler;
-import static org.jboss.xnio.IoUtils.nullHandler;
+import org.jboss.xnio.ChannelListener;
+import org.jboss.xnio.IoUtils;
import static org.jboss.xnio.IoUtils.safeClose;
import org.jboss.xnio.channels.ChannelInputStream;
import org.jboss.xnio.channels.StreamChannel;
@@ -59,12 +59,12 @@
localInstance = instance;
}
- public IoHandler<StreamChannel> getLocalHandler() {
+ public ChannelListener<StreamChannel> getLocalHandler() {
return new LocalHandler(localInstance);
}
- public IoHandler<Channel> getRemoteHandler() {
- return nullHandler();
+ public ChannelListener<Channel> getRemoteHandler() {
+ return IoUtils.nullChannelListener();
}
public OutputStream getRemoteProxy(final IoFuture<? extends StreamChannel> futureChannel) {
@@ -72,7 +72,7 @@
}
}
- private static final class LocalHandler implements IoHandler<StreamChannel> {
+ private static final class LocalHandler implements ChannelListener<StreamChannel> {
private final OutputStream localInstance;
private final byte[] bytes = new byte[1024];
@@ -80,33 +80,33 @@
localInstance = instance;
}
- public void handleOpened(final StreamChannel channel) {
- }
-
- public void handleClosed(final StreamChannel channel) {
- safeClose(localInstance);
- }
-
- public void handleReadable(final StreamChannel channel) {
- final byte[] bytes = this.bytes;
- final ByteBuffer buffer = ByteBuffer.wrap(bytes);
- try {
- for (;;) {
- final int res = channel.read(buffer);
- if (res == 0) {
- channel.resumeReads();
- return;
+ public void handleEvent(final StreamChannel channel) {
+ channel.getCloseSetter().set(new ChannelListener<StreamChannel>() {
+ public void handleEvent(final StreamChannel channel) {
+ safeClose(localInstance);
+ }
+ });
+ channel.getReadSetter().set(new ChannelListener<StreamChannel>() {
+ public void handleEvent(final StreamChannel channel) {
+ final byte[] bytes = LocalHandler.this.bytes;
+ final ByteBuffer buffer = ByteBuffer.wrap(bytes);
+ try {
+ for (;;) {
+ final int res = channel.read(buffer);
+ if (res == 0) {
+ channel.resumeReads();
+ return;
+ }
+ localInstance.write(bytes, 0, buffer.position());
+ buffer.clear();
+ }
+ } catch (IOException e) {
+ safeClose(channel);
}
- localInstance.write(bytes, 0, buffer.position());
- buffer.clear();
}
- } catch (IOException e) {
- safeClose(channel);
- }
+ });
+ channel.resumeReads();
}
-
- public void handleWritable(final StreamChannel channel) {
- }
}
private static final class ProxyOutputStream extends OutputStream {
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/stream/StreamHandler.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/stream/StreamHandler.java 2009-10-01 20:18:15 UTC (rev 5552)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/stream/StreamHandler.java 2009-10-01 20:56:19 UTC (rev 5553)
@@ -22,8 +22,8 @@
package org.jboss.remoting3.stream;
-import org.jboss.xnio.IoHandler;
import org.jboss.xnio.IoFuture;
+import org.jboss.xnio.ChannelListener;
import java.nio.channels.Channel;
import java.io.Serializable;
@@ -39,20 +39,20 @@
public interface StreamHandler<T, C extends Channel> extends Serializable {
/**
- * Get the local XNIO handler for this stream. If this handler is cached on the object, it should be
+ * Get the local XNIO open handler for this stream. If this handler is cached on the object, it should be
* done in a {@code transient} fashion to prevent the local handler from being sent to the remote side.
*
* @return the local XNIO handler
*/
- IoHandler<? super C> getLocalHandler();
+ ChannelListener<? super C> getLocalHandler();
/**
- * Get the remote XNIO handler for this stream. The remote handler should not be instantiated until the
+ * Get the remote XNIO open handler for this stream. The remote handler should not be instantiated until the
* {@code StreamHandler} instance is on the remote side to avoid copying the handler across the wire.
*
* @return the remote XNIO handler
*/
- IoHandler<? super C> getRemoteHandler();
+ ChannelListener<? super C> getRemoteHandler();
/**
* Get the remote proxy instance for this stream. The remote proxy should not be instantiated until the
@@ -62,5 +62,5 @@
* @param futureChannel the future channel
* @return the remote proxy instance
*/
- T getRemoteProxy(final IoFuture<? extends C> futureChannel);
+ T getRemoteProxy(IoFuture<? extends C> futureChannel);
}
15 years, 2 months
JBoss Remoting SVN: r5552 - remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-10-01 16:18:15 -0400 (Thu, 01 Oct 2009)
New Revision: 5552
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractHandleableCloseable.java
Log:
Carlo reminds us that we should not have private instance methods on abstract classes.
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractHandleableCloseable.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractHandleableCloseable.java 2009-09-22 16:43:04 UTC (rev 5551)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/AbstractHandleableCloseable.java 2009-10-01 20:18:15 UTC (rev 5552)
@@ -115,7 +115,7 @@
log.trace("Closed %s", this);
if (closeHandlers != null) {
for (final CloseHandler<? super T> handler : closeHandlers.values()) {
- runCloseTask(new CloseHandlerTask<T>(handler));
+ runCloseTask(executor, new CloseHandlerTask<T>(handler));
}
}
closeAction();
@@ -143,11 +143,11 @@
return key;
}
}
- runCloseTask(new CloseHandlerTask<T>(handler));
+ runCloseTask(executor, new CloseHandlerTask<T>(handler));
return new NullKey();
}
- private void runCloseTask(final CloseHandlerTask<T> task) {
+ private static <T extends HandleableCloseable<T>> void runCloseTask(final Executor executor, final CloseHandlerTask<T> task) {
try {
executor.execute(task);
} catch (RejectedExecutionException ree) {
15 years, 2 months