JBoss Remoting SVN: r5226 - in remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning: lease and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-14 23:24:45 -0400 (Thu, 14 May 2009)
New Revision: 5226
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestClient.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestServer.java
Log:
JBREM-1133, JBREM-1134: New unit tests for versioning test suite.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestCase.java 2009-05-15 03:24:45 UTC (rev 5226)
@@ -0,0 +1,133 @@
+package org.jboss.test.remoting.versioning.lease;
+
+import org.apache.log4j.Level;
+import org.jboss.test.remoting.transport.InvokerTestDriver;
+
+/**
+ * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
+ */
+public class LeaseVersionTestCase extends InvokerTestDriver
+{
+ public void declareTestClasses()
+ {
+ addTestClasses("org.jboss.test.remoting.versioning.lease.LeaseVersionTestClient",
+ 1,
+ "org.jboss.test.remoting.versioning.lease.LeaseVersionTestServer");
+ }
+
+ /**
+ * Returns the classpath to be added to the classpath used to start the client tests.
+ * Default return is null, which means no extra classpath will be added.
+ *
+ * @return
+ */
+ protected String getExtendedServerClasspath()
+ {
+ return System.getProperty("server.path");
+ }
+
+ /**
+ * Returns the classpath to be added to the classpath used to start the client tests.
+ * Default return is null, which means no extra classpath will be added.
+ *
+ * @return
+ */
+ protected String getExtendedClientClasspath()
+ {
+ return System.getProperty("client.path");
+ }
+
+ protected String getClientJVMArguments()
+ {
+ String prop = System.getProperty("client.pre_2_0_compatible");
+ String args = "";
+ if (prop != null && !"".equals(prop))
+ {
+ args = "-Djboss.remoting.pre_2_0_compatible=" + prop;
+ }
+ else
+ {
+ prop = System.getProperty("client.version");
+ if (prop != null && !"".equals(prop))
+ args = "-Djboss.remoting.version=" + prop;
+ }
+ prop = System.getProperty("client.check_connection");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -Dremoting.metadata=socket.check_connection=" + prop;
+ }
+ System.out.println("client arg: " + args);
+ return args;
+ }
+
+
+ protected String getServerJVMArguments()
+ {
+ String prop = System.getProperty("server.pre_2_0_compatible");
+ String args = "";
+ if (prop != null && !"".equals(prop))
+ {
+ args = "-Djboss.remoting.pre_2_0_compatible=" + prop;
+ }
+ else
+ {
+ prop = System.getProperty("server.version");
+ if (prop != null && !"".equals(prop))
+ args = "-Djboss.remoting.version=" + prop;
+ }
+ prop = System.getProperty("server.check_connection");
+ if (prop != null && !"".equals(prop))
+ {
+ args += " -Dremoting.metadata=socket.check_connection=" + prop;
+ }
+ System.out.println("server arg: " + args);
+ return args;
+ }
+
+
+ protected Level getTestHarnessLogLevel()
+ {
+ return Level.INFO;
+ }
+
+ protected Level getTestLogLevel()
+ {
+ return Level.INFO;
+ }
+
+ /**
+ * How long to wait for test results to be returned from the client(s). If goes longer than the
+ * specified limit, will throw an exception and kill the running test cases. Default value is
+ * RESULTS_TIMEOUT.
+ *
+ * @return
+ */
+ protected long getResultsTimeout()
+ {
+ return 60000;
+ }
+
+ /**
+ * How long for the server test case to wait for tear down message. If exceeds timeout,
+ * will throw exception. The default value is TEARDOWN_TIMEOUT.
+ *
+ * @return
+ */
+ protected long getTearDownTimeout()
+ {
+ return 60000;
+ }
+
+ /**
+ * How long to allow each of the test cases to run their tests. If exceeds this timeout
+ * will throw exception and kill tests. The default value is RUN_TEST_TIMEOUT.
+ *
+ * @return
+ */
+ protected long getRunTestTimeout()
+ {
+ return 60000;
+ }
+
+
+}
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestClient.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestClient.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestClient.java 2009-05-15 03:24:45 UTC (rev 5226)
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.versioning.lease;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+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.Client;
+import org.jboss.remoting.ClientDisconnectedException;
+import org.jboss.remoting.InvokerLocator;
+
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 08, 2009
+ * </p>
+ */
+public class LeaseVersionTestClient extends TestCase
+{
+ private static Logger log = Logger.getLogger(LeaseVersionTestClient.class);
+
+ protected static long LEASE_PERIOD = 2000;
+ protected static String LEASE_PERIOD_STRING = "2000";
+
+ private static boolean firstTime = true;
+
+
+ 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 testLease() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(createLocatorURI());
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Test lease behavior.
+ client.disconnect();
+ client.connect();
+ Map info = (Map) client.invoke(LeaseVersionTestServer.GET_LISTENER_INFO);
+ log.info("listener info: " + info);
+ assertEquals(1, ((Integer)info.get(LeaseVersionTestServer.LISTENER_COUNT)).intValue());
+ assertTrue(info.get(LeaseVersionTestServer.THROWABLE) instanceof ClientDisconnectedException);
+ client.disconnect();
+
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+
+
+ protected String createLocatorURI() throws UnknownHostException
+ {
+ String locatorURI = getTransport() + "://" + InetAddress.getLocalHost().getHostAddress() + ":" + LeaseVersionTestServer.PORT;
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "/?" + metadata;
+ }
+ return locatorURI;
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestServer.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestServer.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/versioning/lease/LeaseVersionTestServer.java 2009-05-15 03:24:45 UTC (rev 5226)
@@ -0,0 +1,190 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.versioning.lease;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.jrunit.extensions.ServerTestCase;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+
+
+/**
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 08, 2009
+ * </p>
+ */
+public class LeaseVersionTestServer extends ServerTestCase
+{
+ public static final String REMOTING_METADATA = "remoting.metadata";
+ public static final String JVM_MAX_HEAP_SIZE = "jvm.mx";
+ public static final String GET_LISTENER_INFO = "getListenerCount";
+ public static final String LISTENER_COUNT = "listenerCount";
+ public static final String THROWABLE = "throwable";
+ public static final String PORT = "9091";
+
+ private static Logger log = Logger.getLogger(LeaseVersionTestServer.class);
+
+ protected static long LEASE_PERIOD = 2000;
+ protected static String LEASE_PERIOD_STRING = "2000";
+
+ protected Connector connector;
+ protected TestConnectionListener listener;
+
+
+ public static void main(String[] args)
+ {
+ try
+ {
+ LeaseVersionTestServer p = new LeaseVersionTestServer();
+ p.setUp();
+ Thread.sleep(3000000);
+ p.tearDown();
+ }
+ catch (Exception e)
+ {
+ log.error("Error", e);
+ }
+ }
+
+
+ public void setUp() throws Exception
+ {
+ 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);
+ setupServer();
+ }
+
+
+ public void tearDown()
+ {
+ if(connector != null)
+ {
+ connector.stop();
+ connector.destroy();
+ }
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ String locatorURI = createLocatorURI();
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "/?" + metadata;
+ }
+ InvokerLocator serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put("leasePeriod", LEASE_PERIOD_STRING);
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ ServerInvocationHandler invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ listener = new TestConnectionListener();
+ connector.addConnectionListener(listener);
+ }
+
+
+ protected String createLocatorURI() throws UnknownHostException
+ {
+ String locatorURI = getTransport() + "://" + InetAddress.getLocalHost().getHostAddress() + ":" + PORT;
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "/?" + metadata;
+ }
+ return locatorURI;
+ }
+
+
+ class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ Object o = invocation.getParameter();
+ if (GET_LISTENER_INFO.equals(o))
+ {
+ HashMap map = new HashMap();
+ map.put(LISTENER_COUNT, new Integer(listener.counter));
+ map.put(THROWABLE, listener.throwable);
+ listener.counter = 0;
+ listener.throwable = null;
+ return map;
+ }
+ return o;
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class TestConnectionListener implements ConnectionListener
+ {
+ public int counter;
+ public Throwable throwable;
+
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ counter++;
+ this.throwable = throwable;
+ log.info("called: throwable = " + throwable);
+ }
+ }
+}
\ No newline at end of file
14 years, 11 months
JBoss Remoting SVN: r5225 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/identity.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-14 23:21:00 -0400 (Thu, 14 May 2009)
New Revision: 5225
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/identity/LeaseIdentityTestCase.java
Log:
JBREM-1133: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/identity/LeaseIdentityTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/identity/LeaseIdentityTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/identity/LeaseIdentityTestCase.java 2009-05-15 03:21:00 UTC (rev 5225)
@@ -0,0 +1,302 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.connection.identity;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.LeasePinger;
+import org.jboss.remoting.MicroRemoteClientInvoker;
+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.ClientInvoker;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.util.id.GUID;
+
+
+/**
+ * Unit test for JBREM-1133.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright May 08, 2009
+ * </p>
+ */
+public class LeaseIdentityTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(LeaseIdentityTestCase.class);
+
+ protected static long LEASE_PERIOD = 2000;
+ protected static String LEASE_PERIOD_STRING = "2000";
+
+ private static boolean firstTime = true;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+ protected TestConnectionListener listener;
+
+
+ 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 testDefault() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(false, null);
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Test lease behavior.
+ MicroRemoteClientInvoker clientInvoker = (MicroRemoteClientInvoker) client.getInvoker();
+ clientInvoker.terminateLease(client.getSessionId(), 0);
+ TestLeasePinger leasePinger = new TestLeasePinger(clientInvoker, clientInvoker.getSessionId(), LEASE_PERIOD);
+ leasePinger.setLeasePingerId(new GUID().toString());
+ leasePinger.addClient(client.getSessionId(), client.getConfiguration(), LEASE_PERIOD);
+ leasePinger.startPing();
+ Thread.sleep(LEASE_PERIOD * 4);
+ assertFalse(listener.called);
+
+ leasePinger.stopPing();
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testClientConnectionIdentityFalse() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, "false");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Test lease behavior.
+ MicroRemoteClientInvoker clientInvoker = (MicroRemoteClientInvoker) client.getInvoker();
+ clientInvoker.terminateLease(client.getSessionId(), 0);
+ TestLeasePinger leasePinger = new TestLeasePinger(clientInvoker, clientInvoker.getSessionId(), LEASE_PERIOD);
+ leasePinger.setLeasePingerId(new GUID().toString());
+ leasePinger.addClient(client.getSessionId(), client.getConfiguration(), LEASE_PERIOD);
+ leasePinger.startPing();
+ Thread.sleep(LEASE_PERIOD * 4);
+ assertFalse(listener.called);
+
+ leasePinger.stopPing();
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testClientConnectionIdentityTrue() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, "true");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Test lease behavior.
+ MicroRemoteClientInvoker clientInvoker = (MicroRemoteClientInvoker) client.getInvoker();
+ clientInvoker.terminateLease(client.getSessionId(), 0);
+ TestLeasePinger leasePinger = new TestLeasePinger(clientInvoker, clientInvoker.getSessionId(), LEASE_PERIOD);
+ leasePinger.setLeasePingerId(new GUID().toString());
+ leasePinger.addClient(client.getSessionId(), client.getConfiguration(), LEASE_PERIOD);
+ leasePinger.startPing();
+ Thread.sleep(LEASE_PERIOD * 4);
+ assertTrue(listener.called);
+ assertNull(listener.throwable);
+
+ leasePinger.stopPing();
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "socket";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(boolean setUseClientIdentity, String useClientIdentity) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "/?" + metadata;
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ config.put("leasePeriod", LEASE_PERIOD_STRING);
+ if (setUseClientIdentity)
+ {
+ config.put(Remoting.USE_CLIENT_CONNECTION_IDENTITY, useClientIdentity);
+ }
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ listener = new TestConnectionListener();
+ connector.addConnectionListener(listener);
+ }
+
+
+ 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) {}
+ }
+
+
+ static class TestConnectionListener implements ConnectionListener
+ {
+ public boolean called;
+ public Throwable throwable;
+
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ called = true;
+ this.throwable = throwable;
+ log.info("called: throwable = " + throwable);
+ }
+ }
+
+
+ static class TestLeasePinger extends LeasePinger
+ {
+ public TestLeasePinger(ClientInvoker invoker, String invokerSessionID, long defaultLeasePeriod)
+ {
+ super(invoker, invokerSessionID, defaultLeasePeriod);
+ }
+
+ public void setLeasePingerId(String leasePingerId)
+ {
+ super.setLeasePingerId(leasePingerId);
+ }
+ }
+}
\ No newline at end of file
14 years, 11 months
JBoss Remoting SVN: r5224 - in remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection: identity and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-14 23:20:33 -0400 (Thu, 14 May 2009)
New Revision: 5224
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/identity/
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/identity/ConnectionIdentityTestCase.java
Log:
JBREM-1132: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/identity/ConnectionIdentityTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/identity/ConnectionIdentityTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/connection/identity/ConnectionIdentityTestCase.java 2009-05-15 03:20:33 UTC (rev 5224)
@@ -0,0 +1,508 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.remoting.connection.identity;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.logging.XLevel;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.ConnectionListener;
+import org.jboss.remoting.ConnectionValidator;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.InvokerRegistry;
+import org.jboss.remoting.LeasePinger;
+import org.jboss.remoting.MicroRemoteClientInvoker;
+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.ClientFactory;
+import org.jboss.remoting.transport.ClientInvoker;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.ServerFactory;
+import org.jboss.remoting.transport.socket.SocketClientInvoker;
+import org.jboss.remoting.transport.socket.SocketServerInvoker;
+
+
+/**
+/**
+ * Unit test for JBREM-1132.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright May 08, 2009
+ * </p>
+ */
+public class ConnectionIdentityTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ConnectionIdentityTestCase.class);
+
+ private static boolean firstTime = true;
+
+ protected static final int LEASE_PERIOD = 2000;
+ protected static final int VALIDATOR_PING_TIMEOUT = 1000;
+ protected static final int VALIDATOR_PING_PERIOD = 2000;
+ protected static final int PING_PERIODS_TO_WAIT = 2;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+ protected TestConnectionListener serverConnectionListener;
+
+
+ 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);
+ }
+ InvokerRegistry.registerInvokerFactories(getTransport(), TestClientFactory.class, TestServerFactory.class);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testIdentityTrueOneClientRestarts() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, "true");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, Integer.toString(VALIDATOR_PING_PERIOD));
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, Integer.toString(VALIDATOR_PING_TIMEOUT));
+ clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ TestConnectionListener clientConnectionListener = new TestConnectionListener("clientConnectionListener");
+ client.connect(clientConnectionListener, null);
+ Field field = MicroRemoteClientInvoker.class.getDeclaredField("leasePinger");
+ field.setAccessible(true);
+ LeasePinger leasePinger1 = (LeasePinger) field.get(client.getInvoker());
+ log.info("client is connected");
+
+ // Test connection.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Test client side connection failure notifications.
+ int wait = (PING_PERIODS_TO_WAIT + 1) * VALIDATOR_PING_PERIOD + VALIDATOR_PING_TIMEOUT + 2000;
+ log.info(getName() + " going to sleep for " + wait + " ms");
+ Thread.sleep(wait);
+ log.info("checking connection failure notifications");
+ assertEquals(1, clientConnectionListener.calledCounter);
+ assertTrue(clientConnectionListener.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener.throwable.getMessage());
+
+ // Test server side connection failure notifications.
+ wait = 2 * LEASE_PERIOD;
+ log.info(getName() + " going to sleep for " + wait + " ms");
+ Thread.sleep(wait);
+ assertEquals(1, serverConnectionListener.calledCounter);
+ assertNull(serverConnectionListener.throwable);
+
+ // Verify new LeasePinger is created if Client reconnects.
+ client.connect(clientConnectionListener, null);
+ assertNotSame(leasePinger1, field.get(client.getInvoker()));
+
+ client.removeConnectionListener(clientConnectionListener);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testIdentityTrueTwoClientsOneConnectionValidator() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, "true");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, Integer.toString(VALIDATOR_PING_PERIOD));
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, Integer.toString(VALIDATOR_PING_TIMEOUT));
+ clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
+ addExtraClientConfig(clientConfig);
+ Client client1 = new Client(clientLocator, clientConfig);
+ TestConnectionListener clientConnectionListener1 = new TestConnectionListener("clientConnectionListener1");
+ client1.connect(clientConnectionListener1, null);
+ Client client2 = new Client(clientLocator, clientConfig);
+ TestConnectionListener clientConnectionListener2 = new TestConnectionListener("clientConnectionListener2");
+ client2.connect(clientConnectionListener2, null);
+ log.info("clients are connected");
+
+ // Test connection.
+ assertEquals("abc", client1.invoke("abc"));
+ assertEquals("abc", client2.invoke("abc"));
+ log.info("connections are good");
+
+ // Verify Clients share ConnectionValidator.
+ Field field = Client.class.getDeclaredField("connectionValidator");
+ field.setAccessible(true);
+ ConnectionValidator connectionValidator1 = (ConnectionValidator) field.get(client1);
+ ConnectionValidator connectionValidator2 = (ConnectionValidator) field.get(client2);
+ assertSame(connectionValidator1, connectionValidator2);
+
+ // Test client side connection failure notifications.
+ int wait = (PING_PERIODS_TO_WAIT + 1) * VALIDATOR_PING_PERIOD + VALIDATOR_PING_TIMEOUT + 2000;
+ log.info(getName() + " going to sleep for " + wait + " ms");
+ Thread.sleep(wait);
+ log.info("checking connection failure notifications");
+ assertEquals(1, clientConnectionListener1.calledCounter);
+ assertTrue(clientConnectionListener1.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener1.throwable.getMessage());
+ assertEquals(1, clientConnectionListener2.calledCounter);
+ assertTrue(clientConnectionListener2.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener2.throwable.getMessage());
+
+ client1.removeConnectionListener(clientConnectionListener1);
+ client1.disconnect();
+ client2.removeConnectionListener(clientConnectionListener2);
+ client2.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testIdentityTrueTwoClientsTwoConnectionValidators() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, "true");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, Integer.toString(VALIDATOR_PING_PERIOD));
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, Integer.toString(VALIDATOR_PING_TIMEOUT));
+ clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
+ addExtraClientConfig(clientConfig);
+ Client client1 = new Client(clientLocator, clientConfig);
+ TestConnectionListener clientConnectionListener1 = new TestConnectionListener("clientConnectionListener1");
+ Map metadata = new HashMap();
+ metadata.put("abc", "xyz");
+ client1.connect(clientConnectionListener1, metadata);
+ Client client2 = new Client(clientLocator, clientConfig);
+ TestConnectionListener clientConnectionListener2 = new TestConnectionListener("clientConnectionListener2");
+ metadata.put("abc", "123");
+ client2.connect(clientConnectionListener2, metadata);
+ log.info("clients are connected");
+
+ // Test connection.
+ assertEquals("abc", client1.invoke("abc"));
+ assertEquals("abc", client2.invoke("abc"));
+ log.info("connections are good");
+
+ // Verify Clients have distinct ConnectionValidators.
+ Field field = Client.class.getDeclaredField("connectionValidator");
+ field.setAccessible(true);
+ ConnectionValidator connectionValidator1 = (ConnectionValidator) field.get(client1);
+ ConnectionValidator connectionValidator2 = (ConnectionValidator) field.get(client2);
+ assertNotSame(connectionValidator1, connectionValidator2);
+
+ // Test client side connection failure notifications.
+ int wait = (PING_PERIODS_TO_WAIT + 1) * VALIDATOR_PING_PERIOD + VALIDATOR_PING_TIMEOUT + 2000;
+ log.info(getName() + " going to sleep for " + wait + " ms");
+ Thread.sleep(wait);
+ log.info("checking connection failure notifications");
+ assertEquals(1, clientConnectionListener1.calledCounter);
+ assertTrue(clientConnectionListener1.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener1.throwable.getMessage());
+ assertEquals(1, clientConnectionListener2.calledCounter);
+ assertTrue(clientConnectionListener2.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener2.throwable.getMessage());
+
+ client1.removeConnectionListener(clientConnectionListener1);
+ client1.disconnect();
+ client2.removeConnectionListener(clientConnectionListener2);
+ client2.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ public void testIdentityTrueTwoClientsTwoConnectionValidatorsFourConnectionListeners() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer(true, "true");
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(Client.ENABLE_LEASE, "true");
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_PERIOD, Integer.toString(VALIDATOR_PING_PERIOD));
+ clientConfig.put(ConnectionValidator.VALIDATOR_PING_TIMEOUT, Integer.toString(VALIDATOR_PING_TIMEOUT));
+ clientConfig.put(ConnectionValidator.FAILURE_DISCONNECT_TIMEOUT, "0");
+ addExtraClientConfig(clientConfig);
+ Client client1 = new Client(clientLocator, clientConfig);
+ TestConnectionListener clientConnectionListener1a = new TestConnectionListener("clientConnectionListener1a");
+ TestConnectionListener clientConnectionListener1b = new TestConnectionListener("clientConnectionListener1b");
+ Map metadata = new HashMap();
+ metadata.put("abc", "xyz");
+ client1.connect(clientConnectionListener1a, metadata);
+ client1.addConnectionListener(clientConnectionListener1b);
+ Client client2 = new Client(clientLocator, clientConfig);
+ TestConnectionListener clientConnectionListener2a = new TestConnectionListener("clientConnectionListener2a");
+ TestConnectionListener clientConnectionListener2b = new TestConnectionListener("clientConnectionListener2b");
+ metadata.put("abc", "123");
+ client2.connect(clientConnectionListener2a, metadata);
+ client2.addConnectionListener(clientConnectionListener2b);
+ log.info("clients are connected");
+
+ // Test connection.
+ assertEquals("abc", client1.invoke("abc"));
+ assertEquals("abc", client2.invoke("abc"));
+ log.info("connections are good");
+
+ // Verify Clients have distinct ConnectionValidators.
+ Field field = Client.class.getDeclaredField("connectionValidator");
+ field.setAccessible(true);
+ ConnectionValidator connectionValidator1 = (ConnectionValidator) field.get(client1);
+ ConnectionValidator connectionValidator2 = (ConnectionValidator) field.get(client2);
+ assertNotSame(connectionValidator1, connectionValidator2);
+
+ // Test client side connection failure notifications.
+ int wait = (PING_PERIODS_TO_WAIT + 1) * VALIDATOR_PING_PERIOD + VALIDATOR_PING_TIMEOUT + 2000;
+ log.info(getName() + " going to sleep for " + wait + " ms");
+ Thread.sleep(wait);
+ log.info("checking connection failure notifications");
+ assertEquals(1, clientConnectionListener1a.calledCounter);
+ assertTrue(clientConnectionListener1a.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener1a.throwable.getMessage());
+ assertEquals(1, clientConnectionListener1b.calledCounter);
+ assertTrue(clientConnectionListener1b.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener1b.throwable.getMessage());
+ assertEquals(1, clientConnectionListener2a.calledCounter);
+ assertTrue(clientConnectionListener2a.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener2a.throwable.getMessage());
+ assertEquals(1, clientConnectionListener2b.calledCounter);
+ assertTrue(clientConnectionListener2b.throwable instanceof Exception);
+ assertEquals("Could not connect to server!", clientConnectionListener2b.throwable.getMessage());
+
+ client1.removeConnectionListener(clientConnectionListener1a);
+ client1.removeConnectionListener(clientConnectionListener1b);
+ client1.disconnect();
+ client2.removeConnectionListener(clientConnectionListener2a);
+ client2.removeConnectionListener(clientConnectionListener2b);
+ client2.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "test";
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer(boolean addUseClientConnectionIdentity, String useClientConnectionIdentity) throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port + "/?x=x";
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "&" + metadata;
+ }
+ if (addUseClientConnectionIdentity)
+ {
+ locatorURI += "&" + Remoting.USE_CLIENT_CONNECTION_IDENTITY + "=" + useClientConnectionIdentity;
+ }
+ 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.setLeasePeriod(LEASE_PERIOD);
+ serverConnectionListener = new TestConnectionListener("serverConnectionListener");
+ connector.addConnectionListener(serverConnectionListener);
+ 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) {}
+ }
+
+
+ static class TestConnectionListener implements ConnectionListener
+ {
+ String name;
+ Throwable throwable;
+ int calledCounter;
+
+ public TestConnectionListener(String name)
+ {
+ this.name = name;
+ }
+ public void handleConnectionException(Throwable throwable, Client client)
+ {
+ calledCounter++;
+ this.throwable = throwable;
+ log.info(name + " notified: throwable = " + throwable);
+ }
+ }
+
+
+ static class TestServerInvoker extends SocketServerInvoker
+ {
+ int counter;
+
+ public TestServerInvoker(InvokerLocator locator, Map configuration)
+ {
+ super(locator, configuration);
+ }
+ public TestServerInvoker(InvokerLocator locator)
+ {
+ super(locator);
+ }
+
+ public Object invoke(InvocationRequest invocation) throws Throwable
+ {
+ Object param = invocation.getParameter();
+// log.info("TestServerInvoker.invoke() entered: " + param);
+ if ("$PING$".equals(param))
+ {
+ Map metadata = invocation.getRequestPayload();
+ if (metadata != null)
+ {
+// log.info("metadata: " + metadata);
+ String invokerSessionId = (String) metadata.get(INVOKER_SESSION_ID);
+ if (invokerSessionId != null)
+ {
+ log.info(this + " got a ConnectionValidator $PING$");
+ if (++counter > PING_PERIODS_TO_WAIT)
+ {
+ int wait = 2 * VALIDATOR_PING_TIMEOUT;
+ log.info(this + " going to sleep for " + wait + " ms");
+ Thread.sleep(wait);
+ }
+ }
+ }
+ }
+ return super.invoke(invocation);
+ }
+
+ public String toString()
+ {
+ String s = super.toString();
+ int i = s.indexOf('[');
+ return "TestServerInvoker" + s.substring(i);
+ }
+ }
+
+
+ public static class TestClientFactory implements ClientFactory
+ {
+ public ClientInvoker createClientInvoker(InvokerLocator locator, Map config) throws IOException
+ {
+ log.info("TestClientFaotory.createClientInvoker() called");
+ return new SocketClientInvoker(locator, config);
+ }
+ public boolean supportsSSL()
+ {
+ return false;
+ }
+ }
+
+
+ public static class TestServerFactory implements ServerFactory
+ {
+ public ServerInvoker createServerInvoker(InvokerLocator locator, Map config) throws IOException
+ {
+ log.info("TestServerFactory.createServerInvoker() called");
+ return new TestServerInvoker(locator, config);
+ }
+ public boolean supportsSSL()
+ {
+ return false;
+ }
+ }
+}
\ No newline at end of file
14 years, 11 months
JBoss Remoting SVN: r5223 - remoting2/branches/2.x/src/main/org/jboss/remoting/callback.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-14 23:08:58 -0400 (Thu, 14 May 2009)
New Revision: 5223
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/callback/DefaultCallbackErrorHandler.java
Log:
JBREM-1132: Changed a log.warn() to log.debug().
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/callback/DefaultCallbackErrorHandler.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/callback/DefaultCallbackErrorHandler.java 2009-05-15 03:05:50 UTC (rev 5222)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/callback/DefaultCallbackErrorHandler.java 2009-05-15 03:08:58 UTC (rev 5223)
@@ -125,7 +125,7 @@
throw ex;
}
- log.warn(this + " reached maximum number of callback errors allowed (" +
+ log.debug(this + " reached maximum number of callback errors allowed (" +
numOfErrorsAllowed + "). Will clean up callback hander now.");
if (serverInvoker != null)
14 years, 11 months
JBoss Remoting SVN: r5222 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-14 23:05:50 -0400 (Thu, 14 May 2009)
New Revision: 5222
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
Log:
JBREM-1132: Reorganized cleanup().
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java 2009-05-15 02:58:30 UTC (rev 5221)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketServerInvoker.java 2009-05-15 03:05:50 UTC (rev 5222)
@@ -736,11 +736,6 @@
protected void cleanup()
{
- super.cleanup();
-
- if (controlMonitorTimerTask != null)
- controlMonitorTimerTask.shutdown();
-
synchronized (controlConnectionThreadMap)
{
Iterator it = controlConnectionThreadMap.values().iterator();
@@ -751,6 +746,11 @@
t.shutdown();
}
}
+
+ super.cleanup();
+
+ if (controlMonitorTimerTask != null)
+ controlMonitorTimerTask.shutdown();
Iterator it = secondaryServerSocketThreads.iterator();
while (it.hasNext())
@@ -1070,6 +1070,11 @@
return;
}
+ if (!running)
+ {
+ return;
+ }
+
try
{
processInvocation(socket);
14 years, 11 months
JBoss Remoting SVN: r5221 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-14 22:58:30 -0400 (Thu, 14 May 2009)
New Revision: 5221
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
Log:
JBREM-1132: Introduced "useClientConnectionIdentity".
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java 2009-05-15 02:49:58 UTC (rev 5220)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java 2009-05-15 02:58:30 UTC (rev 5221)
@@ -277,6 +277,8 @@
protected ServerSocketFactory serverSocketFactory = null;
protected boolean registerCallbackListeners = true;
+
+ protected boolean useClientConnectionIdentity;
// Constructors ---------------------------------------------------------------------------------
@@ -293,6 +295,17 @@
public ServerInvoker(InvokerLocator locator, Map configuration)
{
super(locator, configuration);
+
+ if (configuration != null)
+ {
+ this.configuration.putAll(configuration);
+ }
+
+ Map locatorParams = locator.getParameters();
+ if(locatorParams != null)
+ {
+ this.configuration.putAll(locator.getParameters());
+ }
}
// Public ---------------------------------------------------------------------------------------
@@ -322,6 +335,11 @@
{
return timeout;
}
+
+ public ConnectionNotifier getConnectionNotifier()
+ {
+ return connectionNotifier;
+ }
public boolean isLeaseActivated()
{
@@ -726,6 +744,16 @@
return (ServerInvocationHandler) handlers.get(subsystem.toUpperCase());
}
+ protected boolean isUseClientConnectionIdentity()
+ {
+ return useClientConnectionIdentity;
+ }
+
+ protected void setUseClientConnectionIdentity(boolean useClientConnectionIdentity)
+ {
+ this.useClientConnectionIdentity = useClientConnectionIdentity;
+ }
+
public Object invoke(Object invoke) throws IOException
{
InvocationRequest request = null;
@@ -1117,6 +1145,13 @@
}
}
+ // config for useClientConnectionIdentity
+ String useClientConnectionIdentityString = (String)config.get(Remoting.USE_CLIENT_CONNECTION_IDENTITY);
+ if(useClientConnectionIdentityString != null)
+ {
+ useClientConnectionIdentity = Boolean.parseBoolean(useClientConnectionIdentityString);
+ }
+
// Inject ConnectionListener
String connectionListener = (String)config.get(CONNECTION_LISTENER);
if (connectionListener != null)
@@ -1879,6 +1914,7 @@
{
if (invocation != null)
{
+ // clientSessionId == MicroRemoteClientInvoker.invokerSessionID.
String clientSessionId = invocation.getSessionId();
Lease clientLease = (Lease)clientLeases.get(clientSessionId);
@@ -1914,7 +1950,7 @@
else
{
String type = "invoker";
- Map reqMap = invocation.getRequestPayload();
+ Map reqMap = invocation.getRequestPayload();
if (reqMap != null)
{
Object holderObj = reqMap.get(ClientHolder.CLIENT_HOLDER_KEY);
@@ -1923,8 +1959,9 @@
type = "client";
}
}
- log.warn("Asked to terminate " + type + " lease for client session id " + clientSessionId +
- ", but lease for this id could not be found." + ": " + clientLeases);
+ log.debug("Asked to terminate " + type + " lease for invoker session id "
+ + clientSessionId + ", but lease for this id could not be found." +"" +
+ "Probably has been removed due to connection failure.");
}
}
}
@@ -1941,7 +1978,7 @@
}
if(clientSessionId != null)
{
- if(trace) { log.trace("Getting lease for client session id: " + clientSessionId); }
+ if(trace) { log.trace("Getting lease for invoker session id: " + clientSessionId); }
Lease clientLease = (Lease)clientLeases.get(clientSessionId);
if(clientLease == null)
@@ -1954,15 +1991,48 @@
clientLeases.put(clientSessionId, newClientLease);
newClientLease.startLease();
-
- if(trace) { log.trace("No lease established for client session id (" + clientSessionId + "), so starting a new one."); }
+
+ if(trace) { log.trace("No lease established for invoker session id (" + clientSessionId +
+ "), so starting a new one:" + newClientLease); }
}
else
{
- // including request payload from invocation as may contain updated list of clients.
- clientLease.updateLease(leasePeriod, invocation.getRequestPayload());
+ if (useClientConnectionIdentity)
+ {
+ String leasePingerId = (String) invocation.getRequestPayload().get(LeasePinger.LEASE_PINGER_ID);;
+ if (leasePingerId.equals(clientLease.getLeasePingerId()))
+ {
+ // including request payload from invocation as may contain updated list of clients.
+ if (trace) log.trace(clientLease + " matches: leasePingerId: " + leasePingerId);
+ clientLease.updateLease(leasePeriod, invocation.getRequestPayload());
+ if(trace) { log.trace("Updated lease for invoker session id (" + clientSessionId + ")"); }
+ }
+ else
+ {
+ if (trace) log.trace(clientLease + " does not match: leasePingerId: " + leasePingerId);
+ if (trace) log.trace("terminating invoker lease: " + clientLease);
+ clientLease.terminateLeaseUponFailure(clientSessionId);
+ clientLeases.remove(clientSessionId);
- if(trace) { log.trace("Updated lease for client session id (" + clientSessionId + ")"); }
+ Lease newClientLease = new Lease(clientSessionId, leasePeriod,
+ locator.getLocatorURI(),
+ invocation.getRequestPayload(),
+ connectionNotifier,
+ clientLeases);
+
+ clientLeases.put(clientSessionId, newClientLease);
+ newClientLease.startLease();
+
+ if(trace) { log.trace("starting a new lease:" + newClientLease); }
+ }
+ }
+ else
+ {
+ // including request payload from invocation as may contain updated list of clients.
+ clientLease.updateLease(leasePeriod, invocation.getRequestPayload());
+
+ if(trace) { log.trace("Updated lease for client session id (" + clientSessionId + ")"); }
+ }
}
}
}
@@ -1972,7 +2042,7 @@
{
if(leaseManagement && invokerSessionId != null)
{
- if(trace) { log.trace("Checking lease for client session id: " + invokerSessionId); }
+ if(trace) { log.trace("Checking lease for invoker session id: " + invokerSessionId); }
Lease clientLease = (Lease)clientLeases.get(invokerSessionId);
if(clientLease == null)
@@ -2064,6 +2134,7 @@
{
callbackHandler = (ServerInvokerCallbackHandler) callbackHandlers.remove(id);
}
+ log.debug(this + " removed " + callbackHandler);
return callbackHandler;
}
14 years, 11 months
JBoss Remoting SVN: r5220 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-14 22:49:58 -0400 (Thu, 14 May 2009)
New Revision: 5220
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java
Log:
JBREM-1132: Introduced "useClientConnectionIdentity".
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java 2009-05-15 02:46:42 UTC (rev 5219)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Remoting.java 2009-05-15 02:49:58 UTC (rev 5220)
@@ -112,4 +112,12 @@
* well as the configuration map when creating a SocketFactory.
*/
public static final String USE_ALL_SOCKET_FACTORY_PARAMS = "useAllSocketFactoryParams";
+
+ /**
+ * Flags indicating that connection monitoring should treat a connection as being defined
+ * by one or two of its endpoints. I.e., if a [client invoker or] server invoker stops and restarts, then
+ * all connections it participated in are now gone.
+ */
+ public static final String USE_CLIENT_CONNECTION_IDENTITY = "useClientConnectionIdentity";
+// public static final String USE_SERVER_CONNECTION_IDENTITY = "useServerConnectionIdentity";
}
14 years, 11 months
JBoss Remoting SVN: r5219 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-14 22:46:42 -0400 (Thu, 14 May 2009)
New Revision: 5219
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
Log:
JBREM-1132: (1) Adopted use of leasePingerId; (2) establishLease() can call Client.addConnectionListener(); JBREM-1133: sends time stamp with first PING.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2009-05-15 02:13:24 UTC (rev 5218)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2009-05-15 02:46:42 UTC (rev 5219)
@@ -385,14 +385,26 @@
public void terminateLease(String sessionId, int disconnectTimeout)
{
+ terminateLease(sessionId, disconnectTimeout, null);
+ }
+
+ public void terminateLease(String sessionId, int disconnectTimeout, LeasePinger passedLeasePinger)
+ {
synchronized(clientLeaseLock)
{
+ if (passedLeasePinger != null && passedLeasePinger != leasePinger)
+ {
+ if (trace) log.trace(this + ": " + passedLeasePinger + " != " + leasePinger);
+ return;
+ }
+ if (trace) log.trace(this + " entering terminateLease() for " + leasePinger);
if(leasePinger != null)
{
leasePinger.setDisconnectTimeout(disconnectTimeout);
if (sessionId == null)
{
+ if (trace) log.trace(this + " shutting down LeasePinger: " + leasePinger);
// Independent of any particular Client - force LeasePinger shutdown.
// Should be called only if there is a reasonable belief that the lease
// has already stopped on the server side.
@@ -402,16 +414,19 @@
}
catch (Exception e)
{
- log.debug("error shutting down lease pinger");
+ log.debug("error shutting down lease pinger" + e.getMessage());
+ log.trace("error shutting down lease pinger", e);
}
leasePinger = null;
}
else
{
// Remove a particular Client.
+ if (trace) log.trace(this + " removing client " + sessionId + " from LeasePinger: " + leasePinger);
boolean isLastClientLease = leasePinger.removeClient(sessionId);
if(isLastClientLease)
{
+ if (trace) log.trace(this + " shutting down LeasePinger, " + sessionId + " was last client lease: " + leasePinger);
try
{
leasePinger.stopPing();
@@ -424,6 +439,11 @@
}
}
}
+ else
+ {
+ if (trace) log.trace(this + " leasePinger is null: must have been shut down already");
+ }
+ if (trace) log.trace(this + " leaving terminateLease() for " + leasePinger);
}
}
@@ -443,6 +463,22 @@
public void establishLease(String clientSessionID, Map configuration, long leasePeriod)
throws Throwable
{
+ Client client = (Client) configuration.get(Client.CLIENT);
+ ConnectionListener listener = (ConnectionListener) configuration.remove(Client.CONNECTION_LISTENER);
+ boolean useClientConnectionIdentity = false;
+ if (configuration != null)
+ {
+ Object o = configuration.get(Remoting.USE_CLIENT_CONNECTION_IDENTITY);
+ if (o instanceof String)
+ {
+ useClientConnectionIdentity = Boolean.valueOf((String) o).booleanValue();
+ }
+ else if (o != null)
+ {
+ log.warn("value of " + Remoting.USE_CLIENT_CONNECTION_IDENTITY + " must be a String: " + o);
+ }
+ }
+
synchronized (clientLeaseLock)
{
// if already have a lease pinger, then already have a client with an established
@@ -450,55 +486,68 @@
if (leasePinger != null)
{
leasePinger.addClient(clientSessionID, configuration, leasePeriod);
- log.debug(this + " added client with session ID " + clientSessionID + " to the lease pinger");
- return;
+ if (trace) log.trace(this + " added client with session ID " + clientSessionID + " to " + leasePinger);
}
-
- try
+ else
{
- if(trace) { log.trace(this + " sending initial lease ping to server to determine if server has leasing enabled."); }
+ try
+ {
+ if(trace) { log.trace(this + " sending initial lease ping to server to determine if server has leasing enabled."); }
- // configuration should NOT be passed as want ping to be specific to client invoker
- // and NOT to the client.
+ // configuration should NOT be passed as want ping to be specific to client invoker
+ // and NOT to the client.
- InvocationRequest ir =
- new InvocationRequest(invokerSessionID, null, "$PING$", null, new HashMap(), null);
+ String leasePingerId = new GUID().toString();
+ Map requestMap = new HashMap();
+ requestMap.put(LeasePinger.LEASE_PINGER_ID, leasePingerId);
+ requestMap.put(LeasePinger.TIME_STAMP, Long.toString(System.currentTimeMillis()));
+ if (trace) log.trace(this + " initiating lease for leasePingerId " + leasePingerId);
+ InvocationRequest ir = new InvocationRequest(invokerSessionID, null, "$PING$", requestMap, new HashMap(), null);
- Object ret = invoke(ir);
+ Object ret = invoke(ir);
- if (ret instanceof InvocationResponse)
- {
- InvocationResponse resp = (InvocationResponse) ret;
- Boolean shouldLease = (Boolean)resp.getResult();
-
- if (shouldLease.booleanValue())
+ if (ret instanceof InvocationResponse)
{
- long defaultLeasePeriod = LeasePinger.DEFAULT_LEASE_PERIOD;
- Map respMap = resp.getPayload();
+ InvocationResponse resp = (InvocationResponse) ret;
+ Boolean shouldLease = (Boolean)resp.getResult();
- if (respMap != null)
+ if (shouldLease.booleanValue())
{
- Long leaseTimeoutValue = (Long)respMap.get("clientLeasePeriod");
- long serverDefaultLeasePeriod = leaseTimeoutValue.longValue();
- if(serverDefaultLeasePeriod > 0)
+ long defaultLeasePeriod = LeasePinger.DEFAULT_LEASE_PERIOD;
+ Map respMap = resp.getPayload();
+
+ if (respMap != null)
{
- defaultLeasePeriod = serverDefaultLeasePeriod;
+ Long leaseTimeoutValue = (Long)respMap.get("clientLeasePeriod");
+ long serverDefaultLeasePeriod = leaseTimeoutValue.longValue();
+ if(serverDefaultLeasePeriod > 0)
+ {
+ defaultLeasePeriod = serverDefaultLeasePeriod;
+ }
}
- }
- if(trace) { log.trace("server does have leasing enabled (with default lease period of " + defaultLeasePeriod + ") and will start a new lease pinger."); }
+ if(trace) { log.trace("server does have leasing enabled (with default lease period of " + defaultLeasePeriod + ") and will start a new lease pinger."); }
- leasePinger = new LeasePinger(this, invokerSessionID, defaultLeasePeriod, configuration);
- leasePinger.addClient(clientSessionID, configuration, leasePeriod);
- leasePinger.startPing();
+ leasePinger = new LeasePinger(this, invokerSessionID, defaultLeasePeriod);
+ leasePinger.setLeasePingerId(leasePingerId);
+ leasePinger.setUseClientConnectionIdentity(useClientConnectionIdentity);
+ leasePinger.addClient(clientSessionID, configuration, leasePeriod);
+ leasePinger.startPing();
+ }
}
}
+ catch (Throwable throwable)
+ {
+ Exception e = new Exception("Error setting up client lease");
+ e.initCause(throwable);
+ throw e;
+ }
}
- catch (Throwable throwable)
+
+ if (trace) log.trace(this + ": client = " + client + ", listener = " + listener);
+ if (client != null && listener != null)
{
- Exception e = new Exception("Error setting up client lease");
- e.initCause(throwable);
- throw e;
+ client.addConnectionListener(listener, configuration);
}
}
}
@@ -633,6 +682,14 @@
super.finalize();
}
+ protected LeasePinger getLeasePinger()
+ {
+ synchronized(clientLeaseLock)
+ {
+ return leasePinger;
+ }
+ }
+
static private String getSystemProperty(final String name)
{
if (SecurityUtility.skipAccessControl())
14 years, 11 months
JBoss Remoting SVN: r5218 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-14 22:13:24 -0400 (Thu, 14 May 2009)
New Revision: 5218
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/LeasePinger.java
Log:
(1) JBREM-1132: Adopted use of leasePingerId; (2) JBREM-1133: adopted use of time stamp.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/LeasePinger.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/LeasePinger.java 2009-05-15 02:06:55 UTC (rev 5217)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/LeasePinger.java 2009-05-15 02:13:24 UTC (rev 5218)
@@ -2,7 +2,6 @@
import org.jboss.logging.Logger;
import org.jboss.remoting.transport.ClientInvoker;
-
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -27,6 +26,9 @@
public static final int DEFAULT_DISCONNECT_TIMEOUT = -1;
public static final String LEASE_PINGER_TIMEOUT = "leasePingerTimeout";
+ static final String LEASE_PINGER_ID = "leasePingerId";
+ static final String TIME_STAMP = "timeStamp";
+
// Static ---------------------------------------------------------------------------------------
private static boolean trace = log.isTraceEnabled();
@@ -40,6 +42,7 @@
private ClientInvoker invoker = null;
private String invokerSessionID = null;
+ private Map clientSessionIds = new ConcurrentHashMap();
private Map clients = new ConcurrentHashMap();
private TimerTask timerTask = null;
@@ -50,6 +53,9 @@
// The following variables exist for testing purposes.
private boolean pingInvoked;
private boolean pingSucceeded;
+
+ private String leasePingerId;
+ private boolean useClientConnectionIdentity;
// Constructors ---------------------------------------------------------------------------------
@@ -118,6 +124,18 @@
timerTask.cancel();
timerTask = null;
+ if (useClientConnectionIdentity)
+ {
+ Iterator it = clients.values().iterator();
+ while (it.hasNext())
+ {
+ Client client = (Client) it.next();
+ if (trace) log.trace(this + " calling " + client + ".notifyAndDisconnect()");
+ client.notifyListeners();
+ it.remove();
+ }
+ }
+
try
{
// sending request map with no ClientHolders will indicate to server
@@ -125,7 +143,7 @@
HashMap metadata = null;
// If disconnectTimeout == 0, skip network i/o.
- log.debug(this + ": disconnectTimeout: " + disconnectTimeout);
+ if (trace) log.trace(this + ": disconnectTimeout: " + disconnectTimeout);
if (disconnectTimeout != 0)
{
if (disconnectTimeout > 0)
@@ -144,6 +162,25 @@
e.initCause(throwable);
throw e;
}
+
+ if (trace)
+ {
+ log.trace(this + " shut down");
+ if (!clientSessionIds.isEmpty())
+ {
+ log.trace(this + " " + clientSessionIds.size() + " remaining clients:");
+ Iterator it = clientSessionIds.keySet().iterator();
+ while (it.hasNext())
+ {
+ log.trace(this + ": " + it.next());
+ }
+ clientSessionIds.clear();
+ }
+ else
+ {
+ log.trace(this + " No remaining clients");
+ }
+ }
}
}
@@ -156,8 +193,17 @@
if(trace) { log.trace(this + " adding new client with session ID " + sessionID + " and lease period " + leasePeriod); }
+ if (useClientConnectionIdentity)
+ {
+ Client client = (Client) configuration.remove(Client.CLIENT);
+ if (client != null)
+ {
+ clients.put(sessionID, client);
+ }
+ }
+
ClientHolder newClient = new ClientHolder(sessionID, configuration, leasePeriod);
- clients.put(sessionID, newClient);
+ clientSessionIds.put(sessionID, newClient);
sendClientPing();
@@ -182,7 +228,9 @@
if(trace) { log.trace(this + " removing client with session ID " + sessionID); }
- ClientHolder holder = (ClientHolder)clients.remove(sessionID);
+ // Don't remove holder until after client has been removed from server side Lease, to
+ // avoid a race with LeaseTimerTask sending a PING without the Client being removed.
+ ClientHolder holder = (ClientHolder)clientSessionIds.get(sessionID);
if (holder != null)
{
@@ -210,14 +258,20 @@
log.debug(this + " failed sending disconnect for client lease for " +
"client with session ID " + sessionID);
}
+
+ clientSessionIds.remove(sessionID);
+ if (useClientConnectionIdentity)
+ {
+ clients.remove(sessionID);
+ }
}
else
{
log.debug(this + " tried to remove lease for client with session ID " + sessionID +
- ", but no such lease was found");
+ ", but no such lease was found: probably it was registered with an older LeasePinger");
}
- if (clients.isEmpty())
+ if (clientSessionIds.isEmpty())
{
isLastClientLease = true;
if(trace) { log.trace(this + " has no more client leases"); }
@@ -229,7 +283,7 @@
long tempPingPeriod = defaultPingPeriod;
- for (Iterator i = clients.values().iterator(); i.hasNext(); )
+ for (Iterator i = clientSessionIds.values().iterator(); i.hasNext(); )
{
ClientHolder clientHolder = (ClientHolder)i.next();
long clientHolderLeasePeriod = clientHolder.getLeasePeriod();
@@ -265,7 +319,7 @@
}
// look to see if the client is still amont those serviced by this lease pinger
- if (clients.containsKey(sessionID))
+ if (clientSessionIds.containsKey(sessionID))
{
return pingPeriod;
}
@@ -277,7 +331,7 @@
public String toString()
{
- return "LeasePinger[" + invoker + "(" + invokerSessionID + ")]";
+ return "LeasePinger[" + leasePingerId + ":" + invoker + "(" + invokerSessionID + ")]";
}
// Package protected ----------------------------------------------------------------------------
@@ -293,9 +347,29 @@
protected void setDisconnectTimeout(int disconnectTimeout)
{
this.disconnectTimeout = disconnectTimeout;
- log.debug(this + " setting disconnect timeout to: " + disconnectTimeout);
+ if (trace) log.trace(this + " setting disconnect timeout to: " + disconnectTimeout);
}
+ protected String getLeasePingerId()
+ {
+ return leasePingerId;
+ }
+
+ protected void setLeasePingerId(String leasePingerId)
+ {
+ this.leasePingerId = leasePingerId;
+ }
+
+ boolean isUseClientConnectionIdentity()
+ {
+ return useClientConnectionIdentity;
+ }
+
+ void setUseClientConnectionIdentity(boolean useClientConnectionIdentity)
+ {
+ this.useClientConnectionIdentity = useClientConnectionIdentity;
+ }
+
// Private --------------------------------------------------------------------------------------
private void sendClientPing()
@@ -305,9 +379,9 @@
if(trace)
{
StringBuffer sb = new StringBuffer();
- if(clients != null)
+ if(clientSessionIds != null)
{
- for(Iterator i = clients.values().iterator(); i.hasNext(); )
+ for(Iterator i = clientSessionIds.values().iterator(); i.hasNext(); )
{
ClientHolder h = (ClientHolder)i.next();
sb.append(" ").append(h.getSessionId()).append('\n');
@@ -315,20 +389,21 @@
}
log.trace(this + " sending ping to server. Currently managing lease " +
- "for following clients:\n" + sb.toString());
+ "for following clients:\n" + sb.toString());
}
- Map clientsClone = new ConcurrentHashMap(clients);
+ Map clientsClone = new ConcurrentHashMap(clientSessionIds);
Map requestClients = new ConcurrentHashMap();
requestClients.put(ClientHolder.CLIENT_HOLDER_KEY, clientsClone);
+ requestClients.put(LeasePinger.LEASE_PINGER_ID, leasePingerId);
+ requestClients.put(TIME_STAMP, Long.toString(System.currentTimeMillis()));
if (leasePingerTimeout >= 0)
{
requestClients.put(ServerInvoker.TIMEOUT, Integer.toString(leasePingerTimeout));
}
- InvocationRequest ir =
- new InvocationRequest(invokerSessionID, null, "$PING$", requestClients, null, null);
+ InvocationRequest ir = new InvocationRequest(invokerSessionID, null, "$PING$", requestClients, null, null);
pingSucceeded = false;
pingInvoked = true;
@@ -342,6 +417,7 @@
{
pingInvoked = false;
log.debug(this + " failed to ping to server", t);
+ log.warn(this + " failed to ping to server: " + t.getMessage());
}
}
14 years, 11 months
JBoss Remoting SVN: r5217 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-14 22:06:55 -0400 (Thu, 14 May 2009)
New Revision: 5217
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/Lease.java
Log:
(1) JBREM-1132: Adopted use of leasePingerId; (2) JBREM-1133: adopted use of time stamp.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/Lease.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Lease.java 2009-05-15 01:58:55 UTC (rev 5216)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Lease.java 2009-05-15 02:06:55 UTC (rev 5217)
@@ -25,6 +25,7 @@
import org.jboss.remoting.util.TimerUtil;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TimerTask;
@@ -48,8 +49,13 @@
private long leaseWindow = -1;
private long pingStart = -1;
private Map clientLeases = null;
+ private Object lock = new Object();
+ private String leasePingerId;
+ private boolean stopped;
private boolean leaseUpdated = false;
+ private long lastUpdate;
+ private boolean useClientConnectionIdentity;
private static final Logger log = Logger.getLogger(Lease.class);
private static final boolean isTraceEnabled = log.isTraceEnabled();
@@ -64,6 +70,16 @@
if(requestPayload != null)
{
this.requestPayload = (Map)requestPayload.get(ClientHolder.CLIENT_HOLDER_KEY);
+ this.leasePingerId = (String) requestPayload.get(LeasePinger.LEASE_PINGER_ID);
+ String s = (String) requestPayload.get(LeasePinger.TIME_STAMP);
+ if (s != null)
+ {
+ this.lastUpdate = Long.valueOf(s).longValue();
+ this.useClientConnectionIdentity = true;
+ if (isTraceEnabled) log.trace(this + " initialized with lastUpdate: " + lastUpdate);
+ }
+ if (isTraceEnabled) log.trace(this + " initialized with requestPayload: " + this.requestPayload);
+ if (isTraceEnabled) log.trace("leasePingerId: " + leasePingerId);
}
this.leaseWindow = leasePeriod * 2;
this.clientLeases = clientLeases;
@@ -84,9 +100,36 @@
{
if(requestMap != null)
{
- this.requestPayload = (Map)requestMap.get(ClientHolder.CLIENT_HOLDER_KEY);
+ synchronized (lock)
+ {
+ if (useClientConnectionIdentity)
+ {
+ if (isTraceEnabled) log.trace(this + " requestMap: " + requestMap);
+ long time = 0;
+ String timeString = (String) requestMap.get(LeasePinger.TIME_STAMP);
+ time = Long.valueOf(timeString).longValue();
+ if (isTraceEnabled) log.trace(this + " last update: " + lastUpdate + ", this update: " + time);
+ if (time > lastUpdate)
+ {
+ lastUpdate = time;
+ doUpdate(requestMap);
+ }
+ else
+ {
+ if (isTraceEnabled) log.trace(this + " updating lease but not client list");
+ leaseUpdated = true;
+ }
+ }
+ else
+ {
+ doUpdate(requestMap);
+ }
+ }
}
- updateLease(leasePeriod);
+ else
+ {
+ if (isTraceEnabled) log.trace(this + " requestPayload == null");
+ }
}
public void updateLease(long leasePeriod)
@@ -124,13 +167,14 @@
public void terminateLease(String sessionId)
{
- if(isTraceEnabled)
- {
- log.trace("Terminating lease for session id " + sessionId);
- }
// is this terminate for all clients
if (clientSessionId.equals(sessionId))
{
+ if(isTraceEnabled)
+ {
+ log.trace(this + " Terminating lease group for session id " + sessionId);
+ }
+
stopLease();
// should be ok to call this will null as all the client should have
// already been disconnected and there been a notification for each
@@ -140,33 +184,101 @@
}
else
{
+ if(isTraceEnabled)
+ {
+ log.trace(this + " Terminating individual lease for session id " + sessionId);
+ }
notifyClientTermination(sessionId);
}
}
-
+
+ public void terminateLeaseUponFailure(String sessionId)
+ {
+ // is this terminate for all clients
+ if (clientSessionId.equals(sessionId))
+ {
+ if(isTraceEnabled)
+ {
+ log.trace(this + " Terminating lease group for session id " + sessionId);
+ }
+
+ stopLease();
+ // should be ok to call this will null as all the client should have
+ // already been disconnected and there been a notification for each
+ // of these client disconnections (which would remove the client from
+ // the lease, thus leaving the collection empty
+ notifyClientLost();
+ }
+ else
+ {
+ if(true)
+ {
+ log.warn(this + " Expected invoker session id: " + sessionId);
+ }
+ notifyClientLost();
+ }
+ }
+
+ public String toString()
+ {
+ String hash = Integer.toHexString(System.identityHashCode(this));
+ return "Lease[" + hash + ":" + clientSessionId + ":" + leasePingerId + "]";
+ }
+
private void notifyClientTermination(String sessionId)
{
- // is for a particular client, so need to inspect request payload for client
- if (requestPayload != null)
+ Map localRequestPayload = null;
+ synchronized (lock)
{
+ if (requestPayload != null)
+ {
+ localRequestPayload = new HashMap(requestPayload);
+ if (sessionId != null)
+ {
+ requestPayload.remove(sessionId);
+ }
+ }
+ }
+
+ if (localRequestPayload != null)
+ {
// should notify for one client or all?
if (sessionId != null)
{
- Object clientHolderObj = requestPayload.remove(sessionId);
+ synchronized (lock)
+ {
+ if (stopped)
+ {
+ if (isTraceEnabled) log.trace(this + " already stopped");
+ return;
+ }
+ }
+
+ Object clientHolderObj = localRequestPayload.get(sessionId);
if (clientHolderObj != null && clientHolderObj instanceof ClientHolder)
{
ClientHolder clientHolder = (ClientHolder) clientHolderObj;
notifier.connectionTerminated(locatorURL, clientHolder.getSessionId(), clientHolder.getConfig());
if(isTraceEnabled)
{
- log.trace("Notified connection listener of lease termination due to disconnect from client (client session id = " + clientHolder.getSessionId());
+ log.trace(this + " Notified connection listener of lease termination due to disconnect from client (client session id = " + clientHolder.getSessionId());
}
}
}
else
{
+ synchronized (lock)
+ {
+ if (stopped)
+ {
+ if (isTraceEnabled) log.trace(this + " already stopped");
+ return;
+ }
+ stopped = true;
+ }
+
// loop through and notify for all clients
- Collection clientHoldersCol = requestPayload.values();
+ Collection clientHoldersCol = localRequestPayload.values();
if (clientHoldersCol != null && clientHoldersCol.size() > 0)
{
Iterator itr = clientHoldersCol.iterator();
@@ -179,7 +291,7 @@
notifier.connectionTerminated(locatorURL, clientHolder.getSessionId(), clientHolder.getConfig());
if(isTraceEnabled)
{
- log.trace("Notified connection listener of lease termination due to disconnect from client (client session id = " + clientHolder.getSessionId());
+ log.trace(this + " Notified connection lif (isTraceEnabled) log.tracef lease termination due to disconnect from client (client session id = " + clientHolder.getSessionId());
}
}
}
@@ -188,17 +300,32 @@
}
else
{
- log.warn("Tried to terminate lease for session id " + sessionId + ", but no collection of clients have been set.");
+ log.warn(this + " Tried to terminate lease for session id " + sessionId + ", but no collection of clients have been set.");
}
}
private void notifyClientLost()
{
- // is not for a particular client (but all clients associated with client invoker), so need to inspect request payload for client
- if (requestPayload != null)
+ Map localRequestPayload = null;
+ synchronized (lock)
{
+ if (stopped)
+ {
+ if (isTraceEnabled) log.trace(this + " already stopped");
+ return;
+ }
+ stopped = true;
+ if (requestPayload != null)
+ {
+ localRequestPayload = new HashMap(requestPayload);
+ }
+ }
+
+ if (localRequestPayload != null)
+ {
// loop through and notify for all clients
- Collection clientHoldersCol = requestPayload.values();
+ Collection clientHoldersCol = localRequestPayload.values();
+ if (isTraceEnabled) log.trace(this + " notifying listeners about " + clientHoldersCol.size() + " expired client(s)");
if (clientHoldersCol != null && clientHoldersCol.size() > 0)
{
Iterator itr = clientHoldersCol.iterator();
@@ -211,7 +338,7 @@
notifier.connectionLost(locatorURL, clientHolder.getSessionId(), clientHolder.getConfig());
if(isTraceEnabled)
{
- log.trace("Notified connection listener of lease expired due to lost connection from client (client session id = " + clientHolder.getSessionId());
+ log.trace(this + " Notified connection listener of lease expired due to lost connection from client (client session id = " + clientHolder.getSessionId());
}
}
}
@@ -219,16 +346,43 @@
}
else
{
- log.debug("requestPayload == null, calling ConnectionNotifier.connectionTerminated()");
- notifier.connectionTerminated(locatorURL, clientSessionId, null);
+ if (isTraceEnabled) log.trace(this + " requestPayload == null, calling ConnectionNotifier.connectionLost()");
+ notifier.connectionLost(locatorURL, clientSessionId, null);
}
}
+ protected String getLeasePingerId()
+ {
+ return leasePingerId;
+ }
+
private void stopLease()
{
leaseTimerTask.cancel();
}
+ private void doUpdate(Map requestMap)
+ {
+ this.requestPayload = (Map)requestMap.get(ClientHolder.CLIENT_HOLDER_KEY);
+ if (isTraceEnabled)
+ {
+ log.trace(this + " updating: new Client list:");
+ Collection clientHoldersCol = requestPayload.values();
+ Iterator itr = clientHoldersCol.iterator();
+ while (itr.hasNext())
+ {
+ Object val = itr.next();
+ if (val != null && val instanceof ClientHolder)
+ {
+ ClientHolder clientHolder = (ClientHolder) val;
+ log.trace(leasePingerId + ": " + clientHolder.getSessionId());
+ }
+ }
+ }
+ updateLease(leasePeriod);
+ }
+
+
private class LeaseTimerTask extends TimerTask
{
@@ -245,14 +399,14 @@
{
try
{
- if (log.isTraceEnabled()) log.trace("did not receive ping: " + clientSessionId);
+ if (isTraceEnabled) log.trace(Lease.this + " did not receive ping: " + clientSessionId);
stopLease();
notifyClientLost();
if (clientLeases != null)
{
clientLeases.remove(clientSessionId);
}
- if (log.isTraceEnabled()) log.trace("removed lease:" + clientSessionId);
+ if (isTraceEnabled) log.trace(Lease.this + " removed lease:" + clientSessionId);
}
catch (Throwable thr)
{
14 years, 11 months