JBoss Remoting SVN: r4444 - in remoting2/branches/2.x/src/tests/org/jboss/test/remoting: transport/bisocket/socketfactory and 8 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-07-31 19:32:40 -0400 (Thu, 31 Jul 2008)
New Revision: 4444
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory/SSLSocketFactoryClassNameTestRoot.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory/SocketFactoryClassNameTestRoot.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/socketfactory/SocketFactoryClassNameTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/socketfactory/
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/socketfactory/SocketFactoryClassNameTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/socketfactory/SocketFactoryClassNameTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/socketfactory/SocketFactoryClassNameTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
Log:
JBREM-1015: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory/SSLSocketFactoryClassNameTestRoot.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory/SSLSocketFactoryClassNameTestRoot.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory/SSLSocketFactoryClassNameTestRoot.java 2008-07-31 23:32:40 UTC (rev 4444)
@@ -0,0 +1,100 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.net.UnknownHostException;
+
+import javax.net.SocketFactory;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.jboss.test.remoting.socketfactory.SocketFactoryClassNameTestRoot.TestSocketFactory;
+
+
+/**
+ *
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public abstract class SSLSocketFactoryClassNameTestRoot extends SocketFactoryClassNameTestRoot
+{
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ String trustStoreFilePath = this.getClass().getResource("../.truststore").getFile();
+ System.setProperty("javax.net.ssl.trustStore", trustStoreFilePath);
+ System.setProperty("javax.net.ssl.trustStorePassword", "unit-tests-client");
+ String keyStoreFilePath = this.getClass().getResource("../.keystore").getFile();
+ System.setProperty("javax.net.ssl.keyStore", keyStoreFilePath);
+ System.setProperty("javax.net.ssl.keyStorePassword", "unit-tests-server");
+ System.setProperty("org.jboss.security.ignoreHttpsHost", "true");
+ }
+
+ protected Class getSocketFactoryClass()
+ {
+ return TestSSLSocketFactory.class;
+ }
+
+ public static class TestSSLSocketFactory extends SocketFactory
+ {
+ SocketFactory sf = SSLSocketFactory.getDefault();
+
+ public TestSSLSocketFactory()
+ {
+ }
+
+ public Socket createSocket() throws IOException, UnknownHostException
+ {
+ return sf.createSocket();
+ }
+
+ public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
+ {
+ return sf.createSocket(arg0, arg1);
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1) throws IOException
+ {
+ return sf.createSocket(arg0, arg1);
+ }
+
+ public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException,
+ UnknownHostException
+ {
+ return sf.createSocket(arg0, arg1, arg2, arg3);
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
+ {
+ return sf.createSocket(arg0, arg1, arg2, arg3);
+ }
+ }
+}
+
Added: 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 (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/socketfactory/SocketFactoryClassNameTestRoot.java 2008-07-31 23:32:40 UTC (rev 4444)
@@ -0,0 +1,227 @@
+package org.jboss.test.remoting.socketfactory;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+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.AbstractInvoker;
+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.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+
+/**
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public abstract class SocketFactoryClassNameTestRoot extends TestCase
+{
+ private static Logger log = Logger.getLogger(SocketFactoryClassNameTestRoot.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(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);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testSocketFactoryClassNameInLocator() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // 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 testSocketFactoryClassNameInConfigMap() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // 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();
+
+
+ protected Class getSocketFactoryClass()
+ {
+ return TestSocketFactory.class;
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ 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 TestSocketFactory extends SocketFactory
+ {
+ SocketFactory sf = SocketFactory.getDefault();
+
+ public TestSocketFactory()
+ {
+ }
+
+ public Socket createSocket() throws IOException, UnknownHostException
+ {
+ return sf.createSocket();
+ }
+
+ public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
+ {
+ return sf.createSocket(arg0, arg1);
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1) throws IOException
+ {
+ return sf.createSocket(arg0, arg1);
+ }
+
+ public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException,
+ UnknownHostException
+ {
+ return sf.createSocket(arg0, arg1, arg2, arg3);
+ }
+
+ public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
+ {
+ return sf.createSocket(arg0, arg1, arg2, arg3);
+ }
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/socketfactory/SocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/socketfactory/SocketFactoryClassNameTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/socketfactory/SocketFactoryClassNameTestCase.java 2008-07-31 23:32:40 UTC (rev 4444)
@@ -0,0 +1,22 @@
+package org.jboss.test.remoting.transport.bisocket.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SocketFactoryClassNameTestRoot;
+
+
+/**
+ *
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SocketFactoryClassNameTestCase extends SocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "bisocket";
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java 2008-07-31 23:32:40 UTC (rev 4444)
@@ -0,0 +1,44 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SSLSocketFactoryClassNameTestRoot;
+
+
+/**
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SSLSocketFactoryClassNameTestCase extends SSLSocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "sslbisocket";
+ }
+}
+
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/socketfactory/SocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/socketfactory/SocketFactoryClassNameTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/socketfactory/SocketFactoryClassNameTestCase.java 2008-07-31 23:32:40 UTC (rev 4444)
@@ -0,0 +1,22 @@
+package org.jboss.test.remoting.transport.http.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SocketFactoryClassNameTestRoot;
+
+
+/**
+ *
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SocketFactoryClassNameTestCase extends SocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "http";
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java 2008-07-31 23:32:40 UTC (rev 4444)
@@ -0,0 +1,44 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.http.ssl.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SSLSocketFactoryClassNameTestRoot;
+
+
+/**
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SSLSocketFactoryClassNameTestCase extends SSLSocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "https";
+ }
+}
+
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/socketfactory/SocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/socketfactory/SocketFactoryClassNameTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/socketfactory/SocketFactoryClassNameTestCase.java 2008-07-31 23:32:40 UTC (rev 4444)
@@ -0,0 +1,22 @@
+package org.jboss.test.remoting.transport.rmi.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SocketFactoryClassNameTestRoot;
+
+
+/**
+ *
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SocketFactoryClassNameTestCase extends SocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "rmi";
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/rmi/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java 2008-07-31 23:32:40 UTC (rev 4444)
@@ -0,0 +1,44 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.rmi.ssl.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SSLSocketFactoryClassNameTestRoot;
+
+
+/**
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SSLSocketFactoryClassNameTestCase extends SSLSocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "sslrmi";
+ }
+}
+
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/socketfactory/SocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/socketfactory/SocketFactoryClassNameTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/socketfactory/SocketFactoryClassNameTestCase.java 2008-07-31 23:32:40 UTC (rev 4444)
@@ -0,0 +1,22 @@
+package org.jboss.test.remoting.transport.socket.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SocketFactoryClassNameTestRoot;
+
+
+/**
+ *
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SocketFactoryClassNameTestCase extends SocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "socket";
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/ssl/socketfactory/SSLSocketFactoryClassNameTestCase.java 2008-07-31 23:32:40 UTC (rev 4444)
@@ -0,0 +1,44 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.socketfactory;
+
+import org.jboss.test.remoting.socketfactory.SSLSocketFactoryClassNameTestRoot;
+
+
+/**
+ * Unit test for JBREM-1014.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 18, 2008
+ * </p>
+ */
+public class SSLSocketFactoryClassNameTestCase extends SSLSocketFactoryClassNameTestRoot
+{
+ protected String getTransport()
+ {
+ return "sslsocket";
+ }
+}
+
16 years, 4 months
JBoss Remoting SVN: r4443 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-07-31 19:20:48 -0400 (Thu, 31 Jul 2008)
New Revision: 4443
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/RemoteClientInvoker.java
Log:
JBREM-1015: Tries to get "socketFactoryClassName" from locator parameters when creating SocketFactory.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/RemoteClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/RemoteClientInvoker.java 2008-07-31 21:52:03 UTC (rev 4442)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/RemoteClientInvoker.java 2008-07-31 23:20:48 UTC (rev 4443)
@@ -43,6 +43,15 @@
public RemoteClientInvoker(InvokerLocator locator, Map configuration)
{
super(locator, configuration);
+ Map parameters = locator.getParameters();
+ if (parameters != null)
+ {
+ String socketFactoryClassName = (String) locator.parameters.get(Remoting.SOCKET_FACTORY_CLASS_NAME);
+ if (socketFactoryClassName != null)
+ {
+ configuration.put(Remoting.SOCKET_FACTORY_CLASS_NAME, socketFactoryClassName);
+ }
+ }
socketFactory = createSocketFactory(configuration);
}
}
16 years, 4 months
JBoss Remoting SVN: r4442 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-07-31 17:52:03 -0400 (Thu, 31 Jul 2008)
New Revision: 4442
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/AbstractInvoker.java
Log:
JBREM-1015: Uses new Remoting.SOCKET_FACTORY_CLASS_NAME parameter.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/AbstractInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/AbstractInvoker.java 2008-07-31 21:44:38 UTC (rev 4441)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/AbstractInvoker.java 2008-07-31 21:52:03 UTC (rev 4442)
@@ -351,6 +351,11 @@
if(factory == null)
{
String socketFactoryString = (String)configuration.get(Remoting.SOCKET_FACTORY_NAME);
+ if (socketFactoryString == null)
+ {
+ socketFactoryString = (String)configuration.get(Remoting.SOCKET_FACTORY_CLASS_NAME);
+ }
+
if(socketFactoryString != null && socketFactoryString.length() > 0)
{
try
16 years, 4 months
JBoss Remoting SVN: r4441 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2008-07-31 17:44:38 -0400 (Thu, 31 Jul 2008)
New Revision: 4441
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java
Log:
JBREM-1014: Added new SOCKET_FACTORY_CLASS_NAME parameter.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java 2008-07-31 00:33:26 UTC (rev 4440)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java 2008-07-31 21:44:38 UTC (rev 4441)
@@ -48,6 +48,12 @@
public static final String SOCKET_FACTORY_NAME = "socketFactory";
/**
+ * Key for the configuration map passed to a Client to indicate the classname of
+ * the socket factory to be used. This one is distinct from the bean property "socketFactory".
+ */
+ public static final String SOCKET_FACTORY_CLASS_NAME = "socketFactoryClassName";
+
+ /**
* Key for the configuration map passed to a Client or Connector to indicate
* a socket creation listener for sockets created by a SocketFactory.
*/
16 years, 4 months
JBoss Remoting SVN: r4440 - in remoting2/branches/2.x/src/main/org/jboss/remoting: loading and 1 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: scott.stark(a)jboss.org
Date: 2008-07-30 20:33:26 -0400 (Wed, 30 Jul 2008)
New Revision: 4440
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/AbstractInvoker.java
remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java
remoting2/branches/2.x/src/main/org/jboss/remoting/loading/RemotingClassLoader.java
remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
Log:
JBREM-1019, add a Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION = "classloadingParentFirstDelegation" invoker configuration option and
Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION_PROP = "org.jboss.remoting.classloadingParentFirstDelegation" system property for controlling the order the RemotingClassLoader uses for delegation to the parent and user class loaders. When true (the default, the parent class loader is delegated to before the user class loader.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/AbstractInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/AbstractInvoker.java 2008-07-30 15:30:52 UTC (rev 4439)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/AbstractInvoker.java 2008-07-31 00:33:26 UTC (rev 4440)
@@ -387,7 +387,11 @@
return wrapSocketFactory(factory, configuration);
}
-
+ protected Map getConfiguration()
+ {
+ return configuration;
+ }
+
static public SocketFactory wrapSocketFactory(SocketFactory socketFactory, Map config)
{
if (config == null)
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2008-07-30 15:30:52 UTC (rev 4439)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2008-07-31 00:33:26 UTC (rev 4440)
@@ -117,6 +117,19 @@
// classes. If possible, will simply reset context classloader on existing
// RemotingClassLoader.
final ClassLoader contextClassLoader = SecurityUtility.getContextClassLoader(Thread.currentThread());
+ // Get the parent delegation order flag, default is parent first
+ Object flag = super.getConfiguration().get(Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION);
+ if(flag == null)
+ {
+ // Fallback to the system property
+ flag = SecurityUtility.getSystemProperty(Remoting.CLASSLOADING_PARENT_FIRST_DELEGATION_PROP);
+ }
+ boolean parentFirst = true;
+ if (flag != null)
+ {
+ String sflag = flag.toString();
+ parentFirst = Boolean.valueOf(sflag);
+ }
if (unmarshaller instanceof UpdateableClassloaderUnMarshaller)
{
UpdateableClassloaderUnMarshaller uclum = (UpdateableClassloaderUnMarshaller) unmarshaller;
@@ -128,13 +141,13 @@
}
else
{
- rcl = SecurityUtility.createRemotingClassLoader(getClassLoader(), contextClassLoader);
+ rcl = SecurityUtility.createRemotingClassLoader(getClassLoader(), contextClassLoader, parentFirst);
unmarshaller.setClassLoader(rcl);
}
}
else
{
- rcl = SecurityUtility.createRemotingClassLoader(getClassLoader(), contextClassLoader);
+ rcl = SecurityUtility.createRemotingClassLoader(getClassLoader(), contextClassLoader, parentFirst);
unmarshaller.setClassLoader(rcl);
}
}
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java 2008-07-30 15:30:52 UTC (rev 4439)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java 2008-07-31 00:33:26 UTC (rev 4440)
@@ -75,4 +75,11 @@
* java.security.AccessController.doPrivileged() calls.
*/
public static final String SKIP_ACCESS_CONTROL = "skipAccessControl";
+
+ /**
+ * A flag indicating whether the RemotingClassLoader uses parent first (=true)
+ * or user class loader first delegation.
+ */
+ public static final String CLASSLOADING_PARENT_FIRST_DELEGATION = "classloadingParentFirstDelegation";
+ public static final String CLASSLOADING_PARENT_FIRST_DELEGATION_PROP = "org.jboss.remoting.classloadingParentFirstDelegation";
}
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/loading/RemotingClassLoader.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/loading/RemotingClassLoader.java 2008-07-30 15:30:52 UTC (rev 4439)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/loading/RemotingClassLoader.java 2008-07-31 00:33:26 UTC (rev 4440)
@@ -27,22 +27,30 @@
/**
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
+ * @version $Revision$
*/
public class RemotingClassLoader extends ClassLoader
{
private ClassLoader userClassLoader = null;
private int referenceCounter;
+ private boolean parentFirstDelegation;
protected static final Logger log = Logger.getLogger(RemotingClassLoader.class);
protected static final boolean isTrace = log.isTraceEnabled();
public RemotingClassLoader(ClassLoader remotingClassLoader, ClassLoader userClassLoader)
{
+ this(remotingClassLoader, userClassLoader, true);
+ }
+ public RemotingClassLoader(ClassLoader remotingClassLoader, ClassLoader userClassLoader,
+ boolean parentFirstDelegation)
+ {
super(remotingClassLoader);
this.userClassLoader = userClassLoader;
+ this.parentFirstDelegation = parentFirstDelegation;
referenceCounter = 1;
}
-
+
public synchronized void setUserClassLoader(ClassLoader userClassLoader)
throws Exception
{
@@ -67,9 +75,35 @@
{
Class loadedClass = null;
+ ClassLoader parent = getParent();
+ if (this.parentFirstDelegation || userClassLoader == null)
+ loadedClass = loadClassDelegate(name, parent, userClassLoader);
+ else
+ loadedClass = loadClassDelegate(name, userClassLoader, parent);
+
+ if(loadedClass == null)
+ {
+ loadedClass = ClassLoaderUtility.loadClass(name, getClass());
+ }
+
+ return loadedClass;
+ }
+
+ /**
+ * Try to load the named class using the primary and secondary class loaders.
+ * @param name - the class name to load
+ * @param primary - the initial class loader to delegate to
+ * @param secondary - the backup class loader to delegate to
+ * @return the loaded class
+ * @throws ClassNotFoundException
+ */
+ private Class loadClassDelegate(String name, ClassLoader primary, ClassLoader secondary)
+ throws ClassNotFoundException
+ {
+ Class loadedClass = null;
try
{
- loadedClass = Class.forName(name, false, getParent());
+ loadedClass = Class.forName(name, false, primary);
}
catch(ClassNotFoundException e)
{
@@ -77,11 +111,11 @@
{
log.trace("Could not load class (" + name + ") using parent remoting class loader (" + getParent() + ")");
}
- if(userClassLoader != null)
+ if(secondary != null)
{
try
{
- loadedClass = Class.forName(name, false, userClassLoader);
+ loadedClass = Class.forName(name, false, secondary);
}
catch (ClassNotFoundException e1)
{
@@ -92,13 +126,6 @@
}
}
}
-
- if(loadedClass == null)
- {
- loadedClass = ClassLoaderUtility.loadClass(name, getClass());
- }
-
return loadedClass;
}
-
}
\ No newline at end of file
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java 2008-07-30 15:30:52 UTC (rev 4439)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java 2008-07-31 00:33:26 UTC (rev 4440)
@@ -640,18 +640,24 @@
// RuntimePermission methods
///////////////////////////////////////////////////////////////////////////////////////
- static public RemotingClassLoader createRemotingClassLoader(final ClassLoader remotingClassLoader, final ClassLoader userClassLoader)
+ static public RemotingClassLoader createRemotingClassLoader(final ClassLoader remotingClassLoader,
+ final ClassLoader userClassLoader)
{
+ return createRemotingClassLoader(remotingClassLoader, userClassLoader, true);
+ }
+ static public RemotingClassLoader createRemotingClassLoader(final ClassLoader remotingClassLoader,
+ final ClassLoader userClassLoader, final boolean parentFirstDelegation)
+ {
if (skipAccessControl)
{
- return new RemotingClassLoader(remotingClassLoader, userClassLoader);
+ return new RemotingClassLoader(remotingClassLoader, userClassLoader, parentFirstDelegation);
}
return (RemotingClassLoader)AccessController.doPrivileged( new PrivilegedAction()
{
public Object run()
{
- return new RemotingClassLoader(remotingClassLoader, userClassLoader);
+ return new RemotingClassLoader(remotingClassLoader, userClassLoader, parentFirstDelegation);
}
});
}
16 years, 4 months
JBoss Remoting SVN: r4439 - in remoting3/trunk: api/src/main/java/org/jboss/cx/remoting/spi and 6 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-30 11:30:52 -0400 (Wed, 30 Jul 2008)
New Revision: 4439
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestContext.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractAutoCloseable.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/Handle.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RequestHandler.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RequestHandlerSource.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/RequestContextWrapper.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/LocalRequestHandlerSource.java
remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StreamingRot13RequestListener.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StringRot13RequestListener.java
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
Log:
More exception fiddling
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Endpoint.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -1,6 +1,7 @@
package org.jboss.cx.remoting;
import java.util.concurrent.ConcurrentMap;
+import java.io.IOException;
import org.jboss.cx.remoting.spi.remote.RequestHandler;
import org.jboss.cx.remoting.spi.remote.RequestHandlerSource;
import org.jboss.cx.remoting.spi.remote.Handle;
@@ -36,9 +37,9 @@
* @param <O> the reply type
* @param requestListener the request listener
* @return a handle for the client
- * @throws RemotingException if an error occurs
+ * @throws IOException if an error occurs
*/
- <I, O> Handle<RequestHandler> createRequestHandler(RequestListener<I, O> requestListener) throws RemotingException;
+ <I, O> Handle<RequestHandler> createRequestHandler(RequestListener<I, O> requestListener) throws IOException;
/**
* Create a request handler source that can be used to acquire clients associated with a request listener on this endpoint.
@@ -51,9 +52,9 @@
* @param <O> the reply type
* @param requestListener the request listener
* @return a handle for the client source
- * @throws RemotingException if an error occurs
+ * @throws IOException if an error occurs
*/
- <I, O> Handle<RequestHandlerSource> createRequestHandlerSource(RequestListener<I, O> requestListener) throws RemotingException;
+ <I, O> Handle<RequestHandlerSource> createRequestHandlerSource(RequestListener<I, O> requestListener) throws IOException;
/**
* Create a client that uses the given request handler to handle its requests.
@@ -62,9 +63,9 @@
* @param <O> the reply type
* @param handler the request handler
* @return the client
- * @throws RemotingException if an error occurs
+ * @throws IOException if an error occurs
*/
- <I, O> Client<I, O> createClient(RequestHandler handler) throws RemotingException;
+ <I, O> Client<I, O> createClient(RequestHandler handler) throws IOException;
/**
* Create a client source that uses the given request handler source to generate clients.
@@ -73,7 +74,7 @@
* @param <O> the reply type
* @param handlerSource the request handler source
* @return the client source
- * @throws RemotingException if an error occurs
+ * @throws IOException if an error occurs
*/
- <I, O> ClientSource<I, O> createClientSource(RequestHandlerSource handlerSource) throws RemotingException;
+ <I, O> ClientSource<I, O> createClientSource(RequestHandlerSource handlerSource) throws IOException;
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestContext.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestContext.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestContext.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -1,6 +1,7 @@
package org.jboss.cx.remoting;
import java.util.concurrent.Executor;
+import java.io.IOException;
/**
* The context of a single request.
@@ -26,10 +27,10 @@
* Send a reply back to the caller.
*
* @param reply the reply to send
- * @throws RemotingException if the transmission failed
+ * @throws IOException if the transmission failed
* @throws IllegalStateException if a reply was already sent
*/
- void sendReply(O reply) throws RemotingException, IllegalStateException;
+ void sendReply(O reply) throws IOException, IllegalStateException;
/**
* Send a failure message back to the caller.
@@ -37,18 +38,18 @@
* @param msg a message describing the failure, if any (can be {@code null})
* @param cause the failure cause, if any (can be {@code null})
*
- * @throws RemotingException if the transmission failed
+ * @throws IOException if the transmission failed
* @throws IllegalStateException if a reply was already sent
*/
- void sendFailure(String msg, Throwable cause) throws RemotingException, IllegalStateException;
+ void sendFailure(String msg, Throwable cause) throws IOException, IllegalStateException;
/**
* Send a cancellation message back to the client.
*
- * @throws RemotingException if the message could not be sent (the client could not be notified about the cancellation)
+ * @throws IOException if the message could not be sent (the client could not be notified about the cancellation)
* @throws IllegalStateException if a reply was already sent
*/
- void sendCancelled() throws RemotingException, IllegalStateException;
+ void sendCancelled() throws IOException, IllegalStateException;
/**
* Add a notifier to be called if a cancel request is received. The notifier may be called from the current thread
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractAutoCloseable.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractAutoCloseable.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractAutoCloseable.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -23,10 +23,9 @@
package org.jboss.cx.remoting.spi;
import java.util.concurrent.Executor;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import java.io.IOException;
import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.CloseHandler;
import org.jboss.cx.remoting.spi.remote.Handle;
import org.jboss.xnio.log.Logger;
@@ -54,9 +53,9 @@
/**
* Decrement the reference count by one. If the count drops to zero, the resource is closed.
*
- * @throws RemotingException if the reference count dropped to zero and the close operation threw an exception
+ * @throws IOException if the reference count dropped to zero and the close operation threw an exception
*/
- protected void dec() throws RemotingException {
+ protected void dec() throws IOException {
final int v = refcount.decrementAndGet();
if (v == 0) {
// we dropped the refcount to zero
@@ -80,13 +79,13 @@
*
* @throws RemotingException if the resource is closed
*/
- protected void inc() throws RemotingException {
+ protected void inc() throws IOException {
final int v = refcount.getAndIncrement();
log.trace("Raising reference count of %s to %d", this, Integer.valueOf(v + 1));
if (v < 0) {
// was already closed
refcount.decrementAndGet();
- throw new RemotingException("Resource is closed");
+ throw new IOException("Resource is closed");
}
}
@@ -97,17 +96,17 @@
* @return the handle
* @throws RemotingException if the resource is closed
*/
- public Handle<T> getHandle() throws RemotingException {
+ public Handle<T> getHandle() throws IOException {
return new HandleImpl();
}
private final class HandleImpl extends AbstractCloseable<Handle<T>> implements Handle<T> {
- private HandleImpl() throws RemotingException {
+ private HandleImpl() throws IOException {
super(AbstractAutoCloseable.this.executor);
inc();
}
- protected void closeAction() throws RemotingException {
+ protected void closeAction() throws IOException {
dec();
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -35,6 +35,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.io.IOException;
/**
* A basic implementation of a closeable resource. Use as a convenient base class for your closeable resources.
@@ -94,12 +95,12 @@
*
* @throws RemotingException if the close failed
*/
- protected void closeAction() throws RemotingException {}
+ protected void closeAction() throws IOException {}
/**
* {@inheritDoc}
*/
- public final void close() throws RemotingException {
+ public final void close() throws IOException {
if (! closed.getAndSet(true)) {
log.trace("Closed %s", this);
synchronized (closeLock) {
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/Handle.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/Handle.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/Handle.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -23,8 +23,8 @@
package org.jboss.cx.remoting.spi.remote;
import org.jboss.cx.remoting.Closeable;
-import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.CloseHandler;
+import java.io.IOException;
/**
* A handle to a local resource.
@@ -41,9 +41,9 @@
/**
* Close this reference.
*
- * @throws RemotingException if the close failed
+ * @throws IOException if the close failed
*/
- void close() throws RemotingException;
+ void close() throws IOException;
/**
* Add a handler that is invoked when this handle is closed.
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RequestHandler.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RequestHandler.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RequestHandler.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -25,6 +25,7 @@
import org.jboss.cx.remoting.Closeable;
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.CloseHandler;
+import java.io.IOException;
/**
* A request handler, which can be passed to remote endpoints. Remote systems can then use the handler
@@ -59,9 +60,9 @@
* warning of the leak.
*
* @return the handle
- * @throws RemotingException if a handle could not be acquired
+ * @throws IOException if a handle could not be acquired
*/
- Handle<RequestHandler> getHandle() throws RemotingException;
+ Handle<RequestHandler> getHandle() throws IOException;
/**
* Close this request handler. The outcome of any outstanding requests is not defined, though implementations
@@ -69,7 +70,7 @@
*
* @throws RemotingException if the client endpoint could not be closed
*/
- void close() throws RemotingException;
+ void close() throws IOException;
/**
* Add a handler that is called when the request handler is closed.
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RequestHandlerSource.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RequestHandlerSource.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RequestHandlerSource.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -25,6 +25,7 @@
import org.jboss.cx.remoting.Closeable;
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.CloseHandler;
+import java.io.IOException;
/**
* A request handler source, which can be passed to remote endpoints. Remote systems can then use the handler source
@@ -40,7 +41,7 @@
* @return a request handler
* @throws RemotingException if a client could not be opened
*/
- Handle<RequestHandler> createRequestHandler() throws RemotingException;
+ Handle<RequestHandler> createRequestHandler() throws IOException;
/**
* Get a handle to this request handler source. The request handler source will not auto-close as long as there is at least
@@ -51,12 +52,12 @@
* @return the handle
* @throws RemotingException if a handle could not be acquired
*/
- Handle<RequestHandlerSource> getHandle() throws RemotingException;
+ Handle<RequestHandlerSource> getHandle() throws IOException;
/**
* Close this request handler source immediately.
*/
- void close() throws RemotingException;
+ void close() throws IOException;
/**
* Add a handler that is called when the request handler source is closed.
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/EndpointWrapper.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -1,8 +1,8 @@
package org.jboss.cx.remoting.spi.wrapper;
import java.util.concurrent.ConcurrentMap;
+import java.io.IOException;
import org.jboss.cx.remoting.Endpoint;
-import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.RequestListener;
import org.jboss.cx.remoting.Client;
import org.jboss.cx.remoting.ClientSource;
@@ -42,28 +42,28 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public <I, O> Handle<RequestHandler> createRequestHandler(final RequestListener<I, O> requestListener) throws RemotingException {
+ public <I, O> Handle<RequestHandler> createRequestHandler(final RequestListener<I, O> requestListener) throws IOException {
return delegate.createRequestHandler(requestListener);
}
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public <I, O> Handle<RequestHandlerSource> createRequestHandlerSource(final RequestListener<I, O> requestListener) throws RemotingException {
+ public <I, O> Handle<RequestHandlerSource> createRequestHandlerSource(final RequestListener<I, O> requestListener) throws IOException {
return delegate.createRequestHandlerSource(requestListener);
}
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public <I, O> Client<I, O> createClient(final RequestHandler handler) throws RemotingException {
+ public <I, O> Client<I, O> createClient(final RequestHandler handler) throws IOException {
return delegate.createClient(handler);
}
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public <I, O> ClientSource<I, O> createClientSource(final RequestHandlerSource handlerSource) throws RemotingException {
+ public <I, O> ClientSource<I, O> createClientSource(final RequestHandlerSource handlerSource) throws IOException {
return delegate.createClientSource(handlerSource);
}
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/RequestContextWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/RequestContextWrapper.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/RequestContextWrapper.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -4,6 +4,7 @@
import org.jboss.cx.remoting.RequestCancelHandler;
import org.jboss.cx.remoting.RequestContext;
import org.jboss.cx.remoting.ClientContext;
+import java.io.IOException;
/**
* A simple delegating wrapper for request context instances.
@@ -39,21 +40,21 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public void sendReply(O reply) throws RemotingException, IllegalStateException {
+ public void sendReply(O reply) throws IOException, IllegalStateException {
delegate.sendReply(reply);
}
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public void sendFailure(String msg, Throwable cause) throws RemotingException, IllegalStateException {
+ public void sendFailure(String msg, Throwable cause) throws IOException, IllegalStateException {
delegate.sendFailure(msg, cause);
}
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public void sendCancelled() throws RemotingException, IllegalStateException {
+ public void sendCancelled() throws IOException, IllegalStateException {
delegate.sendCancelled();
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -45,7 +45,7 @@
this.handle = handle;
}
- protected void closeAction() throws RemotingException {
+ protected void closeAction() throws IOException {
handle.close();
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientSourceImpl.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -31,6 +31,7 @@
import org.jboss.cx.remoting.spi.remote.Handle;
import org.jboss.cx.remoting.spi.AbstractCloseable;
import org.jboss.xnio.IoUtils;
+import java.io.IOException;
/**
*
@@ -46,11 +47,11 @@
this.endpoint = endpoint;
}
- protected void closeAction() throws RemotingException {
+ protected void closeAction() throws IOException {
handle.close();
}
- public Client<I, O> createClient() throws RemotingException {
+ public Client<I, O> createClient() throws IOException {
if (! isOpen()) {
throw new RemotingException("Client source is not open");
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -7,9 +7,9 @@
import java.util.concurrent.TimeUnit;
import java.util.Set;
import java.io.Closeable;
+import java.io.IOException;
import org.jboss.cx.remoting.Endpoint;
import org.jboss.cx.remoting.RequestListener;
-import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.CloseHandler;
import org.jboss.cx.remoting.Client;
import org.jboss.cx.remoting.ClientSource;
@@ -121,23 +121,23 @@
return endpointMap;
}
- public <I, O> Handle<RequestHandler> createRequestHandler(final RequestListener<I, O> requestListener) throws RemotingException {
+ public <I, O> Handle<RequestHandler> createRequestHandler(final RequestListener<I, O> requestListener) throws IOException {
final LocalRequestHandler<I, O> localRequestHandler = new LocalRequestHandler<I, O>(executor, requestListener);
localRequestHandler.addCloseHandler(remover);
localRequestHandler.open();
return localRequestHandler.getHandle();
}
- public <I, O> Handle<RequestHandlerSource> createRequestHandlerSource(final RequestListener<I, O> requestListener) throws RemotingException {
+ public <I, O> Handle<RequestHandlerSource> createRequestHandlerSource(final RequestListener<I, O> requestListener) throws IOException {
final LocalRequestHandlerSource<I, O> localRequestHandlerSource = new LocalRequestHandlerSource<I, O>(executor, requestListener);
localRequestHandlerSource.addCloseHandler(remover);
localRequestHandlerSource.open();
return localRequestHandlerSource.getHandle();
}
- public <I, O> Client<I, O> createClient(final RequestHandler endpoint) throws RemotingException {
+ public <I, O> Client<I, O> createClient(final RequestHandler requestHandler) throws IOException {
boolean ok = false;
- final Handle<RequestHandler> handle = endpoint.getHandle();
+ final Handle<RequestHandler> handle = requestHandler.getHandle();
try {
final ClientImpl<I, O> client = new ClientImpl<I, O>(handle, executor);
client.addCloseHandler(new CloseHandler<Client<I, O>>() {
@@ -154,7 +154,7 @@
}
}
- public <I, O> ClientSource<I, O> createClientSource(final RequestHandlerSource requestHandlerSource) throws RemotingException {
+ public <I, O> ClientSource<I, O> createClientSource(final RequestHandlerSource requestHandlerSource) throws IOException {
boolean ok = false;
final Handle<RequestHandlerSource> handle = requestHandlerSource.getHandle();
try {
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/LocalRequestHandlerSource.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/LocalRequestHandlerSource.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/LocalRequestHandlerSource.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -31,6 +31,7 @@
import org.jboss.cx.remoting.CloseHandler;
import org.jboss.xnio.log.Logger;
import java.util.concurrent.Executor;
+import java.io.IOException;
/**
*
@@ -50,7 +51,7 @@
serviceContext = new ServiceContextImpl(executor);
}
- public Handle<RequestHandler> createRequestHandler() throws RemotingException {
+ public Handle<RequestHandler> createRequestHandler() throws IOException {
if (isOpen()) {
final LocalRequestHandler<I, O> localRequestHandler = new LocalRequestHandler<I, O>(executor, this, requestListener);
localRequestHandler.open();
Modified: remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java
===================================================================
--- remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/core/src/test/java/org/jboss/cx/remoting/core/EndpointTestCase.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -27,12 +27,12 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.io.IOException;
import org.jboss.cx.remoting.AbstractRequestListener;
import org.jboss.cx.remoting.RequestContext;
import org.jboss.cx.remoting.RemoteExecutionException;
import org.jboss.cx.remoting.CloseHandler;
import org.jboss.cx.remoting.Client;
-import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.test.support.LoggingHelper;
import org.jboss.cx.remoting.spi.remote.RequestHandler;
import org.jboss.cx.remoting.spi.remote.Handle;
@@ -84,10 +84,10 @@
assertEquals(request, requestObj);
try {
context.sendReply(replyObj);
- } catch (RemotingException e) {
+ } catch (IOException e) {
try {
context.sendFailure(e.getMessage(), e);
- } catch (RemotingException e1) {
+ } catch (IOException e1) {
fail("double fault");
}
}
@@ -143,10 +143,10 @@
assertEquals(request, requestObj);
try {
context.sendReply(replyObj);
- } catch (RemotingException e) {
+ } catch (IOException e) {
try {
context.sendFailure(e.getMessage(), e);
- } catch (RemotingException e1) {
+ } catch (IOException e1) {
fail("double fault");
}
}
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StreamingRot13RequestListener.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StreamingRot13RequestListener.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StreamingRot13RequestListener.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -4,7 +4,6 @@
import java.io.Reader;
import org.jboss.cx.remoting.AbstractRequestListener;
import org.jboss.cx.remoting.RemoteExecutionException;
-import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.RequestContext;
/**
@@ -40,7 +39,7 @@
request.close();
}
});
- } catch (RemotingException e) {
+ } catch (IOException e) {
throw new RemoteExecutionException("Failed to send reply", e);
}
}
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StringRot13RequestListener.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StringRot13RequestListener.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/StringRot13RequestListener.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -2,8 +2,8 @@
import org.jboss.cx.remoting.AbstractRequestListener;
import org.jboss.cx.remoting.RemoteExecutionException;
-import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.RequestContext;
+import java.io.IOException;
/**
*
@@ -17,7 +17,7 @@
b.append(rot13(request.charAt(i)));
}
readerRequestContext.sendReply(b.toString());
- } catch (RemotingException e) {
+ } catch (IOException e) {
throw new RemoteExecutionException("Failed to send reply", e);
}
}
Modified: remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
===================================================================
--- remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-07-29 19:54:18 UTC (rev 4438)
+++ remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-07-30 15:30:52 UTC (rev 4439)
@@ -32,7 +32,7 @@
}
}
- public static <I, O> Client<I, O> createLocalClient(Endpoint endpoint, RequestListener<I, O> requestListener) throws RemotingException {
+ public static <I, O> Client<I, O> createLocalClient(Endpoint endpoint, RequestListener<I, O> requestListener) throws IOException {
final Handle<RequestHandler> handle = endpoint.createRequestHandler(requestListener);
try {
return endpoint.createClient(handle.getResource());
@@ -41,7 +41,7 @@
}
}
- public static <I, O> ClientSource<I, O> createLocalClientSource(Endpoint endpoint, RequestListener<I, O> requestListener) throws RemotingException {
+ public static <I, O> ClientSource<I, O> createLocalClientSource(Endpoint endpoint, RequestListener<I, O> requestListener) throws IOException {
final Handle<RequestHandlerSource> handle = endpoint.createRequestHandlerSource(requestListener);
try {
return endpoint.createClientSource(handle.getResource());
16 years, 4 months
JBoss Remoting SVN: r4438 - remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-29 15:54:18 -0400 (Tue, 29 Jul 2008)
New Revision: 4438
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java
Log:
Fix compile error
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java 2008-07-29 19:34:26 UTC (rev 4437)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientSourceWrapper.java 2008-07-29 19:54:18 UTC (rev 4438)
@@ -4,6 +4,7 @@
import org.jboss.cx.remoting.Client;
import org.jboss.cx.remoting.ClientSource;
import org.jboss.cx.remoting.RemotingException;
+import java.io.IOException;
/**
* A simple delegating wrapper for client sources.
@@ -26,7 +27,7 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public void close() throws RemotingException {
+ public void close() throws IOException {
delegate.close();
}
@@ -44,7 +45,7 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public Client<I, O> createClient() throws RemotingException {
+ public Client<I, O> createClient() throws IOException {
return delegate.createClient();
}
}
16 years, 4 months
JBoss Remoting SVN: r4437 - in remoting3/trunk: api/src/main/java/org/jboss/cx/remoting and 7 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-29 15:34:26 -0400 (Tue, 29 Jul 2008)
New Revision: 4437
Removed:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/FutureReply.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCompletionHandler.java
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Client.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientSource.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Closeable.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemoteExecutionException.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCancelHandler.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteRequestContext.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientWrapper.java
remoting3/trunk/build.properties
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/LocalRequestHandler.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestContextImpl.java
remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java
remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java
remoting3/trunk/testing-support/src/main/resources/testing.policy
Log:
Change exception structure; use IoFuture as a basis for future replies rather than Future.
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Client.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Client.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Client.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -1,6 +1,8 @@
package org.jboss.cx.remoting;
import java.util.concurrent.ConcurrentMap;
+import java.io.IOException;
+import org.jboss.xnio.IoFuture;
/**
* A communications client. The client may be associated with state maintained by the local and/or remote side.
@@ -24,7 +26,7 @@
* @throws RemotingException if the request could not be sent
* @throws RemoteExecutionException if the remote handler threw an exception
*/
- O invoke(I request) throws RemotingException, RemoteExecutionException;
+ O invoke(I request) throws IOException;
/**
* Send a request asynchronously.
@@ -38,9 +40,9 @@
*
* @return a future representing the result of the request
*
- * @throws RemotingException if the request could not be sent
+ * @throws IOException if the request could not be sent
*/
- FutureReply<O> send(I request) throws RemotingException;
+ IoFuture<O> send(I request) throws IOException;
/**
* Send a request asynchronously, ignoring the reply.
@@ -51,9 +53,9 @@
* Returns immediately.
*
* @param request the request to send
- * @throws RemotingException if the request could not be sent
+ * @throws IOException if the request could not be sent
*/
- void sendOneWay(I request) throws RemotingException;
+ void sendOneWay(I request) throws IOException;
/**
* Get the attribute map. This map holds metadata about the current clinet.
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientSource.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientSource.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/ClientSource.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -1,5 +1,7 @@
package org.jboss.cx.remoting;
+import java.io.IOException;
+
/**
* A source for new Remoting contexts.
*
@@ -11,12 +13,12 @@
* Close the context source. New contexts may no longer be created after this
* method is called. Subsequent calls to this method have no additional effect.
*/
- void close() throws RemotingException;
+ void close() throws IOException;
/**
* Create a new communications context.
*
* @return the new context
*/
- Client<I, O> createClient() throws RemotingException;
+ Client<I, O> createClient() throws IOException;
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Closeable.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Closeable.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/Closeable.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -1,5 +1,7 @@
package org.jboss.cx.remoting;
+import java.io.IOException;
+
/**
* A Remoting resource that can be closed.
*
@@ -10,9 +12,9 @@
/**
* Close, waiting for any outstanding processing to finish.
*
- * @throws RemotingException if the close failed
+ * @throws IOException if the close failed
*/
- void close() throws RemotingException;
+ void close() throws IOException;
/**
* Add a handler that will be called upon close. The handler may be called before or after the close acutally
Deleted: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/FutureReply.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/FutureReply.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/FutureReply.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -1,121 +0,0 @@
-package org.jboss.cx.remoting;
-
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-
-/**
- * The result of an invocation that may or may not yet have completed.
- * <p/>
- * In addition to representing the invocation results, this interface allows the user to cancel the request, or schedule
- * an asynchronous callback for when the request completes.
- *
- * @param <T> the result type of the future operation
- */
-public interface FutureReply<T> extends Future<T> {
-
- /**
- * Attempts to cancel execution of this request. This attempt will fail if the request has already completed,
- * already been cancelled, or could not be cancelled for some other reason. The {@code mayInterruptIfRunning}
- * parameter determines whether the thread executing this task should be interrupted in an attempt to stop the
- * task. If {@code false}, the thread will not be interrupted. If {@code true}, then the remote service's
- * interruption policy will be used.
- *
- * @param mayInterruptIfRunning {@code true} if the thread executing this task should be interrupted; otherwise,
- * in-progress tasks are allowed to complete
- *
- * @return {@code false} if the task could not be cancelled, typically because it has already completed normally;
- * {@code true} otherwise
- */
- boolean cancel(boolean mayInterruptIfRunning);
-
- /**
- * Asynchronously send a request to cancel this request. Does not block the current method. Use the
- * {@link #addCompletionHandler(RequestCompletionHandler)} method to add a notifier to be called upon completion.
- *
- * @param mayInterruptIfRunning
- */
- FutureReply<T> sendCancel(boolean mayInterruptIfRunning);
-
- /**
- * Returns {@code true} if this task was cancelled before it completed normally.
- *
- * @return {@code true} if task was cancelled before it completed
- */
- boolean isCancelled();
-
- /**
- * Returns {@code true} if this request completed.
- * <p/>
- * Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method
- * will return {@code true}.
- *
- * @return {@code true} if this request completed
- */
- boolean isDone();
-
- /**
- * Waits if necessary for the request to complete, and then retrieves its reply.
- *
- * @return the reply
- *
- * @throws CancellationException if the computation was cancelled
- * @throws RemoteExecutionException if the computation threw an exception
- */
- T get() throws CancellationException, RemoteExecutionException;
-
- /**
- * Waits if necessary for the request to complete, and then retrieves its reply.
- *
- * @return the reply
- *
- * @throws CancellationException if the computation was cancelled
- * @throws RemoteExecutionException if the computation threw an exception
- * @throws InterruptedException if the current thread was interrupted while waiting
- */
- T getInterruptibly() throws InterruptedException, CancellationException, RemoteExecutionException;
-
- /**
- * Waits if necessary for at most the given time for the request to complete, and then retrieves the reply, if
- * available. If no reply was available, {@code null} is returned.
- *
- * @param timeout the maximum time to wait
- * @param unit the time unit of the timeout argument
- *
- * @return the reply, or {@code null} if the operation timed out
- *
- * @throws CancellationException if the computation was cancelled
- * @throws RemoteExecutionException if the computation threw an exception
- */
- T get(long timeout, TimeUnit unit) throws CancellationException, RemoteExecutionException;
-
- /**
- * Waits if necessary for at most the given time for the request to complete, and then retrieves the reply, if
- * available. If no reply was available, {@code null} is returned.
- *
- * @param timeout the maximum time to wait
- * @param unit the time unit of the timeout argument
- *
- * @return the reply, or {@code null} if the operation timed out
- *
- * @throws CancellationException if the computation was cancelled
- * @throws RemoteExecutionException if the computation threw an exception
- * @throws InterruptedException if the current thread was interrupted while waiting
- */
- T getInterruptibly(long timeout, TimeUnit unit) throws InterruptedException, CancellationException, RemoteExecutionException;
-
- /**
- * Add a notifier to be called when the request has completed. The notifier may be called from the current thread
- * or a different thread. If the request has already completed, the notifier will be called immediately. Calling
- * this method guarantees that the supplied handler will be called. The handler may be called at any time after
- * the request has completed, though implementations should make a reasonable effort to ensure that the handler is
- * called in a timely manner.
- * <p/>
- * This method returns {@code this} in order to facilitate method call chaining.
- *
- * @param handler the handler to add, or {@code null} to clear the handler
- *
- * @return this future reply
- */
- FutureReply<T> addCompletionHandler(RequestCompletionHandler<T> handler);
-}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemoteExecutionException.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemoteExecutionException.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RemoteExecutionException.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -1,11 +1,9 @@
package org.jboss.cx.remoting;
-import java.util.concurrent.ExecutionException;
-
/**
* Exception thrown when execution of a remote operation fails for some reason.
*/
-public class RemoteExecutionException extends ExecutionException {
+public class RemoteExecutionException extends RemotingException {
private static final long serialVersionUID = 3580395686019440048L;
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCancelHandler.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCancelHandler.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCancelHandler.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -11,7 +11,6 @@
* Receive notification that the request was cancelled.
*
* @param requestContext the request context
- * @param mayInterrupt the value of the cancellation {@code mayInterrupt} flag
*/
- void notifyCancel(RequestContext<O> requestContext, boolean mayInterrupt);
+ void notifyCancel(RequestContext<O> requestContext);
}
Deleted: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCompletionHandler.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCompletionHandler.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/RequestCompletionHandler.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -1,16 +0,0 @@
-package org.jboss.cx.remoting;
-
-/**
- * A handler for receiving notification of request completion on the client side.
- *
- * @param <T> the reply type
- */
-public interface RequestCompletionHandler<T> {
-
- /**
- * Receive notification that the request was completed, was cancelled, or has failed.
- *
- * @param futureReply the future result
- */
- void notifyComplete(FutureReply<T> futureReply);
-}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -33,6 +33,8 @@
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
/**
* A basic implementation of a closeable resource. Use as a convenient base class for your closeable resources.
@@ -53,7 +55,11 @@
static {
boolean b = false;
try {
- b = Boolean.parseBoolean(System.getProperty("jboss.remoting.leakdebugging", "false"));
+ b = Boolean.parseBoolean(AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ return System.getProperty("jboss.remoting.leakdebugging", "false");
+ }
+ }));
} catch (SecurityException se) {
b = false;
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/SpiUtils.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -27,8 +27,6 @@
import org.jboss.cx.remoting.RequestCancelHandler;
import org.jboss.cx.remoting.RequestContext;
import org.jboss.cx.remoting.CloseHandler;
-import org.jboss.cx.remoting.RequestCompletionHandler;
-import org.jboss.cx.remoting.FutureReply;
import org.jboss.xnio.log.Logger;
/**
@@ -85,14 +83,12 @@
/**
* Safely notify a request listener's cancel handler of cancellation.
*
- * @param <O> the reply
* @param handler the request cancel handler
* @param requestContext the request context
- * @param mayInterrupt {@code true} if the request listener threads may be interrupted
*/
- public static <O> void safeNotifyCancellation(final RequestCancelHandler<O> handler, final RequestContext<O> requestContext, boolean mayInterrupt) {
+ public static <O> void safeNotifyCancellation(final RequestCancelHandler<O> handler, final RequestContext<O> requestContext) {
try {
- handler.notifyCancel(requestContext, mayInterrupt);
+ handler.notifyCancel(requestContext);
} catch (Throwable t) {
log.error(t, "Request cancel handler threw an exception when calling notifyCancel()");
}
@@ -113,21 +109,6 @@
}
}
- /**
- * Safely handle a future request completion.
- *
- * @param <O> the reply type
- * @param handler
- * @param futureReply
- */
- public static <O> void safeHandleRequestCompletion(final RequestCompletionHandler<O> handler, final FutureReply<O> futureReply) {
- try {
- handler.notifyComplete(futureReply);
- } catch (Throwable t) {
- log.error(t, "Request completion handler failed unexpectedly");
- }
- }
-
public static RemoteRequestContext getBlankRemoteRequestContext() {
return BLANK_REMOTE_REQUEST_CONTEXT;
}
@@ -135,7 +116,7 @@
private static final RemoteRequestContext BLANK_REMOTE_REQUEST_CONTEXT = new BlankRemoteRequestContext();
private static final class BlankRemoteRequestContext implements RemoteRequestContext {
- public void cancel(final boolean mayInterrupt) {
+ public void cancel() {
}
}
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteRequestContext.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteRequestContext.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/remote/RemoteRequestContext.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -30,8 +30,6 @@
/**
* Signal that the request should be cancelled, if possible.
- *
- * @param mayInterrupt {@code true} if the task can be interrupted (advisory)
*/
- void cancel(final boolean mayInterrupt);
+ void cancel();
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientWrapper.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientWrapper.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/wrapper/ClientWrapper.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -1,11 +1,10 @@
package org.jboss.cx.remoting.spi.wrapper;
import java.util.concurrent.ConcurrentMap;
+import java.io.IOException;
import org.jboss.cx.remoting.CloseHandler;
import org.jboss.cx.remoting.Client;
-import org.jboss.cx.remoting.FutureReply;
-import org.jboss.cx.remoting.RemoteExecutionException;
-import org.jboss.cx.remoting.RemotingException;
+import org.jboss.xnio.IoFuture;
/**
* A simple delegating wrapper for clients.
@@ -28,7 +27,7 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public void close() throws RemotingException {
+ public void close() throws IOException {
delegate.close();
}
@@ -46,21 +45,21 @@
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public O invoke(final I request) throws RemotingException, RemoteExecutionException {
+ public O invoke(final I request) throws IOException {
return delegate.invoke(request);
}
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public FutureReply<O> send(final I request) throws RemotingException {
+ public IoFuture<O> send(final I request) throws IOException {
return delegate.send(request);
}
/**
* {@inheritDoc} This implementation calls the same method on the delegate object.
*/
- public void sendOneWay(final I request) throws RemotingException {
+ public void sendOneWay(final I request) throws IOException {
delegate.sendOneWay(request);
}
Modified: remoting3/trunk/build.properties
===================================================================
--- remoting3/trunk/build.properties 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/build.properties 2008-07-29 19:34:26 UTC (rev 4437)
@@ -173,7 +173,7 @@
lib.trove.local=${local.repository}/${lib.trove.path}
lib.trove.remote=${remote.repository}/${lib.trove.path}
-lib.xnio.version=1.1.0.Alpha2008072101
+lib.xnio.version=1.1.0.Alpha2008072901
lib.xnio-api.name=xnio-api-${lib.xnio.version}.jar
lib.xnio-api.license=lgpl
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/ClientImpl.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -24,15 +24,14 @@
import org.jboss.cx.remoting.Client;
import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.RemoteExecutionException;
-import org.jboss.cx.remoting.FutureReply;
-import org.jboss.cx.remoting.RequestCompletionHandler;
import org.jboss.cx.remoting.core.util.QueueExecutor;
import org.jboss.cx.remoting.spi.remote.RequestHandler;
import org.jboss.cx.remoting.spi.remote.ReplyHandler;
import org.jboss.cx.remoting.spi.remote.RemoteRequestContext;
import org.jboss.cx.remoting.spi.remote.Handle;
+import org.jboss.xnio.IoFuture;
import java.util.concurrent.Executor;
+import java.io.IOException;
/**
*
@@ -50,7 +49,7 @@
handle.close();
}
- public O invoke(final I request) throws RemotingException, RemoteExecutionException {
+ public O invoke(final I request) throws IOException {
if (! isOpen()) {
throw new RemotingException("Client is not open");
}
@@ -59,8 +58,8 @@
final ReplyHandler replyHandler = futureReply.getReplyHandler();
final RemoteRequestContext requestContext = handle.getResource().receiveRequest(request, replyHandler);
futureReply.setRemoteRequestContext(requestContext);
- futureReply.addCompletionHandler(new RequestCompletionHandler<O>() {
- public void notifyComplete(final FutureReply<O> reply) {
+ futureReply.addNotifier(new IoFuture.Notifier<O>() {
+ public void notify(final IoFuture<O> future) {
executor.shutdown();
}
});
@@ -68,7 +67,7 @@
return futureReply.get();
}
- public FutureReply<O> send(final I request) throws RemotingException {
+ public IoFuture<O> send(final I request) throws IOException {
if (! isOpen()) {
throw new RemotingException("Client is not open");
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -22,347 +22,57 @@
package org.jboss.cx.remoting.core;
-import org.jboss.cx.remoting.FutureReply;
-import org.jboss.cx.remoting.RemoteExecutionException;
-import org.jboss.cx.remoting.RequestCompletionHandler;
-import org.jboss.cx.remoting.util.CollectionUtil;
+import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.spi.remote.ReplyHandler;
import org.jboss.cx.remoting.spi.remote.RemoteRequestContext;
-import org.jboss.cx.remoting.spi.SpiUtils;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.TimeUnit;
+import org.jboss.xnio.AbstractIoFuture;
+import org.jboss.xnio.IoFuture;
import java.util.concurrent.Executor;
-import java.util.List;
/**
*
*/
-public final class FutureReplyImpl<O> implements FutureReply<O> {
+public final class FutureReplyImpl<O> extends AbstractIoFuture<O> {
private final Executor executor;
private final ReplyHandler replyHandler = new Handler();
- private final Object lock = new Object();
- // @protectedby lock
- private State state = State.NEW;
- // @protectedby lock
- private RemoteRequestContext remoteRequestContext;
- // @protectedby lock
- private O result;
- // @protectedby lock
- private Throwable cause;
- // @protectedby lock
- private String msg;
- // @protectedby lock
- private List<RequestCompletionHandler<O>> completionHandlers;
+ private volatile RemoteRequestContext remoteRequestContext;
public FutureReplyImpl(final Executor executor) {
this.executor = executor;
}
- private enum State {
- NEW,
- WAITING,
- DONE,
- CANCELLED,
- FAILED,
- }
-
void setRemoteRequestContext(final RemoteRequestContext remoteRequestContext) {
- synchronized (lock) {
- if (state != State.NEW) {
- throw new IllegalStateException("Wrong state");
- }
- state = State.WAITING;
- this.remoteRequestContext = remoteRequestContext;
- lock.notifyAll();
- }
+ this.remoteRequestContext = remoteRequestContext;
}
- public boolean cancel(final boolean mayInterruptIfRunning) {
- final RemoteRequestContext context;
- synchronized (lock) {
- while (state == State.NEW) {
- try {
- lock.wait();
- } catch (InterruptedException e) {
- return false;
- }
- }
- context = remoteRequestContext;
- }
- context.cancel(mayInterruptIfRunning);
- synchronized (lock) {
- while (state == State.WAITING) {
- try {
- lock.wait();
- } catch (InterruptedException e) {
- return false;
- }
- }
- return state == State.CANCELLED;
- }
- }
-
- public FutureReply<O> sendCancel(final boolean mayInterruptIfRunning) {
- final RemoteRequestContext context;
- synchronized (lock) {
- while (state == State.NEW) {
- try {
- lock.wait();
- } catch (InterruptedException e) {
- return this;
- }
- }
- context = remoteRequestContext;
- }
- context.cancel(mayInterruptIfRunning);
+ public IoFuture<O> cancel() {
+ // must not be called before setRemoteRequestContext
+ remoteRequestContext.cancel();
return this;
}
- public boolean isCancelled() {
- synchronized (lock) {
- return state == State.CANCELLED;
- }
+ protected Executor getNotifierExecutor() {
+ return executor;
}
- public boolean isDone() {
- synchronized (lock) {
- return state == State.DONE;
- }
- }
-
- public O get() throws CancellationException, RemoteExecutionException {
- boolean intr = false;
- try {
- synchronized (lock) {
- while (state == State.WAITING || state == State.NEW) {
- try {
- lock.wait();
- } catch (InterruptedException e) {
- intr = true;
- }
- }
- switch (state) {
- case CANCELLED:
- throw new CancellationException("Request was cancelled");
- case DONE:
- return result;
- case FAILED:
- throw new RemoteExecutionException(msg, cause);
- default:
- throw new IllegalStateException("Wrong state");
- }
- }
- } finally {
- if (intr) {
- Thread.currentThread().interrupt();
- }
- }
- }
-
- public O getInterruptibly() throws InterruptedException, CancellationException, RemoteExecutionException {
- synchronized (lock) {
- while (state == State.WAITING || state == State.NEW) {
- lock.wait();
- }
- switch (state) {
- case CANCELLED:
- throw new CancellationException("Request was cancelled");
- case DONE:
- return result;
- case FAILED:
- throw new RemoteExecutionException(msg, cause);
- default:
- throw new IllegalStateException("Wrong state");
- }
- }
- }
-
- public O get(final long timeout, final TimeUnit unit) throws CancellationException, RemoteExecutionException {
- if (unit == null) {
- throw new NullPointerException("unit is null");
- }
- if (timeout < 0L) {
- throw new IllegalArgumentException("timeout is negative");
- }
- boolean intr = false;
- try {
- synchronized (lock) {
- long now = System.currentTimeMillis();
- final long deadline = now + unit.toMillis(timeout);
- if (deadline < 0L) {
- return get();
- }
- while (state == State.WAITING || state == State.NEW) {
- try {
- if (now >= deadline) {
- return null;
- }
- lock.wait(deadline - now);
- } catch (InterruptedException e) {
- intr = true;
- }
- now = System.currentTimeMillis();
- }
- switch (state) {
- case CANCELLED:
- throw new CancellationException("Request was cancelled");
- case DONE:
- return result;
- case FAILED:
- throw new RemoteExecutionException(msg, cause);
- default:
- throw new IllegalStateException("Wrong state");
- }
- }
- } finally {
- if (intr) {
- Thread.currentThread().interrupt();
- }
- }
- }
-
- public O getInterruptibly(final long timeout, final TimeUnit unit) throws InterruptedException, CancellationException, RemoteExecutionException {
- if (unit == null) {
- throw new NullPointerException("unit is null");
- }
- if (timeout < 0L) {
- throw new IllegalArgumentException("timeout is negative");
- }
- synchronized (lock) {
- while (state == State.WAITING || state == State.NEW) {
- unit.timedWait(lock, timeout);
- }
- switch (state) {
- case CANCELLED:
- throw new CancellationException("Request was cancelled");
- case DONE:
- return result;
- case FAILED:
- throw new RemoteExecutionException(msg, cause);
- case WAITING:
- case NEW:
- return null;
- default:
- throw new IllegalStateException("Wrong state");
- }
- }
- }
-
- public FutureReply<O> addCompletionHandler(final RequestCompletionHandler<O> handler) {
- synchronized (lock) {
- switch (state) {
- case NEW:
- case WAITING:
- if (completionHandlers == null) {
- completionHandlers = CollectionUtil.arrayList();
- }
- completionHandlers.add(handler);
- break;
- default:
- SpiUtils.safeHandleRequestCompletion(handler, this);
- break;
- }
- }
- return this;
- }
-
ReplyHandler getReplyHandler() {
return replyHandler;
}
- private void runCompletionHandlers() {
- synchronized (lock) {
- final List<RequestCompletionHandler<O>> handlers = completionHandlers;
- if (handlers != null) {
- completionHandlers = null;
- executor.execute(new Runnable() {
- public void run() {
- for (RequestCompletionHandler<O> handler : handlers) {
- SpiUtils.safeHandleRequestCompletion(handler, FutureReplyImpl.this);
- }
- }
- });
- }
- }
- }
-
private final class Handler implements ReplyHandler {
@SuppressWarnings({ "unchecked" })
public void handleReply(final Object reply) {
- synchronized (lock) {
- while (state == State.NEW) {
- boolean intr = false;
- try {
- try {
- lock.wait();
- } catch (InterruptedException e) {
- intr = true;
- }
- } finally {
- if (intr) {
- Thread.currentThread().interrupt();
- }
- }
- }
- if (state == State.WAITING) {
- state = State.DONE;
- result = (O) reply;
- runCompletionHandlers();
- lock.notifyAll();
- }
- }
+ setResult((O) reply);
}
public void handleException(final String exMsg, final Throwable exCause) {
- synchronized (lock) {
- while (state == State.NEW) {
- boolean intr = false;
- try {
- try {
- lock.wait();
- } catch (InterruptedException e) {
- intr = true;
- }
- } finally {
- if (intr) {
- Thread.currentThread().interrupt();
- }
- }
- }
- if (state == State.WAITING) {
- state = State.FAILED;
- msg = exMsg;
- cause = exCause;
- runCompletionHandlers();
- lock.notifyAll();
- }
- }
+ setException(new RemotingException(exMsg, exCause));
}
public void handleCancellation() {
- synchronized (lock) {
- while (state == State.NEW) {
- boolean intr = false;
- try {
- try {
- lock.wait();
- } catch (InterruptedException e) {
- intr = true;
- }
- } finally {
- if (intr) {
- Thread.currentThread().interrupt();
- }
- }
- }
- if (state == State.WAITING) {
- state = State.CANCELLED;
- runCompletionHandlers();
- lock.notifyAll();
- }
- }
+ finishCancel();
}
}
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/LocalRequestHandler.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/LocalRequestHandler.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/LocalRequestHandler.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -89,8 +89,8 @@
}
});
return new RemoteRequestContext() {
- public void cancel(final boolean mayInterrupt) {
- context.cancel(mayInterrupt);
+ public void cancel() {
+ context.cancel();
}
};
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestContextImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestContextImpl.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/RequestContextImpl.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -101,7 +101,7 @@
public void addCancelHandler(final RequestCancelHandler<O> handler) {
synchronized (cancelLock) {
if (cancelled.get()) {
- SpiUtils.safeNotifyCancellation(handler, this, false);
+ SpiUtils.safeNotifyCancellation(handler, this);
} else {
if (cancelHandlers == null) {
cancelHandlers = new HashSet<RequestCancelHandler<O>>();
@@ -115,23 +115,21 @@
executor.execute(command);
}
- protected void cancel(final boolean mayInterrupt) {
+ protected void cancel() {
if (! cancelled.getAndSet(true)) {
synchronized (cancelLock) {
if (cancelHandlers != null) {
for (final RequestCancelHandler<O> handler : cancelHandlers) {
executor.execute(new Runnable() {
public void run() {
- SpiUtils.safeNotifyCancellation(handler, RequestContextImpl.this, mayInterrupt);
+ SpiUtils.safeNotifyCancellation(handler, RequestContextImpl.this);
}
});
}
cancelHandlers = null;
}
}
- if (mayInterrupt) {
- executor.interruptAll();
- }
+ executor.interruptAll();
}
}
}
Modified: remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java
===================================================================
--- remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/protocol/basic/src/main/java/org/jboss/cx/remoting/protocol/basic/BasicHandler.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -727,12 +727,11 @@
this.channel = channel;
}
- public void cancel(final boolean mayInterrupt) {
+ public void cancel() {
try {
final ByteBuffer buffer = allocator.allocate();
buffer.put((byte) MessageType.CANCEL_REQUEST);
buffer.putInt(id);
- buffer.put((byte) (mayInterrupt ? 1 : 0));
buffer.flip();
registerWriter(channel, new SimpleWriteHandler(allocator, buffer));
} catch (InterruptedException e) {
Modified: remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java
===================================================================
--- remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/protocol/basic/src/test/java/org/jboss/cx/remoting/protocol/basic/ConnectionTestCase.java 2008-07-29 19:34:26 UTC (rev 4437)
@@ -38,7 +38,6 @@
import org.jboss.cx.remoting.ClientSource;
import org.jboss.cx.remoting.Client;
import org.jboss.cx.remoting.RemotingException;
-import org.jboss.cx.remoting.FutureReply;
import org.jboss.cx.remoting.AbstractRequestListener;
import org.jboss.cx.remoting.spi.remote.RequestHandlerSource;
import org.jboss.cx.remoting.spi.remote.Handle;
@@ -51,6 +50,7 @@
import org.jboss.xnio.ChannelSource;
import org.jboss.xnio.CloseableTcpConnector;
import org.jboss.xnio.CloseableExecutor;
+import org.jboss.xnio.nio.NioXnio;
import org.jboss.xnio.channels.AllocatedMessageChannel;
import org.jboss.xnio.channels.Channels;
import org.jboss.xnio.channels.StreamChannel;
@@ -77,7 +77,7 @@
public void free(final ByteBuffer buffer) {
}
};
- final Xnio xnio = Xnio.createNio();
+ final Xnio xnio = NioXnio.create();
try {
final EndpointImpl endpoint = new EndpointImpl();
endpoint.setExecutor(closeableExecutor);
@@ -113,8 +113,9 @@
try {
final Client<Object,Object> client = clientSource.createClient();
try {
- final FutureReply<Object> future = client.send(REQUEST);
- assertEquals(REPLY, future.get(500L, TimeUnit.MILLISECONDS));
+ final IoFuture<Object> future = client.send(REQUEST);
+ assertEquals(IoFuture.Status.DONE, future.await(TimeUnit.MILLISECONDS, 500L));
+ assertEquals(REPLY, future.get());
client.close();
clientSource.close();
handleThirteen.close();
Modified: remoting3/trunk/testing-support/src/main/resources/testing.policy
===================================================================
--- remoting3/trunk/testing-support/src/main/resources/testing.policy 2008-07-29 15:17:07 UTC (rev 4436)
+++ remoting3/trunk/testing-support/src/main/resources/testing.policy 2008-07-29 19:34:26 UTC (rev 4437)
@@ -15,20 +15,30 @@
{
permission java.lang.RuntimePermission "modifyThread"; // for executor control
permission java.net.SocketPermission "*:*", "accept, connect, resolve";
+ permission java.util.PropertyPermission "xnio.provider", "read"; // todo - fixed in XNIO trunk...
};
-grant codeBase "file:${build.home}/protocol/basic/target/main/classes/-"
+// Permissions for Remoting itself
+
+grant codeBase "file:${build.home}/api/target/main/classes/-"
{
- permission java.net.SocketPermission "*:*", "accept, connect, resolve";
+ permission java.util.PropertyPermission "jboss.remoting.*", "read";
};
-// TODO: this is for the marshallers, which ought to be in their own module/module set
-
grant codeBase "file:${build.home}/core/target/main/classes/-"
{
+ // TODO: this is for the marshallers, which ought to be in their own module/module set
permission java.io.SerializablePermission "enableSubstitution";
+ permission java.util.PropertyPermission "jboss.remoting.*", "read";
};
+grant codeBase "file:${build.home}/protocol/basic/target/main/classes/-"
+{
+ permission java.net.SocketPermission "*:*", "accept, connect, resolve"; // todo - need a better solution
+ permission java.util.PropertyPermission "jboss.remoting.*", "read";
+};
+
+
// Support classes
grant codeBase "file:${build.home}/testing-support/target/main/classes/-"
16 years, 4 months
JBoss Remoting SVN: r4435 - remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-28 18:11:14 -0400 (Mon, 28 Jul 2008)
New Revision: 4435
Modified:
remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingHelper.java
Log:
Improve exception printout
Modified: remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingHelper.java
===================================================================
--- remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingHelper.java 2008-07-28 22:04:33 UTC (rev 4434)
+++ remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/LoggingHelper.java 2008-07-28 22:11:14 UTC (rev 4435)
@@ -61,9 +61,7 @@
Throwable t = record.getThrown();
while (t != null) {
builder.append("\n Caused by: ");
- builder.append(t.getClass().getName());
- builder.append(": ");
- builder.append(t.getMessage());
+ builder.append(t.toString());
for (StackTraceElement e : t.getStackTrace()) {
builder.append("\n at ");
builder.append(e.getClassName()).append('.').append(e.getMethodName());
16 years, 4 months
JBoss Remoting SVN: r4434 - remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-28 18:04:33 -0400 (Mon, 28 Jul 2008)
New Revision: 4434
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java
Log:
Add leak tracking
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java 2008-07-28 21:11:10 UTC (rev 4433)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/spi/AbstractCloseable.java 2008-07-28 22:04:33 UTC (rev 4434)
@@ -31,6 +31,7 @@
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Executor;
+import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
/**
@@ -46,6 +47,19 @@
private final AtomicBoolean closed = new AtomicBoolean();
private Set<CloseHandler<? super T>> closeHandlers;
+ private static final boolean LEAK_DEBUGGING;
+ private final StackTraceElement[] backtrace;
+
+ static {
+ boolean b = false;
+ try {
+ b = Boolean.parseBoolean(System.getProperty("jboss.remoting.leakdebugging", "false"));
+ } catch (SecurityException se) {
+ b = false;
+ }
+ LEAK_DEBUGGING = b;
+ }
+
/**
* Basic constructor.
*
@@ -56,6 +70,7 @@
throw new NullPointerException("executor is null");
}
this.executor = executor;
+ backtrace = LEAK_DEBUGGING ? new Throwable().getStackTrace() : null;
}
/**
@@ -84,12 +99,16 @@
synchronized (closeLock) {
if (closeHandlers != null) {
for (final CloseHandler<? super T> handler : closeHandlers) {
- executor.execute(new Runnable() {
- @SuppressWarnings({ "unchecked" })
- public void run() {
- SpiUtils.safeHandleClose(handler, (T) AbstractCloseable.this);
- }
- });
+ try {
+ executor.execute(new Runnable() {
+ @SuppressWarnings({ "unchecked" })
+ public void run() {
+ SpiUtils.safeHandleClose(handler, (T) AbstractCloseable.this);
+ }
+ });
+ } catch (RejectedExecutionException ree) {
+ log.warn("Unable to execute close handler (execution rejected) for %s (%s)", this, ree.getMessage());
+ }
}
closeHandlers = null;
}
@@ -127,9 +146,26 @@
super.finalize();
} finally {
if (isOpen()) {
- log.warn("Leaked a %s instance!", getClass().getName());
+ if (LEAK_DEBUGGING) {
+ final Throwable t = new LeakThrowable();
+ t.setStackTrace(backtrace);
+ log.warn(t, "Leaked a %s instance: %s", getClass().getName(), this);
+ } else {
+ log.warn("Leaked a %s instance: %s", getClass().getName(), this);
+ }
IoUtils.safeClose(this);
}
}
}
+
+ @SuppressWarnings({ "serial" })
+ private static final class LeakThrowable extends Throwable {
+
+ public LeakThrowable() {
+ }
+
+ public String toString() {
+ return "a leaked reference";
+ }
+ }
}
16 years, 4 months