JBoss Remoting SVN: r5085 - in remoting2/branches/2.x/src/main/org/jboss/remoting/transport: sslbisocket and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-22 23:36:18 -0400 (Wed, 22 Apr 2009)
New Revision: 5085
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketServerInvoker.java
Log:
JBREM-1120: Moved SocketFactory creation from SSLBisocketServerInvoker to BisocketServerInvoker.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java 2009-04-22 23:59:35 UTC (rev 5084)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java 2009-04-23 03:36:18 UTC (rev 5085)
@@ -726,6 +726,11 @@
{
secondaryConnectPorts = new ArrayList(secondaryBindPorts);
}
+
+ if (isCallbackServer)
+ {
+ socketFactory = createSocketFactory(configuration);
+ }
}
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketServerInvoker.java 2009-04-22 23:59:35 UTC (rev 5084)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/sslbisocket/SSLBisocketServerInvoker.java 2009-04-23 03:36:18 UTC (rev 5085)
@@ -122,11 +122,6 @@
o = configuration.get("enabledProtocols");
if (o instanceof String[])
setEnabledProtocols((String[]) o);
-
- if (isCallbackServer)
- {
- socketFactory = createSocketFactory(configuration);
- }
}
protected SocketFactory createSocketFactory(Map configuration)
15 years, 8 months
JBoss Remoting SVN: r5084 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-22 19:59:35 -0400 (Wed, 22 Apr 2009)
New Revision: 5084
Added:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java
Log:
JBREM-1120: New OutputStream for output timeout facility.
Added: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java (rev 0)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/TimedOutputStream.java 2009-04-22 23:59:35 UTC (rev 5084)
@@ -0,0 +1,127 @@
+package org.jboss.remoting.transport.socket;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.apache.log4j.Logger;
+
+public class TimedOutputStream extends OutputStream
+{
+ static private Timer timer = new Timer("TimedOutputStreamTimer", 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);
+ }
+ catch (IllegalStateException e)
+ {
+ timer = new Timer("TimedOutputStreamTimer", true);
+ timer.schedule(new OutputTimerTask(this), outputTimeout);
+ log.info("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);
+ }
+ catch (IllegalStateException e)
+ {
+ timer = new Timer("TimedOutputStreamTimer", true);
+ timer.schedule(new OutputTimerTask(this), 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.info("closing: " + tos);
+ tos.close();
+ tos = null;
+ }
+ catch (IOException e)
+ {
+ log.debug("unable to close " + tos);
+ }
+ }
+
+ public boolean cancel()
+ {
+ tos = null;
+ return super.cancel();
+ }
+ }
+}
15 years, 8 months
JBoss Remoting SVN: r5083 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-22 19:58:56 -0400 (Wed, 22 Apr 2009)
New Revision: 5083
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketWrapper.java
Log:
JBREM-1120: Added WRITE_TIMEOUT constant; also, removed some old commented code.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketWrapper.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketWrapper.java 2009-04-22 23:58:00 UTC (rev 5082)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketWrapper.java 2009-04-22 23:58:56 UTC (rev 5083)
@@ -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;
@@ -93,35 +94,6 @@
public void close() throws IOException
{
-// InputStream in = getInputStream();
-// if (in != null)
-// {
-// try
-// {
-// log.trace(this + " closing input stream");
-// in.close();
-// log.trace(this + " closed input stream");
-// }
-// catch (IOException e)
-// {
-// log.debug(this + " unable to close input stream");
-// }
-// }
-// OutputStream out = getOutputStream();
-// if (out != null)
-// {
-// try
-// {
-// log.trace(this + " closing output stream");
-// out.close();
-// log.trace(this + " closed input stream");
-// }
-// catch (IOException e)
-// {
-// log.debug(this + " unable to close output stream");
-// }
-// }
-
if(socket != null)
{
log.trace(this + " closing socket");
15 years, 8 months
JBoss Remoting SVN: r5082 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-22 19:58:00 -0400 (Wed, 22 Apr 2009)
New Revision: 5082
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java
Log:
JBREM-1120: Added writeTimeout facility; also, corrected some javadoc.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java 2009-04-22 23:57:04 UTC (rev 5081)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java 2009-04-22 23:58:00 UTC (rev 5082)
@@ -125,6 +125,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)
{
@@ -591,7 +593,7 @@
}
/**
- * @return Value of property serverBindPort.
+ * @return Number of idle ServerThreads
* @jmx:managed-attribute
*/
public int getCurrentThreadPoolSize()
@@ -600,7 +602,7 @@
}
/**
- * @return Value of property serverBindPort.
+ * @return Number of ServerThreads current executing or waiting on an invocation
* @jmx:managed-attribute
*/
public int getCurrentClientPoolSize()
@@ -724,6 +726,16 @@
this.immediateShutdown = immediateShutdown;
}
+ public int getWriteTimeout()
+ {
+ return writeTimeout;
+ }
+
+ public void setWriteTimeout(int writeTimeout)
+ {
+ this.writeTimeout = writeTimeout;
+ }
+
protected void configureSocket(Socket s) throws SocketException
{
s.setReuseAddress(getReuseAddress());
@@ -769,7 +781,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); }
newThread = true;
}
15 years, 8 months
JBoss Remoting SVN: r5081 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-22 19:57:04 -0400 (Wed, 22 Apr 2009)
New Revision: 5081
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java
Log:
JBREM-1120: Added writeTimeout facility.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java 2009-04-22 23:56:19 UTC (rev 5080)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ServerThread.java 2009-04-22 23:57:04 UTC (rev 5081)
@@ -120,6 +120,7 @@
private Socket socket;
private int timeout;
+ private int writeTimeout;
protected SocketServerInvoker invoker;
private Constructor serverSocketConstructor;
protected SocketWrapper socketWrapper;
@@ -156,7 +157,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();
@@ -166,6 +167,7 @@
this.socket = socket;
this.timeout = timeout;
+ this.writeTimeout = writeTimeout;
this.serverSocketClassName = serverSocketClassName;
this.invoker = invoker;
this.clientpool = clientpool;
@@ -686,7 +688,7 @@
protected void processInvocation(SocketWrapper socketWrapper, InputStream inputStream, OutputStream outputStream) throws Exception
{
- if(trace) { log.trace("preparing to process next invocation invocation"); }
+ if(trace) { log.trace("preparing to process next invocation"); }
// Ok, now read invocation and invoke
@@ -927,7 +929,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)});
}
15 years, 8 months
JBoss Remoting SVN: r5080 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-22 19:56:19 -0400 (Wed, 22 Apr 2009)
New Revision: 5080
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
Log:
JBREM-1120: Added writeTimeout 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-04-22 23:55:41 UTC (rev 5079)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2009-04-22 23:56:19 UTC (rev 5080)
@@ -91,6 +91,9 @@
/** Key for setting time to wait to get permission to get a connection */
public static final String CONNECTION_WAIT = "connectionWait";
+ /** Key for setting socket write timeout */
+ public static final String WRITE_TIMEOUT = "writeTimeout";
+
/**
* Default value for enable TCP nodelay. Value is false.
*/
@@ -247,6 +250,8 @@
protected boolean soLingerSet;
protected int soLingerDuration = -1;
protected int trafficClass = -1;
+
+ protected int writeTimeout = -1;
// Constructors ---------------------------------------------------------------------------------
@@ -384,6 +389,16 @@
this.trafficClass = trafficClass;
}
+ public int getWriteTimeout()
+ {
+ return writeTimeout;
+ }
+
+ public void setWriteTimeout(int writeTimeout)
+ {
+ this.writeTimeout = writeTimeout;
+ }
+
public synchronized void disconnect()
{
log.debug(this + " disconnecting ...");
@@ -612,6 +627,22 @@
val + " to a boolean value");
}
}
+
+ // 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(InetAddress addr, int port)
@@ -1102,7 +1133,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));
15 years, 8 months
JBoss Remoting SVN: r5079 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-22 19:55:41 -0400 (Wed, 22 Apr 2009)
New Revision: 5079
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ClientSocketWrapper.java
Log:
JBREM-1120: Added writeTimeout variable.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ClientSocketWrapper.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ClientSocketWrapper.java 2009-04-22 02:55:12 UTC (rev 5078)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/ClientSocketWrapper.java 2009-04-22 23:55:41 UTC (rev 5079)
@@ -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
@@ -156,6 +167,15 @@
log.trace("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);
+ }
+ }
}
out = createOutputStream(serializationType, socket, marshaller);
@@ -192,6 +212,11 @@
log.warn("got null marshaller");
OutputStream os = socket.getOutputStream();
+ if (writeTimeout > 0)
+ {
+ os = new TimedOutputStream(os, writeTimeout);
+ }
+
if (marshaller instanceof PreferredStreamMarshaller)
{
PreferredStreamMarshaller psm = (PreferredStreamMarshaller) marshaller;
15 years, 8 months
JBoss Remoting SVN: r5078 - remoting2/branches/2.x/docs/guide/en.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-21 22:55:12 -0400 (Tue, 21 Apr 2009)
New Revision: 5078
Modified:
remoting2/branches/2.x/docs/guide/en/chap5.xml
Log:
JBREM-1123: Added discussion of SocketServerInvoker's immediateShutdown parameter.
Modified: remoting2/branches/2.x/docs/guide/en/chap5.xml
===================================================================
--- remoting2/branches/2.x/docs/guide/en/chap5.xml 2009-04-21 05:42:20 UTC (rev 5077)
+++ remoting2/branches/2.x/docs/guide/en/chap5.xml 2009-04-22 02:55:12 UTC (rev 5078)
@@ -1474,6 +1474,24 @@
</listitem>
</orderedlist>
+ <para><emphasis role="bold">Note.</emphasis> When a
+ <classname>ServerThread</classname> receives an invocation, it enters a
+ synchronized method to prevent itself from being interrupted while it is
+ processing the invocation. When <methodname>SocketServerInvoker.stop()</methodname>
+ is called, it calls the synchronized method <methodname>ServerThread.shutdown()</methodname>
+ for each <classname>ServerThread</classname>, which insures that the server
+ does not shut down until all currently invocations are complete.
+ </para>
+
+ <para>However, if it happens that an invocation gets hung up for some reason, the
+ server would be prevented from shutting down. For example, the
+ <classname>ServerInvocationHandler</classname> could have a bug, or an attempt
+ to write to a disconnected network could get hung up. As of Release 2.5.2, there
+ is an option to shut down a <classname>SocketServerInvoker</classname> immediately
+ without waiting for current invocations to complete. This option can be enabled
+ by setting the property "immediateShutdown" to "true".
+ </para>
+
<bridgehead><emphasis role="bold">Client</emphasis></bridgehead>
<para>When the socket client invoker makes its first invocation, it will
@@ -1513,9 +1531,9 @@
<section>
<title>Configuration</title>
- <para>The following configuration properties can be set at any time, but
- will not take effect until the socket invoker, on the server side, is
- stopped and restarted.</para>
+ <para>The following configuration properties can be set at any time. If
+ the <classname>SocketServerInvoker</classname> has already started, they
+ will not take effect until it is stopped and restarted.</para>
<para><emphasis role="bold">timeout</emphasis> - The socket timeout
value passed to the Socket.setSoTimeout() method. The default on the
@@ -1567,6 +1585,12 @@
continue to wait for an invocation; otherwise, it will return itself to
the thread pool.</para>
+ <para><emphasis role="bold">immediateShutdown</emphasis> - indicates, when
+ set to "true", that, when <methodname>Connector.stop()</methodname> is
+ called and it calls <methodname>SocketServerInvoker.stop()</methodname>,
+ all <classname>ServerThread</classname>s are shut down immediately,
+ even if they are processing an invocation.</para>
+
<bridgehead>Configurations affecting the Socket invoker
client</bridgehead>
@@ -6592,6 +6616,13 @@
value is 'serverSocketClass') - specifies the fully qualified class name
for the custom SocketWrapper implementation to use on the server.</para>
+ <para><emphasis role="bold">Bean properties (meaning have getter/setter):</emphasis></para>
+
+ <para><emphasis role="bold">ImmediateShutdown</emphasis> - a flag for indicating
+ that <classname>SocketServerInvoker</classname> should shut down all of its
+ <classname>ServerThreads</classname> immediately instead of waiting for any
+ current invocations to finish.</para>
+
</section>
</section>
15 years, 8 months
JBoss Remoting SVN: r5077 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-21 01:42:20 -0400 (Tue, 21 Apr 2009)
New Revision: 5077
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory/UseAllSocketFactoryParamsTestCase.java
Log:
JBREM-1121: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory/UseAllSocketFactoryParamsTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory/UseAllSocketFactoryParamsTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory/UseAllSocketFactoryParamsTestCase.java 2009-04-21 05:42:20 UTC (rev 5077)
@@ -0,0 +1,320 @@
+/*
+* 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.socketfactory;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+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.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.InvokerCallbackHandler;
+import org.jboss.remoting.socketfactory.SocketCreationListener;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ * Unit tests for JBREM-1121.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Rev$
+ * <p>
+ * Copyright Apr 21, 2009
+ * </p>
+ */
+public class UseAllSocketFactoryParamsTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(UseAllSocketFactoryParamsTestCase.class);
+
+ private static boolean firstTime = true;
+
+ 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(Level.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);
+ }
+
+ TestSocketCreationListener.called = false;
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testDefault() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(false, null);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ log.info("clientConfig: " + clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify that TestSocketCreationListener was called.
+ assertFalse(TestSocketCreationListener.called);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseAllSocketFactoryParamsFalseInLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, "false");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ log.info("clientConfig: " + clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify that TestSocketCreationListener was called.
+ assertFalse(TestSocketCreationListener.called);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseAllSocketFactoryParamsFalseInConfig() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(false, null);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.USE_ALL_SOCKET_FACTORY_PARAMS, "false");
+ addExtraClientConfig(clientConfig);
+ log.info("clientConfig: " + clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify that TestSocketCreationListener was called.
+ assertFalse(TestSocketCreationListener.called);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseAllSocketFactoryParamsTrueInLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, "true");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ log.info("clientConfig: " + clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify that TestSocketCreationListener was called.
+ assertTrue(TestSocketCreationListener.called);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testUseAllSocketFactoryParamsTrueInConfig() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(false, null);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.USE_ALL_SOCKET_FACTORY_PARAMS, "true");
+ addExtraClientConfig(clientConfig);
+ log.info("clientConfig: " + clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify that TestSocketCreationListener was called.
+ assertTrue(TestSocketCreationListener.called);
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(boolean setUseAllParams, String useAllParams) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ locatorURI += "/?" + Remoting.SOCKET_CREATION_CLIENT_LISTENER + "=" + TestSocketCreationListener.class.getName();
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "&" + metadata;
+ }
+ if (setUseAllParams)
+ {
+ locatorURI += "&" + Remoting.USE_ALL_SOCKET_FACTORY_PARAMS + "=" + useAllParams;
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ 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
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ 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) {}
+ }
+
+
+ public static class TestSocketCreationListener implements SocketCreationListener
+ {
+ static public boolean called;
+
+ public TestSocketCreationListener()
+ {
+ log.info("TestSocketCreationListener created");
+ }
+
+ public void socketCreated(Socket socket, Object source) throws IOException
+ {
+ called = true;
+ log.info("TestSocketCreationListener called");
+ }
+ }
+}
\ No newline at end of file
15 years, 8 months
JBoss Remoting SVN: r5076 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-21 01:34:17 -0400 (Tue, 21 Apr 2009)
New Revision: 5076
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory/SocketFactoryClassNameTestRoot.java
Log:
JBREM-1121: Added variation of existing test methods with "useAllSocketFactoryParams=true" in InvokerLocator.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory/SocketFactoryClassNameTestRoot.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory/SocketFactoryClassNameTestRoot.java 2009-04-21 05:29:34 UTC (rev 5075)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory/SocketFactoryClassNameTestRoot.java 2009-04-21 05:34:17 UTC (rev 5076)
@@ -1,3 +1,24 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, 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.socketfactory;
import java.io.IOException;
@@ -16,7 +37,6 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
-import org.jboss.logging.XLevel;
import org.jboss.remoting.AbstractInvoker;
import org.jboss.remoting.Client;
import org.jboss.remoting.InvocationRequest;
@@ -57,7 +77,7 @@
if (firstTime)
{
firstTime = false;
- Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.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);
@@ -77,11 +97,11 @@
log.info("entering " + getName());
// Start server.
- setupServer();
+ setupServer(false);
// Create client.
String clientLocatorURI = locatorURI;
- clientLocatorURI += "/?" + Remoting.SOCKET_FACTORY_CLASS_NAME + "=" + getSocketFactoryClass().getName();
+ clientLocatorURI += "&" + Remoting.SOCKET_FACTORY_CLASS_NAME + "=" + getSocketFactoryClass().getName();
InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
HashMap clientConfig = new HashMap();
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
@@ -111,7 +131,7 @@
log.info("entering " + getName());
// Start server.
- setupServer();
+ setupServer(false);
// Create client.
InvokerLocator clientLocator = new InvokerLocator(locatorURI);
@@ -139,6 +159,73 @@
}
+ public void testSocketFactoryClassNameInLocatorWithUseAllParams() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true);
+
+ // Create client.
+ String clientLocatorURI = locatorURI;
+ clientLocatorURI += "&" + Remoting.SOCKET_FACTORY_CLASS_NAME + "=" + getSocketFactoryClass().getName();
+ InvokerLocator clientLocator = new InvokerLocator(clientLocatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected to " + clientLocatorURI);
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify client invoker is using configured SocketFactory.
+ AbstractInvoker invoker = (AbstractInvoker) client.getInvoker();
+ SocketFactory socketFactory = invoker.getSocketFactory();
+ log.info("SocketFactory: " + socketFactory);
+ assertTrue(getSocketFactoryClass().isInstance(socketFactory));
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testSocketFactoryClassNameInConfigMapWithUseAllParams() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Remoting.SOCKET_FACTORY_CLASS_NAME, getSocketFactoryClass().getName());
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Verify client invoker is using configured SocketFactory.
+ AbstractInvoker invoker = (AbstractInvoker) client.getInvoker();
+ SocketFactory socketFactory = invoker.getSocketFactory();
+ log.info("SocketFactory: " + socketFactory);
+ assertTrue(getSocketFactoryClass().isInstance(socketFactory));
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
protected abstract String getTransport();
@@ -152,11 +239,20 @@
protected void addExtraServerConfig(Map config) {}
- protected void setupServer() throws Exception
+ protected void setupServer(boolean useAllParams) throws Exception
{
host = InetAddress.getLocalHost().getHostAddress();
port = PortUtil.findFreePort(host);
- locatorURI = getTransport() + "://" + host + ":" + port;
+ locatorURI = getTransport() + "://" + host + ":" + port + "/?x=x";
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "&" + metadata;
+ }
+ if (useAllParams)
+ {
+ locatorURI += "&" + Remoting.USE_ALL_SOCKET_FACTORY_PARAMS + "=true";
+ }
serverLocator = new InvokerLocator(locatorURI);
log.info("Starting remoting server with locator uri of: " + locatorURI);
HashMap config = new HashMap();
15 years, 8 months