[hornetq-commits] JBoss hornetq SVN: r10985 - branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/core/client/impl.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jul 14 12:25:29 EDT 2011


Author: clebert.suconic at jboss.com
Date: 2011-07-14 12:25:28 -0400 (Thu, 14 Jul 2011)
New Revision: 10985

Modified:
   branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/core/client/impl/ServerLocatorImpl.java
Log:
improving clustering

Modified: branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/core/client/impl/ServerLocatorImpl.java
===================================================================
--- branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/core/client/impl/ServerLocatorImpl.java	2011-07-14 16:24:00 UTC (rev 10984)
+++ branches/Branch_2_2_EAP_cluster_clean2/src/main/org/hornetq/core/client/impl/ServerLocatorImpl.java	2011-07-14 16:25:28 UTC (rev 10985)
@@ -1363,33 +1363,26 @@
          try
          {
             
-            List<Future<ClientSessionFactory>> futuresList = new ArrayList<Future<ClientSessionFactory>>();
-            
-            for (Connector conn : connectors)
+            while (csf == null && !ServerLocatorImpl.this.closed && !ServerLocatorImpl.this.closing)
             {
-                // TODO:   Why using submit here? if we are waiting for it anyway?
-                log.info("XXX Submitting call towards " + conn);
-                futuresList.add(threadPool.submit(conn));
-            }
-            
-            for (int i = 0, futuresSize = futuresList.size(); i < futuresSize; i++)
-            {
-               Future<ClientSessionFactory> future = futuresList.get(i);
-               try
+               for (Connector conn : connectors)
                {
-                  csf = future.get();
-                  if (csf != null)
-                     break;
+                   if (log.isDebugEnabled())
+                   {
+                      log.debug("Submitting connect towards " + conn);
+                   }
+                   
+                   csf = conn.tryConnect();
+                   
+                   if (csf != null || ServerLocatorImpl.this.closed || ServerLocatorImpl.this.closing)
+                   {
+                      break;
+                   }
                }
-               catch (Exception e)
-               {
-                  log.debug("unable to connect with static connector " + connectors.get(i).initialConnector);
-               }
+               
+               Thread.sleep (retryInterval);
             }
-            if (csf == null && !closed)
-            {
-               throw new HornetQException(HornetQException.NOT_CONNECTED, "Failed to connect to any static connectors");
-            }
+            
          }
          catch (Exception e)
          {
@@ -1455,14 +1448,12 @@
          super.finalize();
       }
 
-      class Connector implements Callable<ClientSessionFactory>
+      class Connector 
       {
          private TransportConfiguration initialConnector;
 
          private volatile ClientSessionFactoryInternal factory;
 
-         private boolean isConnected = false;
-
          private boolean interrupted = false;
 
          private Exception e;
@@ -1473,15 +1464,16 @@
             this.factory = factory;
          }
 
-         public ClientSessionFactory call() throws HornetQException
+         public ClientSessionFactory tryConnect() throws HornetQException
          {
             if (log.isDebugEnabled())
             {
-               log.debug("Executing connection to " + factory + " through threadPool.submission()");
+               log.debug("Trying to connect to " + factory);
             }
             try
             {
-               factory.connect(initialConnectAttempts, failoverOnInitialConnection);
+               factory.connect(1, false);
+               return factory;
             }
             catch (HornetQException e)
             {
@@ -1491,29 +1483,10 @@
                   this.e = e;
                   throw e;
                }
-               /*if(factory != null)
-               {
-                  factory.close();
-                  factory = null;
-               }*/
                return null;
             }
-            isConnected = true;
-            for (Connector connector : connectors)
-            {
-               if (!connector.isConnected())
-               {
-                  connector.disconnect();
-               }
-            }
-            return factory;
          }
 
-         public boolean isConnected()
-         {
-            return isConnected;
-         }
-
          public void disconnect()
          {
             interrupted = true;



More information about the hornetq-commits mailing list