JBoss Remoting SVN: r5176 - in remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http: headers and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-10 02:37:20 -0400 (Sun, 10 May 2009)
New Revision: 5176
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/headers/
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/headers/ResponseCodeTestCase.java
Log:
JBREM-1079: New unit test.
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/headers/ResponseCodeTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/headers/ResponseCodeTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/http/headers/ResponseCodeTestCase.java 2009-05-10 06:37:20 UTC (rev 5176)
@@ -0,0 +1,214 @@
+/*
+* 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.headers;
+
+import java.net.InetAddress;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+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.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.http.HTTPMetadataConstants;
+
+/**
+ * Unit test for JBREM-728.
+ *
+ * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
+ * <p>
+ * Copyright (c) November 24, 2007
+ * </p>
+ *
+ */
+public class ResponseCodeTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(ResponseCodeTestCase.class);
+
+ private static boolean firstTime = true;
+
+ protected static String RESPONSE_KEY = "responseKey";
+ protected static String RESPONSE_VALUE = "responseValue";
+ protected static String RETURN_RESPONSE_HEADER = "returnResponseHeader";
+
+ 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.TRACE);
+ 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 testResponseHeaders() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator1 = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator1, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ HashMap metadata = new HashMap();
+ assertEquals(RETURN_RESPONSE_HEADER, client.invoke(RETURN_RESPONSE_HEADER, metadata));
+ log.info("connection is good");
+ log.info("metadata: " + metadata);
+ log.info("metadata type: " + metadata.getClass());
+
+ // Verify that all entries in the HTTPMetadataConstants.RESPONSE_HEADERS value
+ // also appear in metadata map.
+ Object o = metadata.remove(HTTPMetadataConstants.RESPONSE_HEADERS);
+ assertTrue(o instanceof Map);
+ Map responseHeaders = (Map) o;
+ Set responseHeadersEntries = responseHeaders.entrySet();
+ Set metadataEntries = metadata.entrySet();
+
+ Iterator it = responseHeadersEntries.iterator();
+ while (it.hasNext())
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ log.info("entry: " + entry);
+ if (entry.getKey() == null)
+ continue;
+ assertTrue("metadata does not contain entry " + entry, metadataEntries.contains(entry));
+ }
+
+ // Verify response map entry generated in invocation handler
+ // was added as a response header.
+ assertTrue(responseHeaders.keySet().contains(RESPONSE_KEY));
+ assertTrue(responseHeaders.get(RESPONSE_KEY) instanceof Collection);
+ List responses = (List) responseHeaders.get(RESPONSE_KEY);
+ assertTrue(responses.size() == 1);
+ assertEquals(RESPONSE_VALUE, responses.get(0));
+
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "http";
+ }
+
+
+ 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
+ {
+ if (RETURN_RESPONSE_HEADER.equals(invocation.getParameter()))
+ invocation.getReturnPayload().put(RESPONSE_KEY, RESPONSE_VALUE);
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback");
+ }
+ }
+}
\ No newline at end of file
14 years, 12 months
JBoss Remoting SVN: r5175 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-10 02:36:44 -0400 (Sun, 10 May 2009)
New Revision: 5175
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/LeaseIdentityTestCase.java
Log:
JBREM-1129: New unit tests.
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/LeaseIdentityTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/LeaseIdentityTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/LeaseIdentityTestCase.java 2009-05-10 06:36:44 UTC (rev 5175)
@@ -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-1128.
+ *
+ * @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, 12 months
JBoss Remoting SVN: r5174 - in remoting2/branches/2.2/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-10 02:36:03 -0400 (Sun, 10 May 2009)
New Revision: 5174
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/ConnectionIdentityTestCase.java
Log:
JBREM-1128: New unit tests.
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/ConnectionIdentityTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/ConnectionIdentityTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/connection/identity/ConnectionIdentityTestCase.java 2009-05-10 06:36:03 UTC (rev 5174)
@@ -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-1128.
+ *
+ * @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, 12 months
JBoss Remoting SVN: r5173 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-10 01:52:57 -0400 (Sun, 10 May 2009)
New Revision: 5173
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/ServerInvoker.java
Log:
JBREM-1128: Adopted use of leasePingerId.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/ServerInvoker.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/ServerInvoker.java 2009-05-10 05:48:27 UTC (rev 5172)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/ServerInvoker.java 2009-05-10 05:52:57 UTC (rev 5173)
@@ -262,6 +262,8 @@
protected ServerSocketFactory serverSocketFactory = null;
protected boolean registerCallbackListeners = true;
+
+ protected boolean useClientConnectionIdentity;
// Constructors ---------------------------------------------------------------------------------
@@ -318,6 +320,11 @@
{
return timeout;
}
+
+ public ConnectionNotifier getConnectionNotifier()
+ {
+ return connectionNotifier;
+ }
public boolean isLeaseActivated()
{
@@ -702,6 +709,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;
@@ -1156,6 +1173,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)
@@ -1477,6 +1501,10 @@
if (registerCallbackListeners)
{
connectionNotifier.addListenerFirst(callbackHandler);
+ if(leasePeriod > 0)
+ {
+ leaseManagement = true;
+ }
}
handler.addListener(callbackHandler);
}
@@ -1500,7 +1528,10 @@
"registered. Please add via xml configuration or via the Connector's " +
"addInvocationHandler() method.");
}
-
+ if (registerCallbackListeners)
+ {
+ connectionNotifier.removeListener(callbackHandler);
+ }
handler.removeListener(callbackHandler);
if(trace) { log.trace("ServerInvoker (" + this + ") removing server callback handler " + callbackHandler + "."); }
@@ -1703,6 +1734,7 @@
{
if (invocation != null)
{
+ // clientSessionId == MicroRemoteClientInvoker.invokerSessionID.
String clientSessionId = invocation.getSessionId();
Lease clientLease = (Lease)clientLeases.get(clientSessionId);
@@ -1738,7 +1770,7 @@
else
{
String type = "invoker";
- Map reqMap = invocation.getRequestPayload();
+ Map reqMap = invocation.getRequestPayload();
if (reqMap != null)
{
Object holderObj = reqMap.get(ClientHolder.CLIENT_HOLDER_KEY);
@@ -1747,8 +1779,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.");
}
}
}
@@ -1760,7 +1793,7 @@
String clientSessionId = invocation.getSessionId();
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)
@@ -1773,15 +1806,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 + ")"); }
+ }
}
}
}
@@ -1791,7 +1857,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)
14 years, 12 months
JBoss Remoting SVN: r5172 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-10 01:48:27 -0400 (Sun, 10 May 2009)
New Revision: 5172
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/Remoting.java
Log:
JBREM-1128: Added "useClientConnectionIdentity".
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/Remoting.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/Remoting.java 2009-05-10 05:46:17 UTC (rev 5171)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/Remoting.java 2009-05-10 05:48:27 UTC (rev 5172)
@@ -82,4 +82,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, 12 months
JBoss Remoting SVN: r5171 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-10 01:46:17 -0400 (Sun, 10 May 2009)
New Revision: 5171
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
Log:
JBREM-1128: (1) Adopted use of leasePingerId; (2) establishLease() can call Client.addConnectionListener().
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2009-05-10 05:40:51 UTC (rev 5170)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2009-05-10 05:46:17 UTC (rev 5171)
@@ -337,14 +337,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.
@@ -354,16 +366,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();
@@ -376,6 +391,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);
}
}
@@ -395,6 +415,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
@@ -402,55 +438,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);
- 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);
}
}
}
@@ -580,4 +629,11 @@
super.finalize();
}
+ protected LeasePinger getLeasePinger()
+ {
+ synchronized(clientLeaseLock)
+ {
+ return leasePinger;
+ }
+ }
}
14 years, 12 months
JBoss Remoting SVN: r5170 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-10 01:40:51 -0400 (Sun, 10 May 2009)
New Revision: 5170
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/LeasePinger.java
Log:
(1) JBREM-1128: Adopted use of leasePingerId; (2) JBREM-1129: adopted use of time stamp.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/LeasePinger.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/LeasePinger.java 2009-05-10 05:36:45 UTC (rev 5169)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/LeasePinger.java 2009-05-10 05:40:51 UTC (rev 5170)
@@ -25,6 +25,9 @@
public static final long DEFAULT_LEASE_PERIOD = 5000;
public static final int DEFAULT_DISCONNECT_TIMEOUT = -1;
+
+ static final String LEASE_PINGER_ID = "leasePingerId";
+ static final String TIME_STAMP = "timeStamp";
// Static ---------------------------------------------------------------------------------------
@@ -39,11 +42,15 @@
private ClientInvoker invoker = null;
private String invokerSessionID = null;
+ private Map clientSessionIds = new ConcurrentHashMap();
private Map clients = new ConcurrentHashMap();
private TimerTask timerTask = null;
private long pingPeriod = -1;
private int disconnectTimeout = DEFAULT_DISCONNECT_TIMEOUT;
+
+ private String leasePingerId;
+ private boolean useClientConnectionIdentity;
// Constructors ---------------------------------------------------------------------------------
@@ -84,6 +91,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
@@ -91,7 +110,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)
@@ -110,6 +129,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");
+ }
+ }
}
}
@@ -122,8 +160,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();
@@ -148,7 +195,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)
{
@@ -176,14 +225,20 @@
log.warn(this + " failed sending disconnect for client lease for " +
"client with session ID " + sessionID);
}
+
+ clientSessionIds.remove(sessionID);
+ if (useClientConnectionIdentity)
+ {
+ clients.remove(sessionID);
+ }
}
else
{
- log.warn(this + " tried to remove lease for client with session ID " + sessionID +
- ", but no such lease was found");
+ log.debug(this + " tried to remove lease for client with session ID " + sessionID +
+ ", 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"); }
@@ -195,7 +250,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();
@@ -231,7 +286,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;
}
@@ -243,7 +298,7 @@
public String toString()
{
- return "LeasePinger[" + invoker + "(" + invokerSessionID + ")]";
+ return "LeasePinger[" + leasePingerId + ":" + invoker + "(" + invokerSessionID + ")]";
}
// Package protected ----------------------------------------------------------------------------
@@ -259,9 +314,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()
@@ -271,9 +346,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');
@@ -284,13 +359,13 @@
"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);
-
- InvocationRequest ir =
- new InvocationRequest(invokerSessionID, null, "$PING$", requestClients, null, null);
-
+ requestClients.put(LeasePinger.LEASE_PINGER_ID, leasePingerId);
+ requestClients.put(TIME_STAMP, Long.toString(System.currentTimeMillis()));
+
+ InvocationRequest ir = new InvocationRequest(invokerSessionID, null, "$PING$", requestClients, null, null);
invoker.invoke(ir);
if(trace) { log.trace(this + " successfully pinged the server"); }
14 years, 12 months
JBoss Remoting SVN: r5169 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-10 01:36:45 -0400 (Sun, 10 May 2009)
New Revision: 5169
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/Lease.java
Log:
(1) JBREM-1128: Adopted use of leasePingerId; (2) JBREM-1129: adopted use of time stamp.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/Lease.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/Lease.java 2009-05-10 05:23:37 UTC (rev 5168)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/Lease.java 2009-05-10 05:36:45 UTC (rev 5169)
@@ -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,12 @@
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 static final Logger log = Logger.getLogger(Lease.class);
private static final boolean isTraceEnabled = log.isTraceEnabled();
@@ -64,6 +69,11 @@
if(requestPayload != null)
{
this.requestPayload = (Map)requestPayload.get(ClientHolder.CLIENT_HOLDER_KEY);
+ this.leasePingerId = (String) requestPayload.get(LeasePinger.LEASE_PINGER_ID);
+ this.lastUpdate = Long.valueOf((String) requestPayload.get(LeasePinger.TIME_STAMP)).longValue();
+ 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 +94,46 @@
{
if(requestMap != null)
{
- this.requestPayload = (Map)requestMap.get(ClientHolder.CLIENT_HOLDER_KEY);
+ if (isTraceEnabled) log.trace(this + " requestMap: " + requestMap);
+ long time = 0;
+ String timeString = (String) requestMap.get(LeasePinger.TIME_STAMP);
+ if (isTraceEnabled) log.trace(this + " timeString: " + timeString);
+ time = Long.valueOf(timeString).longValue();
+ if (isTraceEnabled) log.trace(this + " last update: " + lastUpdate + ", this update: " + time);
+
+ if (time > lastUpdate)
+ {
+ synchronized (lock)
+ {
+ 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;
+ if (isTraceEnabled) log.trace(leasePingerId + ": " + clientHolder.getSessionId());
+ }
+ }
+
+ lastUpdate = time;
+ updateLease(leasePeriod);
+ }
+ }
+ else
+ {
+ if (isTraceEnabled) log.trace(this + " updating lease but not client list");
+ leaseUpdated = true;
+ }
}
- updateLease(leasePeriod);
+ else
+ {
+ if (isTraceEnabled) log.trace(this + " requestPayload == null");
+ }
}
public void updateLease(long leasePeriod)
@@ -124,13 +171,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 +188,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 +295,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 +304,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 +342,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,11 +350,16 @@
}
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();
@@ -245,14 +381,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, 12 months
JBoss Remoting SVN: r5168 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-10 01:23:37 -0400 (Sun, 10 May 2009)
New Revision: 5168
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionValidator.java
Log:
JBREM-1128: Various changes to implement connection identity.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionValidator.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionValidator.java 2009-05-10 05:16:51 UTC (rev 5167)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionValidator.java 2009-05-10 05:23:37 UTC (rev 5168)
@@ -22,11 +22,11 @@
package org.jboss.remoting;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
-import java.util.ListIterator;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
@@ -117,7 +117,7 @@
}
catch (Throwable throwable)
{
- log.debug("ConnectionValidator to connect to server " +
+ log.debug("ConnectionValidator unable to connect to server " +
innerClientInvoker.getLocator().getProtocol() + "://" +
innerClientInvoker.getLocator().getHost() + ":" +
innerClientInvoker.getLocator().getPort(), throwable);
@@ -227,12 +227,13 @@
private Map metadata;
private InvokerLocator locator;
private Map configMap;
- private List listeners;
+ private Map listeners;
private ClientInvoker clientInvoker;
private Object lock = new Object();
private Object notificationLock = new Object();
private boolean started;
private volatile boolean stopped;
+ private volatile boolean stopping;
private String invokerSessionId;
private boolean tieToLease = true;
private boolean stopLeaseOnFailure = true;
@@ -240,6 +241,9 @@
private int failureDisconnectTimeout = -1;
private boolean isValid;
private Timer timer;
+ private MicroRemoteClientInvoker sharedInvoker;
+ private LeasePinger leasePinger;
+ private boolean useClientConnectionIdentity;
// Constructors ---------------------------------------------------------------------------------
@@ -251,9 +255,10 @@
public ConnectionValidator(Client client, long pingPeriod)
{
this.client = client;
+ this.locator = client.getInvoker().getLocator();
this.pingPeriod = pingPeriod;
pingTimeout = DEFAULT_PING_TIMEOUT_INT;
- listeners = new ArrayList();
+ listeners = new HashMap();
stopped = false;
getParameters(client, new HashMap());
log.debug(this + " created");
@@ -262,9 +267,10 @@
public ConnectionValidator(Client client, Map metadata)
{
this.client = client;
+ this.locator = client.getInvoker().getLocator();
pingPeriod = DEFAULT_PING_PERIOD;
pingTimeout = DEFAULT_PING_TIMEOUT_INT;
- listeners = new ArrayList();
+ listeners = new HashMap();
stopped = false;
this.metadata = new HashMap(metadata);
getParameters(client, metadata);
@@ -300,7 +306,7 @@
".addConnectionListener() instead.");
}
- if (stopped)
+ if (stopping)
{
return;
}
@@ -321,7 +327,7 @@
try
{
- if(!stopped)
+ if(!stopping)
{
isValid = false;
@@ -366,41 +372,84 @@
// Public ---------------------------------------------------------------------------------------
- public void addConnectionListener(ConnectionListener listener)
+ public boolean addConnectionListener(Client client, ConnectionListener listener)
{
+ boolean doStart = false;
if (listener != null)
{
synchronized (lock)
{
+ if (stopping)
+ {
+ if (trace) log.trace(this + " is stopped. Cannot add ConnectionListener: " + listener + " for " + client);
+ return false;
+ }
if (listeners.size() == 0)
{
- start();
+ doStart = true;
}
- listeners.add(listener);
+ Set s = (Set) listeners.get(listener);
+ if (s == null)
+ {
+ s = new HashSet();
+ }
+ s.add(client);
+ listeners.put(listener, s);
+ log.debug(this + " added ConnectionListener: " + listener + " for " + client);
}
+ if (doStart)
+ {
+ start();
+ }
}
+
+ return true;
}
- public boolean removeConnectionListener(ConnectionListener listener)
+ public boolean removeConnectionListener(Client client, ConnectionListener listener)
{
- boolean isRemoved = false;
- if (listener != null)
+ if (listener == null)
{
- synchronized (lock)
+ if (trace) log.trace(this + " ConnectionListener is null");
+ return false;
+ }
+ synchronized (lock)
+ {
+ if (stopping)
{
- isRemoved = listeners.remove(listener);
- if (listeners.size() == 0)
- {
- stop();
- }
+ if (trace) log.trace(this + " is stopped. It's too late to remove " + listener);
+ return false;
}
+ Set s = (Set) listeners.get(listener);
+ if (s == null)
+ {
+ log.debug(this + ": " + listener + " is not registered");
+ return false;
+ }
+ if (s.remove(client))
+ {
+ log.debug(this + " removed ConnectionListener: " + listener + " for " + client);
+ }
+ else
+ {
+ log.debug(this + ": " + listener + " is not registered for " + client);
+ return false;
+ }
+ if (s.size() == 0)
+ {
+ listeners.remove(listener);
+ }
+ if (listeners.size() == 0)
+ {
+ stop();
+ }
}
- return isRemoved;
+ return true;
}
public long getPingPeriod()
{
- if (stopped)
+ if (stopping)
{
return -1;
}
@@ -412,9 +461,52 @@
{
return "ConnectionValidator[" + Integer.toHexString(System.identityHashCode(this)) + ":" + clientInvoker + ", pingPeriod=" + pingPeriod + " ms]";
}
+
+ public boolean isStopped()
+ {
+ return stopped;
+ }
// Package protected ----------------------------------------------------------------------------
+ void notifyListeners(Throwable thr)
+ {
+ final Throwable t = thr;
+ synchronized (lock)
+ {
+ if (stopping)
+ {
+ return;
+ }
+ stopping = true;
+ if (trace) log.trace(this + " is stopped. No more listeners will be accepted.");
+
+ Iterator itr = listeners.keySet().iterator();
+ while (itr.hasNext())
+ {
+ final ConnectionListener listener = (ConnectionListener) itr.next();
+ Set clients = (Set) listeners.get(listener);
+ Iterator itr2 = clients.iterator();
+ while (itr2.hasNext())
+ {
+ final Client client = (Client) itr2.next();
+ new Thread()
+ {
+ public void run()
+ {
+ log.debug(ConnectionValidator.this + " calling " + listener + ".handleConnectionException() for " + client);
+ listener.handleConnectionException(t, client);
+ }
+ }.start();
+ }
+ }
+
+ listeners.clear();
+ }
+
+ stop();
+ }
+
// Protected ------------------------------------------------------------------------------------
// Private --------------------------------------------------------------------------------------
@@ -431,12 +523,21 @@
ClientInvoker clientInvoker = client.getInvoker();
if (clientInvoker instanceof MicroRemoteClientInvoker)
{
- invokerSessionId = ((MicroRemoteClientInvoker) clientInvoker).getSessionId();
+ sharedInvoker = (MicroRemoteClientInvoker) clientInvoker;
+ invokerSessionId = sharedInvoker.getSessionId();
}
else
{
throw new RuntimeException("creating a ConnectionValidator on a local connection");
}
+ if (stopLeaseOnFailure)
+ {
+ if (sharedInvoker != null)
+ {
+ leasePinger = sharedInvoker.getLeasePinger();
+ }
+ }
+ if (trace) log.trace(this + ": sharedInvoker = " + sharedInvoker + ", leasePinger = " + leasePinger);
}
private boolean checkUseParametersFromLocator(Client client, Map metadata)
@@ -458,31 +559,37 @@
" in InvokerLocator to a boolean: must be a String");
}
}
- o = client.getConfiguration().get(Client.USE_ALL_PARAMS);
- if (o != null)
+ if (client.getConfiguration() != null)
{
- if (o instanceof String)
+ o = client.getConfiguration().get(Client.USE_ALL_PARAMS);
+ if (o != null)
{
- return Boolean.valueOf(((String) o)).booleanValue();
+ if (o instanceof String)
+ {
+ return Boolean.valueOf(((String) o)).booleanValue();
+ }
+ else
+ {
+ log.warn(this + " could not convert " + Client.USE_ALL_PARAMS + " value" +
+ " in Client configuration map to a boolean: must be a String");
+ }
}
- else
- {
- log.warn(this + " could not convert " + Client.USE_ALL_PARAMS + " value" +
- " in Client configuration map to a boolean: must be a String");
- }
}
- o = metadata.get(Client.USE_ALL_PARAMS);
- if (o != null)
+ if (metadata != null)
{
- if (o instanceof String)
+ o = metadata.get(Client.USE_ALL_PARAMS);
+ if (o != null)
{
- return Boolean.valueOf(((String) o)).booleanValue();
+ if (o instanceof String)
+ {
+ return Boolean.valueOf(((String) o)).booleanValue();
+ }
+ else
+ {
+ log.warn(this + " could not convert " + Client.USE_ALL_PARAMS + " value" +
+ " in metadata map to a boolean: must be a String");
+ }
}
- else
- {
- log.warn(this + " could not convert " + Client.USE_ALL_PARAMS + " value" +
- " in metadata map to a boolean: must be a String");
- }
}
return false;
}
@@ -578,8 +685,17 @@
" to a boolean: must be a String");
}
}
-
+ ClientInvoker invoker = client.getInvoker();
+ if (invoker == null)
+ {
+ if (trace) log.trace(this + " client invoker == null");
+ }
+ else
+ {
+ if (trace) log.trace(this + " InvokerLocator: " + invoker.getLocator());
+ }
o = config.get(FAILURE_DISCONNECT_TIMEOUT);
+ if (trace) log.trace(this + " \"failureDisconnectTimeout\" set to " + o);
if (o != null)
{
if (o instanceof String)
@@ -587,6 +703,7 @@
try
{
failureDisconnectTimeout = Integer.valueOf(((String) o)).intValue();
+ if (trace) log.trace(this + " setting failureDisconnectTimeout to " + failureDisconnectTimeout);
}
catch (Exception e)
{
@@ -600,6 +717,27 @@
" to an int: must be a String");
}
}
+ o = config.get(Remoting.USE_CLIENT_CONNECTION_IDENTITY);
+ if (o != null)
+ {
+ if (o instanceof String)
+ {
+ try
+ {
+ useClientConnectionIdentity = Boolean.valueOf(((String) o)).booleanValue();
+ }
+ catch (Exception e)
+ {
+ log.warn(this + " could not convert " + Remoting.USE_CLIENT_CONNECTION_IDENTITY + " value" +
+ " to a boolean: " + o);
+ }
+ }
+ else
+ {
+ log.warn(this + " could not convert " + Remoting.USE_CLIENT_CONNECTION_IDENTITY + " value" +
+ " to a boolean: must be a String");
+ }
+ }
}
}
@@ -628,7 +766,14 @@
clientInvoker.connect();
}
- TimerUtil.schedule(this, pingPeriod);
+ try
+ {
+ TimerUtil.schedule(this, pingPeriod);
+ }
+ catch (Exception e)
+ {
+ log.error(this + " unable to schedule on TimerUtil", e);
+ }
started = true;
timer = new Timer(true);
log.debug(this + " started");
@@ -696,6 +841,7 @@
private boolean doStop()
{
+ if (trace) log.trace("entering doStop()");
synchronized(lock)
{
if (stopped)
@@ -707,6 +853,7 @@
{
listeners.clear();
}
+ stopping = true;
stopped = true;
timer = null;
}
@@ -723,33 +870,6 @@
return result;
}
- private void notifyListeners(Throwable thr)
- {
- final Throwable t = thr;
- synchronized (lock)
- {
- if (stopped)
- {
- return;
- }
- ListIterator itr = listeners.listIterator();
- while (itr.hasNext())
- {
- final ConnectionListener listener = (ConnectionListener) itr.next();
- new Thread()
- {
- public void run()
- {
- log.debug(this + " calling " + listener + ".handleConnectionException()");
- listener.handleConnectionException(t, client);
- }
- }.start();
- }
- }
- stop();
- listeners.clear();
- }
-
// Inner classes --------------------------------------------------------------------------------
private class WaitOnConnectionCheckTimerTask extends TimerTask
@@ -783,27 +903,30 @@
if (!isValid)
{
log.debug(ConnectionValidator.this + "'s connection is invalid");
-
- notifyListeners(new Exception("Could not connect to server!"));
+ ConnectionValidator.super.cancel();
if (stopLeaseOnFailure)
{
- log.debug(this + " detected connection failure: stopping LeasePinger");
- MicroRemoteClientInvoker invoker = (MicroRemoteClientInvoker) client.getInvoker();
-
- if (invoker != null)
+ if (trace) log.trace(ConnectionValidator.this + " detected connection failure: stopping LeasePinger");
+ if (leasePinger != null)
{
+ log.debug(ConnectionValidator.this + " shutting down lease pinger: " + leasePinger);
int disconnectTimeout = (failureDisconnectTimeout == -1) ? client.getDisconnectTimeout() : failureDisconnectTimeout;
- invoker.terminateLease(null, disconnectTimeout);
- log.debug(ConnectionValidator.this + " shut down lease pinger");
+ if (trace) log.trace(ConnectionValidator.this + " disconnectTimeout: " + disconnectTimeout);
+ sharedInvoker.terminateLease(null, disconnectTimeout, leasePinger);
}
else
{
- log.debug(ConnectionValidator.this + " unable to shut down lease pinger: client must have shut down");
+ if (trace) log.trace(ConnectionValidator.this + ": lease pinger == null: perhaps leasing is not enabled for this connection");
+ notifyListeners(new Exception("Could not connect to server!"));
}
cancel();
}
+ if (!useClientConnectionIdentity)
+ {
+ notifyListeners(new Exception("Could not connect to server!"));
+ }
}
}
}
14 years, 12 months
JBoss Remoting SVN: r5167 - remoting2/branches/2.2/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-10 01:16:51 -0400 (Sun, 10 May 2009)
New Revision: 5167
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionNotifier.java
Log:
JBREM-1128: Improved logging.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionNotifier.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionNotifier.java 2009-05-10 05:15:12 UTC (rev 5166)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/ConnectionNotifier.java 2009-05-10 05:16:51 UTC (rev 5167)
@@ -43,7 +43,7 @@
{
try
{
- log.debug("Server connection lost to client (session id = " + clientSessionId);
+ log.debug(this + " Server connection lost to client (session id = " + clientSessionId);
Client client = new Client(new InvokerLocator(locatorurl), requestPayload);
client.setSessionId(clientSessionId);
@@ -56,7 +56,9 @@
Iterator it = localListeners.iterator();
while (it.hasNext())
{
- ((ConnectionListener) it.next()).handleConnectionException(null, client);
+ ConnectionListener listener = (ConnectionListener) it.next();
+ listener.handleConnectionException(null, client);
+ log.debug(this + " notified " + listener + " of connection lost to: " + clientSessionId);
}
}
catch(Exception e)
@@ -71,7 +73,7 @@
{
if(log.isTraceEnabled())
{
- log.trace("Client disconnected (session id = " + clientSessionId);
+ log.trace(this + ": Client disconnected (session id = " + clientSessionId);
}
Client client = new Client(new InvokerLocator(locatorURL), requestPayload);
client.setSessionId(clientSessionId);
14 years, 12 months