[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting ...
Tom Elrod
tom.elrod at jboss.com
Mon Jul 24 01:23:54 EDT 2006
User: telrod
Date: 06/07/24 01:23:54
Modified: src/main/org/jboss/remoting ConnectionValidator.java
Log:
JBREM-530 - corrected connection validator behavior to not spawn new thread to make invocation on old client invoker, but instead create a new client invoker for the ping invocation.
Revision Changes Path
1.11 +45 -28 JBossRemoting/src/main/org/jboss/remoting/ConnectionValidator.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ConnectionValidator.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/ConnectionValidator.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- ConnectionValidator.java 24 Jul 2006 02:07:56 -0000 1.10
+++ ConnectionValidator.java 24 Jul 2006 05:23:54 -0000 1.11
@@ -27,8 +27,10 @@
import org.jboss.remoting.util.TimerUtil;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
+import java.util.Map;
import java.util.TimerTask;
/**
@@ -109,7 +111,7 @@
{
try
{
- boolean isValid = checkConnection(client.getInvoker());
+ boolean isValid = checkConnection(client.getInvoker().getLocator(), client.getConfiguration());
if (!isValid)
{
notifyListeners(new Exception("Could not connect to server."));
@@ -147,21 +149,34 @@
* Will make $PING$ invocation on server. If sucessful, will return true. Otherwise,
* will throw an exception.
*
- * @param clientInvoker
- * @return
+ * @param locator - locator for the server to ping
+ * @param config - any configuration needed for server
+ * @return true if alive, false if not
* @throws Throwable
*/
- public static boolean checkConnection(ClientInvoker clientInvoker) throws Throwable
+ public static boolean checkConnection(InvokerLocator locator, Map config) throws Throwable
{
- final StringBuffer pinged = new StringBuffer("f");
- final ClientInvoker innerClientInvoker = clientInvoker;
+ boolean pingWorked = false;
- Thread t = new Thread(new Runnable()
- {
- public void run()
+ Map configMap = config;
+ if (configMap == null)
{
+ configMap = new HashMap();
+ }
+ configMap.put("connection_checker", "true");
+ configMap.put("timeout", "1000");
+ configMap.put("NumberOfRetries", "1");
+ ClientInvoker innerClientInvoker = null;
+
try
{
+
+ innerClientInvoker = InvokerRegistry.createClientInvoker(locator, configMap);
+
+ if (!innerClientInvoker.isConnected())
+ {
+ innerClientInvoker.connect();
+ }
/**
* 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
@@ -169,19 +184,21 @@
*/
Object o = innerClientInvoker.invoke(new InvocationRequest(null, Subsystem.SELF,
"$PING$", null, null, null));
- pinged.setCharAt(0, 't');
+ pingWorked = true;
}
catch (Throwable throwable)
{
log.warn("ConnectionValidator could not successfully ping server (" + innerClientInvoker.getLocator());
}
+ finally
+ {
+ if (innerClientInvoker != null)
+ {
+ InvokerRegistry.destroyClientInvoker(locator, configMap);
+ }
}
- });
- t.start();
-
- t.join(5000);
- return pinged.charAt(0) == 't';
+ return pingWorked;
}
More information about the jboss-cvs-commits
mailing list