JBoss Remoting SVN: r5166 - 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:15:12 -0400 (Sun, 10 May 2009)
New Revision: 5166
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java
Log:
JBREM-1128: Various changes to implement connection identity.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java 2009-05-08 18:12:22 UTC (rev 5165)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/Client.java 2009-05-10 05:15:12 UTC (rev 5166)
@@ -49,6 +49,7 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.StreamCorruptedException;
+import java.lang.ref.WeakReference;
import java.net.InetAddress;
import java.net.SocketTimeoutException;
import java.rmi.MarshalException;
@@ -158,7 +159,14 @@
*/
public static final String USE_ALL_PARAMS = "useAllParams";
+ private static Map connectionValidators = new HashMap();
+ private static Object connectionValidatorLock = new Object();
+
+ static final String CLIENT = "client";
+ static final String CONNECTION_LISTENER = "connectionListener";
+
private static final Logger log = Logger.getLogger(Client.class);
+ private static boolean trace = log.isTraceEnabled();
private static final long serialVersionUID = 5679279425009837934L;
@@ -180,6 +188,7 @@
private InvokerLocator locator;
private ConnectionValidator connectionValidator = null;
+ private ConnectionValidatorKey connectionValidatorKey;
private Map configuration = new HashMap();
private Map callbackConnectors = new HashMap();
@@ -192,6 +201,10 @@
private int disconnectTimeout = DEFAULT_DISCONNECT_TIMEOUT;
private boolean connected = false;
+
+ private Set connectionListeners = new HashSet();
+
+ private boolean useClientConnectionIdentity;
// Constructors ---------------------------------------------------------------------------------
@@ -269,6 +282,27 @@
if (configuration != null)
{
this.configuration = new HashMap(configuration);
+ 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);
+ }
+ else
+ {
+ if (locator.getParameters() != null)
+ {
+ o = locator.getParameters().get(Remoting.USE_CLIENT_CONNECTION_IDENTITY);
+ if (o != null)
+ {
+ useClientConnectionIdentity = Boolean.valueOf((String) o).booleanValue();
+ this.configuration.put(Remoting.USE_CLIENT_CONNECTION_IDENTITY, o);
+ }
+ }
+ }
}
this.sessionId = new GUID().toString();
}
@@ -379,7 +413,7 @@
if (invoker == null)
{
throw new RuntimeException("Can not add connection listener to remoting client " +
- "until client has been connected.");
+ "while client is not connected.");
}
else
{
@@ -390,11 +424,56 @@
}
}
- if (connectionValidator == null)
+ synchronized (connectionValidatorLock)
{
- connectionValidator = new ConnectionValidator(this, metadata);
+ if (connectionValidator == null)
+ {
+ Map map = new HashMap(configuration);
+ map.putAll(metadata);
+ connectionValidatorKey = new ConnectionValidatorKey(invoker, map);
+ WeakReference ref = (WeakReference) connectionValidators.get(connectionValidatorKey);
+ if (ref == null)
+ {
+ connectionValidator = new ConnectionValidator(this, metadata);
+ connectionValidators.put(connectionValidatorKey, new WeakReference(connectionValidator));
+ connectionValidator.addConnectionListener(this, listener);
+ log.debug(this + ": created " + connectionValidator);
+ }
+ else
+ {
+ connectionValidator = (ConnectionValidator) ref.get();
+ if (connectionValidator.addConnectionListener(this, listener))
+ {
+ if (trace) log.trace(this + ": reusing from static table: " + connectionValidator);
+ }
+ else
+ {
+ if (trace) log.trace(this + ": unable to reuse existing ConnectionValidator in static map: " + connectionValidator);
+ connectionValidator = new ConnectionValidator(this, metadata);
+ connectionValidators.put(connectionValidatorKey, new WeakReference(connectionValidator));
+ connectionValidator.addConnectionListener(this, listener);
+ log.debug(this + ": current ConnectionValidator is stopped: created " + connectionValidator);
+ }
+ }
+ }
+ else
+ {
+ if (connectionValidator.addConnectionListener(this, listener))
+ {
+ if (trace) log.trace(this + ": reusing from local reference: " + connectionValidator);
+ }
+ else
+ {
+ if (trace) log.trace(this + ": unable to reuse ConnectionValidator from local reference: " + connectionValidator);
+ connectionValidator = new ConnectionValidator(this, metadata);
+ connectionValidators.put(connectionValidatorKey, new WeakReference(connectionValidator));
+ connectionValidator.addConnectionListener(this, listener);
+ if (trace) log.trace(this + ": current ConnectionValidator is stopped: created " + connectionValidator);
+ }
+ }
+
+ connectionListeners.add(listener);
}
- connectionValidator.addConnectionListener(listener);
}
/**
@@ -403,11 +482,36 @@
*/
public boolean removeConnectionListener(ConnectionListener listener)
{
- if (connectionValidator == null)
+ if (trace) log.trace(this + ".removeConnectionListener(" + listener + ")");
+ boolean isRemoved = false;
+ synchronized (connectionValidatorLock)
{
- return false;
+ if (connectionValidator == null)
+ {
+ return false;
+ }
+ isRemoved = connectionValidator.removeConnectionListener(this, listener);
+ if (connectionValidator.isStopped())
+ {
+ if (connectionValidators.remove(connectionValidatorKey) != null)
+ {
+ log.debug(this + ".removeConnectionListener() removed from static map: " + connectionValidator);
+ }
+ connectionValidator = null;
+ connectionValidatorKey = null;
+ }
+ connectionListeners.remove(listener);
+ if (connectionListeners.isEmpty())
+ {
+ connectionValidator = null;
+ connectionValidatorKey = null;
+ }
+ if (connectionValidator == null)
+ {
+ if (trace) log.trace(this + " set connectionValidator to null");
+ }
}
- return connectionValidator.removeConnectionListener(listener);
+ return isRemoved;
}
/**
@@ -453,6 +557,41 @@
*/
public void connect() throws Exception
{
+ connect(null, null);
+ }
+
+ /**
+ * Will cause the underlying transport to make connection to the target server. This is
+ * important for any stateful transports, like socket or multiplex. This is also when a client
+ * lease with the server is started. If listener is not null, it will be registered to
+ * receive a callback if the connection fails.
+ */
+ public void connect(ConnectionListener listener) throws Exception
+ {
+ connect(listener, null);
+ }
+
+ /**
+ * Will cause the underlying transport to make connection to the target server. This is
+ * important for any stateful transports, like socket or multiplex. This is also when a client
+ * lease with the server is started. If listener is not null, it will be registered to
+ * receive a callback if the connection fails.
+ * <p>
+ *
+ * If this version of connect() is used, and leasing is enabled, the concept of "connection
+ * identity" is enforced. That is, the ConnectionValidator used by this Client will be
+ * tied to the LeasePinger currently used by the MicroRemoteClientInvoker created or reused
+ * in this method, and that LeasePinger will be tied to this Client and its ConnectionValidator.
+ * If the ConnectionValidator used by any of the Clients associated with the MicroRemoteClientInvoker
+ * used by this Client detects a broken connection, it will shut down that LeasePinger.
+ * Moreover, each ConnectionValidator associated with that LeasePinger will notify its
+ * ConnectionListeners of the broken connection. At that point, the LeasePinger will be
+ * destroyed, and all of the associated Clients will be disconnected.
+ */
+ public void connect(ConnectionListener listener, Map metadata) throws Exception
+ {
+ log.debug(this + ".connect(" + listener + ")");
+
if (isConnected())
return;
@@ -471,7 +610,7 @@
invoker = InvokerRegistry.createClientInvoker(locator, configuration);
}
- connect(invoker);
+ connect(invoker, listener, metadata);
connected = true;
}
@@ -484,25 +623,44 @@
*/
public void disconnect()
{
+ if (trace) log.trace(this + " entering disconnect()");
+
+ connected = false;
+
if (invoker != null)
{
// this is a noop if no lease is active
invoker.terminateLease(sessionId, disconnectTimeout);
+
+ // Need to remove myself from registry so will not keep reference to me since I am of no
+ // use now. Will have to create a new one.
+ InvokerRegistry.destroyClientInvoker(invoker.getLocator(), configuration);
+ invoker = null;
+ }
+ synchronized (connectionValidatorLock)
+ {
if (connectionValidator != null)
{
- connectionValidator.stop();
+ Iterator it = connectionListeners.iterator();
+ while (it.hasNext())
+ {
+ ConnectionListener listener = (ConnectionListener) it.next();
+ connectionValidator.removeConnectionListener(this, listener);
+ }
+ if (connectionValidator.isStopped())
+ {
+ if (connectionValidators.remove(connectionValidatorKey) != null)
+ {
+ if (trace) log.trace(this + ".disconnect() removed from static map: " + connectionValidator);
+ }
+ }
+
connectionValidator = null;
+ connectionValidatorKey = null;
}
-
- // Need to remove myself from registry so will not keep reference to me since I am of no
- // use now. Will have to create a new one.
-
- InvokerRegistry.destroyClientInvoker(invoker.getLocator(), configuration);
- invoker = null;
}
-
- connected = false;
+ log.debug(this + " is disconnected");
}
/**
@@ -1183,7 +1341,7 @@
{
if (e.getCause() != null && e.getCause() instanceof SocketTimeoutException)
{
- if (log.isTraceEnabled()) log.trace(this + ": getCallbacks() timed out: returning empty list");
+ if (trace) log.trace(this + ": getCallbacks() timed out: returning empty list");
return new ArrayList();
}
throw e;
@@ -1517,23 +1675,61 @@
public String toString()
{
- return "Client[" + System.identityHashCode(this) + "]";
+ return "Client[" + System.identityHashCode(this) + ":" + sessionId + "]";
}
// Package protected ----------------------------------------------------------------------------
+ void notifyListeners()
+ {
+ synchronized (connectionValidatorLock)
+ {
+ log.debug(this + " entering notifyListeners(): " + connectionValidator);
+ if (connectionValidator != null)
+ {
+ synchronized (connectionValidator)
+ {
+ if (connectionValidator.isStopped())
+ {
+ if (trace) log.trace(this + ": " + connectionValidator + " is stopped");
+ }
+ else
+ {
+ if (trace) log.trace(this + ": " + connectionValidator + " is not stopped");
+ if (trace) log.trace(this + " calling connectionValidator.notifyListeners()");
+ connectionValidator.notifyListeners(new Exception("Could not connect to server!"));
+ Iterator it = connectionListeners.iterator();
+ while (it.hasNext())
+ {
+ ConnectionListener listener = (ConnectionListener) it.next();
+ connectionValidator.removeConnectionListener(this, listener);
+ }
+ if (connectionValidators.remove(connectionValidatorKey) != null)
+ {
+ if (trace) log.trace(this + ".notifyAndDisconnect() removed from static map: " + connectionValidator);
+ }
+ }
+ }
+ connectionValidator = null;
+ connectionValidatorKey = null;
+ }
+
+ log.debug(this + " leaving notifyListeners()");
+ }
+ }
+
// Protected ------------------------------------------------------------------------------------
// Private --------------------------------------------------------------------------------------
- private void connect(ClientInvoker invoker)
+ private void connect(ClientInvoker invoker, ConnectionListener listener, Map metadata)
{
if (invoker != null)
{
invoker.connect();
try
{
- setupClientLease(invoker);
+ setupClientLease(invoker, listener, metadata);
}
catch (Throwable throwable)
{
@@ -1542,6 +1738,7 @@
e.initCause(throwable);
throw e;
}
+ log.debug(this + " connected to " + locator);
}
else
{
@@ -1550,7 +1747,7 @@
}
}
- private void setupClientLease(ClientInvoker invoker) throws Throwable
+ private void setupClientLease(ClientInvoker invoker, ConnectionListener listener, Map metadata) throws Throwable
{
long leasePeriod = -1;
boolean enableLease = false;
@@ -1631,10 +1828,26 @@
}
}
+ if (trace) log.trace(this + " enableLease: " + enableLease);
if (enableLease)
{
- invoker.establishLease(sessionId, configuration, leasePeriod);
+ Map temp = new HashMap(configuration);
+ if (metadata != null)
+ {
+ temp.putAll(metadata);
+ }
+ if (useClientConnectionIdentity)
+ {
+ temp.put(CLIENT, this);
+ temp.put(CONNECTION_LISTENER, listener);
+ }
+ if (trace) log.trace(this + " calling MicroRemoteClientInvoker.establishLease()");
+ invoker.establishLease(sessionId, temp, leasePeriod);
}
+ else if (listener != null)
+ {
+ addConnectionListener(listener, metadata);
+ }
}
private Object invoke(Object param, Map metadata, InvokerLocator callbackServerLocator)
@@ -1731,4 +1944,32 @@
// Inner classes --------------------------------------------------------------------------------
+
+ static class ConnectionValidatorKey
+ {
+ private ClientInvoker invoker;
+ private Map metadata;
+
+ ConnectionValidatorKey(ClientInvoker invoker, Map metadata)
+ {
+ this.invoker = invoker;
+ this.metadata = metadata;
+ }
+
+ public boolean equals(Object o)
+ {
+ if (o == null)
+ return false;
+ if (! (o instanceof ConnectionValidatorKey))
+ return false;
+ ConnectionValidatorKey holder = (ConnectionValidatorKey) o;
+ boolean metadataEquals = (metadata == null && holder.metadata == null) || metadata.equals(holder.metadata);
+ return invoker == holder.invoker && metadataEquals;
+ }
+
+ public int hashCode()
+ {
+ return invoker.hashCode() * metadata.hashCode();
+ }
+ }
}
14 years, 11 months
JBoss Remoting SVN: r5165 - remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-08 14:12:22 -0400 (Fri, 08 May 2009)
New Revision: 5165
Modified:
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Version.java
Log:
JBREM-1128: Updated time stamp on version.
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Version.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Version.java 2009-05-08 18:11:36 UTC (rev 5164)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Version.java 2009-05-08 18:12:22 UTC (rev 5165)
@@ -34,7 +34,7 @@
public static final byte VERSION_2 = 2;
public static final byte VERSION_2_2 = 22;
- public static final String VERSION = "2.2.2.SP11_JBREM-1112:050709-00:43";
+ public static final String VERSION = "2.2.2.SP11_JBREM-1112:050809-14:10";
private static final byte byteVersion = VERSION_2_2;
private static byte defaultByteVersion = byteVersion;
private static boolean performVersioning = true;
14 years, 11 months
JBoss Remoting SVN: r5164 - remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-08 14:11:36 -0400 (Fri, 08 May 2009)
New Revision: 5164
Modified:
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/LeasePinger.java
Log:
JBREM-1128: Changed notifyAndDisconnect() to notifyListeners().
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/LeasePinger.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/LeasePinger.java 2009-05-08 18:10:57 UTC (rev 5163)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/LeasePinger.java 2009-05-08 18:11:36 UTC (rev 5164)
@@ -88,7 +88,7 @@
{
Client client = (Client) it.next();
log.debug(this + " calling " + client + ".notifyAndDisconnect()");
- client.notifyAndDisconnect();
+ client.notifyListeners();
it.remove();
}
}
14 years, 11 months
JBoss Remoting SVN: r5163 - remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-08 14:10:57 -0400 (Fri, 08 May 2009)
New Revision: 5163
Modified:
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Client.java
Log:
JBREM-1128: Changed synchronization, renamed notifyAndDisconnect() to notifyListeners(), and removed client invoker destruction from notifyListeners, all to fix a deadlock.
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Client.java 2009-05-08 08:10:00 UTC (rev 5162)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Client.java 2009-05-08 18:10:57 UTC (rev 5163)
@@ -285,6 +285,18 @@
{
log.warn("value of " + Remoting.USE_CLIENT_CONNECTION_IDENTITY + " must be a String: " + o);
}
+ else
+ {
+ if (locator.getParameters() != null)
+ {
+ o = locator.getParameters().get(Remoting.USE_CLIENT_CONNECTION_IDENTITY);
+ if (o != null)
+ {
+ useClientConnectionIdentity = Boolean.valueOf((String) o).booleanValue();
+ this.configuration.put(Remoting.USE_CLIENT_CONNECTION_IDENTITY, o);
+ }
+ }
+ }
}
this.sessionId = new GUID().toString();
}
@@ -389,7 +401,7 @@
*
* @see org.jboss.remoting.ConnectionValidator
*/
- public synchronized void addConnectionListener(ConnectionListener listener, Map metadata)
+ public void addConnectionListener(ConnectionListener listener, Map metadata)
{
if (invoker == null)
{
@@ -405,8 +417,8 @@
}
}
-// synchronized (connectionValidatorLock)
-// {
+ synchronized (connectionValidatorLock)
+ {
log.debug(this + " in addConnectionListener()");
if (connectionValidator == null)
{
@@ -455,18 +467,18 @@
}
connectionListeners.add(listener);
-// }
+ }
}
/**
* Removes specified connection listener. Will return true if it has already been registered,
* false otherwise.
*/
- public synchronized boolean removeConnectionListener(ConnectionListener listener)
+ public boolean removeConnectionListener(ConnectionListener listener)
{
log.debug(this + ".removeConnectionListener(" + listener + ")");
boolean isRemoved = false;
-// synchronized (connectionValidatorLock)
+ synchronized (connectionValidatorLock)
{
if (connectionValidator == null)
{
@@ -570,7 +582,7 @@
* ConnectionListeners of the broken connection. At that point, the LeasePinger will be
* destroyed, and all of the associated Clients will be disconnected.
*/
- public synchronized void connect(ConnectionListener listener, Map metadata) throws Exception
+ public void connect(ConnectionListener listener, Map metadata) throws Exception
{
log.debug(this + ".connect(" + listener + ")");
log.debug(this + ": metadata = " + metadata);
@@ -604,45 +616,46 @@
* remoting client. Otherwise resource will not be cleaned up and if the target server requires
* a lease, it will be maintained in the background.
*/
- public synchronized void disconnect()
+ public void disconnect()
{
log.debug(this + " entering disconnect()");
+
+ connected = false;
+
if (invoker != null)
{
// this is a noop if no lease is active
invoker.terminateLease(sessionId, disconnectTimeout);
+
+ // Need to remove myself from registry so will not keep reference to me since I am of no
+ // use now. Will have to create a new one.
+ InvokerRegistry.destroyClientInvoker(invoker.getLocator(), configuration);
+ invoker = null;
+ }
-// synchronized (connectionValidatorLock)
+ synchronized (connectionValidatorLock)
+ {
+ if (connectionValidator != null)
{
- if (connectionValidator != null)
+ Iterator it = connectionListeners.iterator();
+ while (it.hasNext())
{
- Iterator it = connectionListeners.iterator();
- while (it.hasNext())
+ ConnectionListener listener = (ConnectionListener) it.next();
+ connectionValidator.removeConnectionListener(this, listener);
+ }
+ if (connectionValidator.isStopped())
+ {
+ if (connectionValidators.remove(connectionValidatorKey) != null)
{
- ConnectionListener listener = (ConnectionListener) it.next();
- connectionValidator.removeConnectionListener(this, listener);
+ log.debug(this + ".disconnect() removed from static map: " + connectionValidator);
}
- if (connectionValidator.isStopped())
- {
- if (connectionValidators.remove(connectionValidatorKey) != null)
- {
- log.debug(this + ".disconnect() removed from static map: " + connectionValidator);
- }
- }
}
- // connectionValidator.stop();
+
connectionValidator = null;
connectionValidatorKey = null;
}
-
- // Need to remove myself from registry so will not keep reference to me since I am of no
- // use now. Will have to create a new one.
-
- InvokerRegistry.destroyClientInvoker(invoker.getLocator(), configuration);
- invoker = null;
}
- connected = false;
}
/**
@@ -1663,12 +1676,12 @@
// Package protected ----------------------------------------------------------------------------
- synchronized void notifyAndDisconnect()
+ void notifyListeners()
{
-// synchronized (connectionValidatorLock)
+ synchronized (connectionValidatorLock)
{
// disconnect();
- log.debug(this + " entering notifyAndDisconnect(): " + connectionValidator);
+ log.debug(this + " entering notifyListeners(): " + connectionValidator);
if (connectionValidator != null)
{
synchronized (connectionValidator)
@@ -1698,17 +1711,17 @@
connectionValidatorKey = null;
}
- if (invoker != null)
- {
- // Need to remove myself from registry so will not keep reference to me since I am of no
- // use now. Will have to create a new one.
+// if (invoker != null)
+// {
+// // Need to remove myself from registry so will not keep reference to me since I am of no
+// // use now. Will have to create a new one.
+//
+// InvokerRegistry.destroyClientInvoker(invoker.getLocator(), configuration);
+// invoker = null;
+// }
- InvokerRegistry.destroyClientInvoker(invoker.getLocator(), configuration);
- invoker = null;
- }
-
- connected = false;
- log.debug(this + " leaving notifyAndDisconnect()");
+// connected = false;
+ log.debug(this + " leaving notifyListeners()");
}
}
14 years, 11 months
JBoss Remoting SVN: r5162 - remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-08 04:10:00 -0400 (Fri, 08 May 2009)
New Revision: 5162
Modified:
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/LeasePinger.java
Log:
JBREM-1128: Fixed iteration through Clients in stopPing().
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/LeasePinger.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/LeasePinger.java 2009-05-08 07:00:27 UTC (rev 5161)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/LeasePinger.java 2009-05-08 08:10:00 UTC (rev 5162)
@@ -84,6 +84,7 @@
if (useClientConnectionIdentity)
{
Iterator it = clients.values().iterator();
+ while (it.hasNext())
{
Client client = (Client) it.next();
log.debug(this + " calling " + client + ".notifyAndDisconnect()");
14 years, 11 months
JBoss Remoting SVN: r5161 - remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-08 03:00:27 -0400 (Fri, 08 May 2009)
New Revision: 5161
Modified:
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
Log:
JBREM-1128: Small logging change.
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2009-05-08 06:59:30 UTC (rev 5160)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2009-05-08 07:00:27 UTC (rev 5161)
@@ -424,7 +424,7 @@
{
useClientConnectionIdentity = Boolean.valueOf((String) o).booleanValue();
}
- else
+ else if (o != null)
{
log.warn("value of " + Remoting.USE_CLIENT_CONNECTION_IDENTITY + " must be a String: " + o);
}
14 years, 11 months
JBoss Remoting SVN: r5160 - remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-08 02:59:30 -0400 (Fri, 08 May 2009)
New Revision: 5160
Modified:
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ConnectionValidator.java
Log:
JBREM-1128: Separated stopped into stopping and stopped.
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ConnectionValidator.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ConnectionValidator.java 2009-05-08 02:10:31 UTC (rev 5159)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/ConnectionValidator.java 2009-05-08 06:59:30 UTC (rev 5160)
@@ -236,6 +236,7 @@
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;
@@ -305,7 +306,7 @@
".addConnectionListener() instead.");
}
- if (stopped)
+ if (stopping)
{
return;
}
@@ -326,7 +327,7 @@
try
{
- if(!stopped)
+ if(!stopping)
{
isValid = false;
@@ -378,7 +379,7 @@
{
synchronized (lock)
{
- if (stopped)
+ if (stopping)
{
log.debug(this + " is stopped. Cannot add ConnectionListener: " + listener + " for " + client);
return false;
@@ -414,7 +415,7 @@
}
synchronized (lock)
{
- if (stopped)
+ if (stopping)
{
log.debug(this + " is stopped. It's too late to remove " + listener);
return false;
@@ -448,7 +449,7 @@
public long getPingPeriod()
{
- if (stopped)
+ if (stopping)
{
return -1;
}
@@ -473,11 +474,11 @@
final Throwable t = thr;
synchronized (lock)
{
- if (stopped)
+ if (stopping)
{
return;
}
- stopped = true;
+ stopping = true;
log.debug(this + " is stopped. No more listeners will be accepted.");
Iterator itr = listeners.keySet().iterator();
@@ -750,6 +751,7 @@
{
listeners.clear();
}
+ stopping = true;
stopped = true;
timer = null;
}
14 years, 11 months
JBoss Remoting SVN: r5159 - in remoting2/branches/2.2.2-SP11_JBREM-1112/src/tests/org/jboss/test/remoting/lease: identity and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-07 22:10:31 -0400 (Thu, 07 May 2009)
New Revision: 5159
Added:
remoting2/branches/2.2.2-SP11_JBREM-1112/src/tests/org/jboss/test/remoting/lease/identity/
remoting2/branches/2.2.2-SP11_JBREM-1112/src/tests/org/jboss/test/remoting/lease/identity/LeaseIdentityTestCase.java
Log:
JBREM-1128: New unit tests.
Added: remoting2/branches/2.2.2-SP11_JBREM-1112/src/tests/org/jboss/test/remoting/lease/identity/LeaseIdentityTestCase.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/tests/org/jboss/test/remoting/lease/identity/LeaseIdentityTestCase.java (rev 0)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/tests/org/jboss/test/remoting/lease/identity/LeaseIdentityTestCase.java 2009-05-08 02:10:31 UTC (rev 5159)
@@ -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.lease.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 Jul 18, 2008
+ * </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: r5158 - remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-07 21:54:18 -0400 (Thu, 07 May 2009)
New Revision: 5158
Modified:
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Lease.java
Log:
JBREM-1129: Uses LeasePinger.TIME_STAMP.
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Lease.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Lease.java 2009-05-08 01:53:43 UTC (rev 5157)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/Lease.java 2009-05-08 01:54:18 UTC (rev 5158)
@@ -98,7 +98,7 @@
long time = 0;
try
{
- String timeString = (String) requestMap.get("time");
+ String timeString = (String) requestMap.get(LeasePinger.TIME_STAMP);
log.debug(this + " timeString: " + timeString);
time = Long.valueOf(timeString).longValue();
log.debug(this + " time: " + time);
14 years, 11 months
JBoss Remoting SVN: r5157 - remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-05-07 21:53:43 -0400 (Thu, 07 May 2009)
New Revision: 5157
Modified:
remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
Log:
(1) JBREM-1129: Uses LeasePinger.TIME_STAMP; (2) JBREM-1128: uses "useClientConnectIdentity" parameter.
Modified: remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
===================================================================
--- remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2009-05-08 01:52:32 UTC (rev 5156)
+++ remoting2/branches/2.2.2-SP11_JBREM-1112/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java 2009-05-08 01:53:43 UTC (rev 5157)
@@ -416,6 +416,19 @@
{
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
+ {
+ log.warn("value of " + Remoting.USE_CLIENT_CONNECTION_IDENTITY + " must be a String: " + o);
+ }
+ }
synchronized (clientLeaseLock)
{
@@ -438,7 +451,7 @@
String leasePingerId = new GUID().toString();
Map requestMap = new HashMap();
requestMap.put(LeasePinger.LEASE_PINGER_ID, leasePingerId);
- requestMap.put("time", Long.toString(System.currentTimeMillis()));
+ requestMap.put(LeasePinger.TIME_STAMP, Long.toString(System.currentTimeMillis()));
log.debug(this + " initiating lease for leasePingerId " + leasePingerId);
InvocationRequest ir = new InvocationRequest(invokerSessionID, null, "$PING$", requestMap, new HashMap(), null);
@@ -468,6 +481,7 @@
leasePinger = new LeasePinger(this, invokerSessionID, defaultLeasePeriod);
leasePinger.setLeasePingerId(leasePingerId);
+ leasePinger.setUseClientConnectionIdentity(useClientConnectionIdentity);
leasePinger.addClient(clientSessionID, configuration, leasePeriod);
leasePinger.startPing();
}
14 years, 11 months