[jboss-remoting-commits] JBoss Remoting SVN: r6162 - remoting2/branches/2.x/src/main/org/jboss/remoting.
jboss-remoting-commits at lists.jboss.org
jboss-remoting-commits at lists.jboss.org
Wed Dec 15 18:06:51 EST 2010
Author: ron.sigal at jboss.com
Date: 2010-12-15 18:06:50 -0500 (Wed, 15 Dec 2010)
New Revision: 6162
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java
Log:
JBREM-1144: Declares connection broken when it sees a new serverId, if useServerConnectionIdentity is set to true.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java 2010-12-15 23:05:31 UTC (rev 6161)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ConnectionValidator.java 2010-12-15 23:06:50 UTC (rev 6162)
@@ -268,6 +268,8 @@
private MicroRemoteClientInvoker sharedInvoker;
private LeasePinger leasePinger;
private boolean useClientConnectionIdentity;
+ private boolean useServerConnectionIdentity;
+ private String serverId;
// Constructors ---------------------------------------------------------------------------------
@@ -748,6 +750,27 @@
" to a boolean: must be a String");
}
}
+ o = config.get(Remoting.USE_SERVER_CONNECTION_IDENTITY);
+ if (o != null)
+ {
+ if (o instanceof String)
+ {
+ try
+ {
+ useServerConnectionIdentity = Boolean.valueOf(((String) o)).booleanValue();
+ }
+ catch (Exception e)
+ {
+ log.warn(this + " could not convert " + Remoting.USE_SERVER_CONNECTION_IDENTITY + " value" +
+ " to a boolean: " + o);
+ }
+ }
+ else
+ {
+ log.warn(this + " could not convert " + Remoting.USE_SERVER_CONNECTION_IDENTITY + " value" +
+ " to a boolean: must be a String");
+ }
+ }
}
}
@@ -813,6 +836,12 @@
{
Map metadata = new HashMap();
metadata.put(ServerInvoker.INVOKER_SESSION_ID, invokerSessionId);
+
+ if (useServerConnectionIdentity)
+ {
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ }
+
InvocationRequest ir =
new InvocationRequest(null, Subsystem.SELF, "$PING$", metadata, null, null);
@@ -824,10 +853,61 @@
// Server indicates lease has stopped.
throw new Exception();
}
+ if (o instanceof InvocationResponse)
+ {
+ Object result = ((InvocationResponse) o).getResult();
+ if (result instanceof Boolean && !((Boolean) result).booleanValue())
+ {
+ // Server indicates lease has stopped.
+ throw new Exception();
+ }
+ if (useServerConnectionIdentity)
+ {
+ Map map = ((InvocationResponse) o).getPayload();
+ if (map != null)
+ {
+ String s = (String) map.get(Remoting.SERVER_ID);
+ if (s != null)
+ {
+ if (serverId == null)
+ {
+ serverId = s;
+ pingWorked = true;
+ if (trace) log.trace(this + " set serverId to " + serverId);
+ }
+ else
+ {
+ pingWorked = s.equals(serverId);
+ if (!pingWorked)
+ {
+ if (trace) log.trace(this + " detected new serverId: " + s + " != " + serverId);
+ }
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
- if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);}
-
- pingWorked = true;
+ if (pingWorked)
+ {
+ if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);}
+ }
+ else
+ {
+ if (trace) { log.trace("ConnectionValidator did not get successful ping response " + clientInvoker);}
+ }
}
catch (Throwable t)
{
@@ -845,17 +925,69 @@
{
// Sending null client id as don't want to trigger lease on server side. This also means
// that client connection validator will NOT impact client lease, so can not depend on it
- // to maintain client lease with the server.
- InvocationRequest ir =
- new InvocationRequest(null, Subsystem.SELF, "$PING$", null, null, null);
+ // to maintain client lease with the server
+
+ InvocationRequest ir = null;
+ if (useServerConnectionIdentity)
+ {
+ Map metadata = new HashMap();
+ metadata.put(Remoting.USE_SERVER_CONNECTION_IDENTITY, "true");
+ ir = new InvocationRequest(null, Subsystem.SELF, "$PING$", metadata, null, null);
+ }
+ else
+ {
+ ir = new InvocationRequest(null, Subsystem.SELF, "$PING$", null, null, null);
+ }
if (trace) { log.trace("pinging, sending " + ir + " over " + clientInvoker); }
- clientInvoker.invoke(ir);
+ Object o = clientInvoker.invoke(ir);
+ if (useServerConnectionIdentity && o instanceof InvocationResponse)
+ {
+ Map map = ((InvocationResponse) o).getPayload();
+ if (map != null)
+ {
+ String s = (String) map.get(Remoting.SERVER_ID);
+ if (s != null)
+ {
+ if (serverId == null)
+ {
+ serverId = s;
+ pingWorked = true;
+ if (trace) log.trace(this + " set serverId to " + serverId);
+ }
+ else
+ {
+ pingWorked = s.equals(serverId);
+ if (!pingWorked)
+ {
+ if (trace) log.trace(this + " detected new serverId: " + s + " != " + serverId);
+ }
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
+ }
+ else
+ {
+ pingWorked = true;
+ }
- if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);}
-
- pingWorked = true;
+ if (pingWorked)
+ {
+ if (trace) { log.trace("ConnectionValidator got successful ping using " + clientInvoker);}
+ }
+ else
+ {
+ if (trace) { log.trace("ConnectionValidator did not get successful ping response " + clientInvoker);}
+ }
}
catch (Throwable t)
{
More information about the jboss-remoting-commits
mailing list