[hornetq-commits] JBoss hornetq SVN: r9143 - in trunk: src/config/common/schema and 21 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Apr 21 09:10:18 EDT 2010


Author: timfox
Date: 2010-04-21 09:10:13 -0400 (Wed, 21 Apr 2010)
New Revision: 9143

Modified:
   trunk/docs/user-manual/en/configuration-index.xml
   trunk/docs/user-manual/en/ha.xml
   trunk/src/config/common/schema/hornetq-jms.xsd
   trunk/src/main/org/hornetq/api/core/client/ClientSessionFactory.java
   trunk/src/main/org/hornetq/api/core/client/HornetQClient.java
   trunk/src/main/org/hornetq/api/jms/management/ConnectionFactoryControl.java
   trunk/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java
   trunk/src/main/org/hornetq/core/client/impl/FailoverManagerImpl.java
   trunk/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java
   trunk/src/main/org/hornetq/jms/client/HornetQConnectionFactory.java
   trunk/src/main/org/hornetq/jms/management/impl/JMSConnectionFactoryControlImpl.java
   trunk/src/main/org/hornetq/jms/server/JMSServerManager.java
   trunk/src/main/org/hornetq/jms/server/config/ConnectionFactoryConfiguration.java
   trunk/src/main/org/hornetq/jms/server/config/impl/ConnectionFactoryConfigurationImpl.java
   trunk/src/main/org/hornetq/jms/server/impl/JMSServerConfigParserImpl.java
   trunk/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java
   trunk/tests/config/hornetq-jms-for-JMSServerDeployerTest.xml
   trunk/tests/config/hornetq-jms-for-JMSServerDeployerTest2.xml
   trunk/tests/jms-tests/src/org/hornetq/jms/tests/CTSMiscellaneousTest.java
   trunk/tests/jms-tests/src/org/hornetq/jms/tests/JMSTestCase.java
   trunk/tests/jms-tests/src/org/hornetq/jms/tests/tools/container/LocalTestServer.java
   trunk/tests/src/org/hornetq/tests/integration/client/IncompatibleVersionTest.java
   trunk/tests/src/org/hornetq/tests/integration/cluster/failover/FailoverTest.java
   trunk/tests/src/org/hornetq/tests/integration/jms/FloodServerTest.java
   trunk/tests/src/org/hornetq/tests/integration/jms/client/PreACKJMSTest.java
   trunk/tests/src/org/hornetq/tests/integration/jms/client/ReSendMessageTest.java
   trunk/tests/src/org/hornetq/tests/integration/jms/client/SessionClosedOnRemotingConnectionFailureTest.java
   trunk/tests/src/org/hornetq/tests/integration/jms/client/TextMessageTest.java
   trunk/tests/src/org/hornetq/tests/integration/jms/divert/DivertAndACKClientTest.java
   trunk/tests/src/org/hornetq/tests/integration/jms/server/JMSServerDeployerTest.java
   trunk/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java
   trunk/tests/src/org/hornetq/tests/util/JMSTestBase.java
Log:
https://jira.jboss.org/jira/browse/HORNETQ-285

Modified: trunk/docs/user-manual/en/configuration-index.xml
===================================================================
--- trunk/docs/user-manual/en/configuration-index.xml	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/docs/user-manual/en/configuration-index.xml	2010-04-21 13:10:13 UTC (rev 9143)
@@ -1116,6 +1116,13 @@
                         </row>
                         <row>
                             <entry><link linkend="ha.automatic.failover"
+                                    >connection-factory.failover-on-initial-connection</link></entry>
+                            <entry>Boolean</entry>
+                            <entry>whether or not to failover to backup on event that initial connection to live server fails</entry>
+                            <entry>false</entry>
+                        </row>
+                        <row>
+                            <entry><link linkend="ha.automatic.failover"
                                     >connection-factory.failover-on-server-shutdown</link></entry>
                             <entry>Boolean</entry>
                             <entry>whether or not to failover on server shutdown</entry>

Modified: trunk/docs/user-manual/en/ha.xml
===================================================================
--- trunk/docs/user-manual/en/ha.xml	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/docs/user-manual/en/ha.xml	2010-04-21 13:10:13 UTC (rev 9143)
@@ -162,8 +162,9 @@
                     <programlisting>
                    &lt;shared-store>true&lt;shared-store>
                 </programlisting>
-                     <para>Additionally, the backup server must be flagged explicitly as a backup:</para>
-                     <programlisting>
+                    <para>Additionally, the backup server must be flagged explicitly as a
+                        backup:</para>
+                    <programlisting>
                    &lt;backup>true&lt;/backup>
                      </programlisting>
                     <para>In order for live - backup pairs to operate properly with a shared store,
@@ -235,10 +236,10 @@
                 To configure this you can set the property <literal
                     >FailoverOnServerShutdown</literal> to true either on the <literal
                     >HornetQConnectionFactory</literal> if you're using JMS or in the <literal
-                    >hornetq-jms.xml</literal> file when you define the connection factory, or if
-                using core by setting the property directly on the <literal
-                    >ClientSessionFactoryImpl</literal> instance after creation. The default value
-                for this property is <literal>false</literal>, this means that by default
+                    >hornetq-jms.xml (failover-on-server-shutdown property)</literal> file when you
+                define the connection factory, or if using core by setting the property directly on
+                the <literal>ClientSessionFactoryImpl</literal> instance after creation. The default
+                value for this property is <literal>false</literal>, this means that by default
                     <emphasis>HornetQ clients will not failover to a backup server if the live
                     server is simply shutdown cleanly.</emphasis></para>
             <para>
@@ -253,6 +254,18 @@
                         to true</para>
                 </note>
             </para>
+            <para>By default failover will only occur after at least one connection has been made to
+                the live server. In other words, by default, failover will not occur if the client
+                fails to make an initial connection to the live server - in this case it will simply
+                retry connecting to the live server according to the reconnect-attempts property and
+                fail after this number of attempts.</para>
+            <para>In some cases, you may want the client to automatically try the backup server it
+                fails to make an initial connection to the live server. In this case you can set the
+                property <literal>FailoverOnInitialConnection</literal>, or <literal
+                    >failover-on-initial-connection</literal> in xml, on the <literal
+                    >ClientSessionFactoryImpl</literal> or <literal
+                    >HornetQConnectionFactory</literal>. The default value for this parameter is
+                    <literal>false</literal>. </para>
             <para>For examples of automatic failover with transacted and non-transacted JMS
                 sessions, please see <xref linkend="examples.transaction-failover"/> and <xref
                     linkend="examples.non-transaction-failover"/>.</para>
@@ -272,10 +285,10 @@
                     global order to ensure a consistent replica state. This is extremely hard to do
                     in a performant and scalable way, especially when one considers that multiple
                     threads are changing the live server state concurrently.</para>
-                <para>It is possible to provide full state machine replication using
-                    techniques such as <emphasis role="italic">virtual synchrony</emphasis>, but
-                    this does not scale well and effectively serializes all operations to a single
-                    thread, dramatically reducing concurrency.</para>
+                <para>It is possible to provide full state machine replication using techniques such
+                    as <emphasis role="italic">virtual synchrony</emphasis>, but this does not scale
+                    well and effectively serializes all operations to a single thread, dramatically
+                    reducing concurrency.</para>
                 <para>Other techniques for multi-threaded active replication exist such as
                     replicating lock states or replicating thread scheduling but this is very hard
                     to achieve at a Java level.</para>
@@ -317,7 +330,8 @@
                         >HornetQException.TRANSACTION_ROLLED_BACK</literal> if using the core
                     API.</para>
                 <para>It is up to the user to catch the exception, and perform any client side local
-                    rollback code as necessary. There is no need to manually rollback the session - it is already rolled back. The user can then just retry the transactional
+                    rollback code as necessary. There is no need to manually rollback the session -
+                    it is already rolled back. The user can then just retry the transactional
                     operations again on the same session.</para>
                 <para>HornetQ ships with a fully functioning example demonstrating how to do this,
                     please see <xref linkend="examples.transaction-failover"/></para>

Modified: trunk/src/config/common/schema/hornetq-jms.xsd
===================================================================
--- trunk/src/config/common/schema/hornetq-jms.xsd	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/src/config/common/schema/hornetq-jms.xsd	2010-04-21 13:10:13 UTC (rev 9143)
@@ -112,6 +112,9 @@
             <xsd:element name="reconnect-attempts" type="xsd:int"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>
+            <xsd:element name="failover-on-initial-connection" type="xsd:boolean"
+                maxOccurs="1" minOccurs="0">
+            </xsd:element>
             <xsd:element name="failover-on-server-shutdown" type="xsd:boolean"
                 maxOccurs="1" minOccurs="0">
             </xsd:element>

Modified: trunk/src/main/org/hornetq/api/core/client/ClientSessionFactory.java
===================================================================
--- trunk/src/main/org/hornetq/api/core/client/ClientSessionFactory.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/src/main/org/hornetq/api/core/client/ClientSessionFactory.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -686,6 +686,23 @@
     * @param reconnectAttempts maximum number of attempts to retry connection in case of failure
     */
    void setReconnectAttempts(int reconnectAttempts);
+   
+   /**
+    * Returns true if the client will automatically attempt to connect to the backup server if the initial
+    * connection to the live server fails
+    * 
+    * Default value is {@link HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION}.
+    * 
+    * @return
+    */
+   boolean isFailoverOnInitialConnection();
+   
+   /**
+    * Sets the value for FailoverOnInitialReconnection
+    * 
+    * @param failover
+    */
+   void setFailoverOnInitialConnection(boolean failover);
 
    /**
     * Returns whether connections created by this factory must failover in case the server they are

Modified: trunk/src/main/org/hornetq/api/core/client/HornetQClient.java
===================================================================
--- trunk/src/main/org/hornetq/api/core/client/HornetQClient.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/src/main/org/hornetq/api/core/client/HornetQClient.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -77,6 +77,8 @@
    public static final long DEFAULT_MAX_RETRY_INTERVAL = 2000;
 
    public static final int DEFAULT_RECONNECT_ATTEMPTS = 0;
+   
+   public static final boolean DEFAULT_FAILOVER_ON_INITIAL_CONNECTION = false;
 
    public static final boolean DEFAULT_FAILOVER_ON_SERVER_SHUTDOWN = false;
 

Modified: trunk/src/main/org/hornetq/api/jms/management/ConnectionFactoryControl.java
===================================================================
--- trunk/src/main/org/hornetq/api/jms/management/ConnectionFactoryControl.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/src/main/org/hornetq/api/jms/management/ConnectionFactoryControl.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -239,7 +239,17 @@
     * @see ClientSessionFactory#setReconnectAttempts(int)
     */
    void setReconnectAttempts(int reconnectAttempts);
+   
+   /**
+    * @see ClientSessionFactory#isFailoverOnInitialConnection()
+    */
+   boolean isFailoverOnInitialConnection();
 
+    /**
+    * @see ClientSessionFactory#setFailoverOnInitialConnection(boolean)
+    */
+   void setFailoverOnInitialConnection(boolean failoverOnInitialConnection);
+
    /**
     * @see ClientSessionFactory#isFailoverOnServerShutdown()
     */

Modified: trunk/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -141,6 +141,8 @@
    private long maxRetryInterval;
 
    private int reconnectAttempts;
+   
+   private boolean failoverOnInitialConnection;
 
    private int initialMessagePacketSize;
 
@@ -259,7 +261,8 @@
                                                             retryInterval,
                                                             retryIntervalMultiplier,
                                                             maxRetryInterval,
-                                                            reconnectAttempts,                                                        
+                                                            reconnectAttempts,     
+                                                            failoverOnInitialConnection,
                                                             threadPool,
                                                             scheduledThreadPool,
                                                             interceptors);
@@ -342,6 +345,8 @@
       maxRetryInterval = other.getMaxRetryInterval();
 
       reconnectAttempts = other.getReconnectAttempts();
+      
+      failoverOnInitialConnection = other.isFailoverOnInitialConnection();
 
       failoverOnServerShutdown = other.isFailoverOnServerShutdown();
 
@@ -403,6 +408,8 @@
       maxRetryInterval = HornetQClient.DEFAULT_MAX_RETRY_INTERVAL;
 
       reconnectAttempts = HornetQClient.DEFAULT_RECONNECT_ATTEMPTS;
+      
+      failoverOnInitialConnection = HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION;
 
       failoverOnServerShutdown = HornetQClient.DEFAULT_FAILOVER_ON_SERVER_SHUTDOWN;
 
@@ -730,7 +737,18 @@
       checkWrite();
       this.reconnectAttempts = reconnectAttempts;
    }
+   
+   public synchronized boolean isFailoverOnInitialConnection()
+   {
+      return this.failoverOnInitialConnection;
+   }
 
+   public synchronized void setFailoverOnInitialConnection(final boolean failover)
+   {
+      checkWrite();
+      this.failoverOnInitialConnection = failover;
+   }
+
    public synchronized boolean isFailoverOnServerShutdown()
    {
       return failoverOnServerShutdown;
@@ -1023,7 +1041,8 @@
                                                                       retryInterval,
                                                                       retryIntervalMultiplier,
                                                                       maxRetryInterval,
-                                                                      reconnectAttempts,                                                                    
+                                                                      reconnectAttempts,  
+                                                                      failoverOnInitialConnection,
                                                                       threadPool,
                                                                       scheduledThreadPool,
                                                                       interceptors);

Modified: trunk/src/main/org/hornetq/core/client/impl/FailoverManagerImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/client/impl/FailoverManagerImpl.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/src/main/org/hornetq/core/client/impl/FailoverManagerImpl.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -75,7 +75,7 @@
    private static final long serialVersionUID = 2512460695662741413L;
 
    private static final Logger log = Logger.getLogger(FailoverManagerImpl.class);
-   
+
    // debug
 
    private static Map<TransportConfiguration, Set<CoreRemotingConnection>> debugConns;
@@ -199,7 +199,11 @@
    private volatile boolean exitLoop;
 
    private final List<Interceptor> interceptors;
-   
+
+   private volatile boolean stopPingingAfterOne;
+
+   private final boolean failoverOnInitialConnection;
+
    // Static
    // ---------------------------------------------------------------------------------------
 
@@ -217,6 +221,7 @@
                               final double retryIntervalMultiplier,
                               final long maxRetryInterval,
                               final int reconnectAttempts,
+                              final boolean failoverOnInitialConnection,
                               final ExecutorService threadPool,
                               final ScheduledExecutorService scheduledThreadPool,
                               final List<Interceptor> interceptors)
@@ -260,6 +265,8 @@
 
       this.reconnectAttempts = reconnectAttempts;
 
+      this.failoverOnInitialConnection = failoverOnInitialConnection;
+
       this.scheduledThreadPool = scheduledThreadPool;
 
       this.threadPool = threadPool;
@@ -339,9 +346,33 @@
                         return null;
                      }
 
-                     throw new HornetQException(HornetQException.NOT_CONNECTED,
-                                                "Unable to connect to server using configuration " + connectorConfig);
+                     if (failoverOnInitialConnection && backupConnectorFactory != null)
+                     {
+                        // Try and connect to the backup
 
+                        log.warn("Server is not available to make initial connection to. Will " + "try backup server instead.");
+
+                        connectorFactory = backupConnectorFactory;
+
+                        transportParams = backupTransportParams;
+
+                        backupConnectorFactory = null;
+
+                        backupTransportParams = null;
+
+                        theConnection = getConnectionWithRetry(reconnectAttempts);
+                     }
+
+                     if (exitLoop)
+                     {
+                        return null;
+                     }
+
+                     if (theConnection == null)
+                     {
+                        throw new HornetQException(HornetQException.NOT_CONNECTED,
+                                                   "Unable to connect to server using configuration " + connectorConfig);
+                     }
                   }
 
                   channel1 = theConnection.getChannel(1, -1);
@@ -441,7 +472,6 @@
             }
             catch (Throwable t)
             {
-               t.printStackTrace();
                if (lock != null)
                {
                   lock.unlock();
@@ -530,8 +560,6 @@
    // Public
    // ---------------------------------------------------------------------------------------
 
-   private volatile boolean stopPingingAfterOne;
-
    public void stopPingingAfterOne()
    {
       stopPingingAfterOne = true;
@@ -1136,46 +1164,6 @@
 
    }
 
-   private static final class ActualScheduledBatchFlusher implements Runnable
-   {
-      private final WeakReference<BatchFlushRunnable> batchFlushRunnable;
-
-      ActualScheduledBatchFlusher(final BatchFlushRunnable runnable)
-      {
-         batchFlushRunnable = new WeakReference<BatchFlushRunnable>(runnable);
-      }
-
-      public void run()
-      {
-         BatchFlushRunnable runnable = batchFlushRunnable.get();
-
-         if (runnable != null)
-         {
-            runnable.run();
-         }
-      }
-
-   }
-
-   private final class BatchFlushRunnable implements Runnable
-   {
-      private boolean cancelled;
-
-      public synchronized void run()
-      {
-         if (cancelled)
-         {
-            return;
-         }         
-         connection.getTransportConnection().checkFlushBatchBuffer();
-      }
-
-      public synchronized void cancel()
-      {
-         cancelled = true;
-      }
-   }
-
    private final class PingRunnable implements Runnable
    {
       private boolean cancelled;

Modified: trunk/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -790,7 +790,8 @@
                                      0,
                                      1.0d,
                                      0,
-                                     1,                                     
+                                     1, 
+                                     false,
                                      threadPool,
                                      scheduledPool,
                                      null);

Modified: trunk/src/main/org/hornetq/jms/client/HornetQConnectionFactory.java
===================================================================
--- trunk/src/main/org/hornetq/jms/client/HornetQConnectionFactory.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/src/main/org/hornetq/jms/client/HornetQConnectionFactory.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -509,7 +509,18 @@
       checkWrite();
       sessionFactory.setReconnectAttempts(reconnectAttempts);
    }
+   
+   public synchronized boolean isFailoverOnInitialConnection()
+   {
+      return sessionFactory.isFailoverOnInitialConnection();
+   }
 
+   public synchronized void setFailoverOnInitialConnection(final boolean failover)
+   {
+      checkWrite();
+      sessionFactory.setFailoverOnInitialConnection(failover);
+   }
+
    public synchronized boolean isFailoverOnServerShutdown()
    {
       return sessionFactory.isFailoverOnServerShutdown();

Modified: trunk/src/main/org/hornetq/jms/management/impl/JMSConnectionFactoryControlImpl.java
===================================================================
--- trunk/src/main/org/hornetq/jms/management/impl/JMSConnectionFactoryControlImpl.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/src/main/org/hornetq/jms/management/impl/JMSConnectionFactoryControlImpl.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -217,6 +217,11 @@
    {
       cf.setReconnectAttempts(reconnectAttempts);
    }
+   
+   public void setFailoverOnInitialConnection(boolean failover)
+   {
+      cf.setFailoverOnInitialConnection(failover);
+   }
 
    public void setFailoverOnServerShutdown(boolean failoverOnServerShutdown)
    {
@@ -397,6 +402,11 @@
    {
       return cf.getReconnectAttempts();
    }
+   
+   public boolean isFailoverOnInitialConnection()
+   {
+      return cf.isFailoverOnInitialConnection();
+   }
 
    public boolean isFailoverOnServerShutdown()
    {

Modified: trunk/src/main/org/hornetq/jms/server/JMSServerManager.java
===================================================================
--- trunk/src/main/org/hornetq/jms/server/JMSServerManager.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/src/main/org/hornetq/jms/server/JMSServerManager.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -218,6 +218,7 @@
                                 double retryIntervalMultiplier,
                                 long maxRetryInterval,
                                 int reconnectAttempts,
+                                boolean failoverOnInitialConnection,
                                 boolean failoverOnServerShutdown,
                                 String groupId,
                                 String ... jndiBindings) throws Exception;
@@ -254,6 +255,7 @@
                                 double retryIntervalMultiplier,
                                 long maxRetryInterval,
                                 int reconnectAttempts,
+                                boolean failoverOnInitialConnection,
                                 boolean failoverOnServerShutdown,
                                 String groupId,
                                 String ... jndiBindings) throws Exception;

Modified: trunk/src/main/org/hornetq/jms/server/config/ConnectionFactoryConfiguration.java
===================================================================
--- trunk/src/main/org/hornetq/jms/server/config/ConnectionFactoryConfiguration.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/src/main/org/hornetq/jms/server/config/ConnectionFactoryConfiguration.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -194,7 +194,11 @@
    boolean isFailoverOnServerShutdown();
 
    void setFailoverOnServerShutdown(boolean failoverOnServerShutdown);
+   
+   boolean isFailoverOnInitialConnection();
 
+   void setFailoverOnInitialConnection(boolean failover);
+
    String getGroupID();
 
    void setGroupID(String groupID);

Modified: trunk/src/main/org/hornetq/jms/server/config/impl/ConnectionFactoryConfigurationImpl.java
===================================================================
--- trunk/src/main/org/hornetq/jms/server/config/impl/ConnectionFactoryConfigurationImpl.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/src/main/org/hornetq/jms/server/config/impl/ConnectionFactoryConfigurationImpl.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -109,8 +109,10 @@
 
    private int reconnectAttempts = HornetQClient.DEFAULT_RECONNECT_ATTEMPTS;
 
+   private boolean failoverOnInitialConnection = HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION;
+
    private boolean failoverOnServerShutdown = HornetQClient.DEFAULT_FAILOVER_ON_SERVER_SHUTDOWN;
-
+   
    private String groupID = null;
    
    // Static --------------------------------------------------------
@@ -513,7 +515,17 @@
    {
       this.reconnectAttempts = reconnectAttempts;
    }
+   
+   public boolean isFailoverOnInitialConnection()
+   {
+      return failoverOnInitialConnection;
+   }
 
+   public void setFailoverOnInitialConnection(final boolean failover)
+   {
+      this.failoverOnInitialConnection = failover;
+   }
+
    public boolean isFailoverOnServerShutdown()
    {
       return failoverOnServerShutdown;
@@ -653,6 +665,8 @@
       maxRetryInterval = buffer.readLong();
 
       reconnectAttempts = buffer.readInt();
+      
+      failoverOnInitialConnection = buffer.readBoolean();
 
       failoverOnServerShutdown = buffer.readBoolean();
 
@@ -742,6 +756,8 @@
       buffer.writeLong(maxRetryInterval);
 
       buffer.writeInt(reconnectAttempts);
+      
+      buffer.writeBoolean(failoverOnInitialConnection);
 
       buffer.writeBoolean(failoverOnServerShutdown);
 
@@ -839,6 +855,8 @@
              DataConstants.SIZE_LONG + // maxRetryInterval
 
              DataConstants.SIZE_INT + // reconnectAttempts
+             
+             DataConstants.SIZE_BOOLEAN + // failoverOnInitialConnection
 
              DataConstants.SIZE_BOOLEAN + // failoverOnServerShutdown
              

Modified: trunk/src/main/org/hornetq/jms/server/impl/JMSServerConfigParserImpl.java
===================================================================
--- trunk/src/main/org/hornetq/jms/server/impl/JMSServerConfigParserImpl.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/src/main/org/hornetq/jms/server/impl/JMSServerConfigParserImpl.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -283,6 +283,10 @@
                                                               "reconnect-attempts",
                                                               HornetQClient.DEFAULT_RECONNECT_ATTEMPTS,
                                                               Validators.MINUS_ONE_OR_GE_ZERO);
+      boolean failoverOnInitialConnection = XMLConfigurationUtil.getBoolean(e,
+                                                                         "failover-on-initial-connection",
+                                                                         HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION);
+  
       boolean failoverOnServerShutdown = XMLConfigurationUtil.getBoolean(e,
                                                                          "failover-on-server-shutdown",
                                                                          HornetQClient.DEFAULT_FAILOVER_ON_SERVER_SHUTDOWN);
@@ -404,6 +408,7 @@
       cfConfig.setMaxRetryInterval(maxRetryInterval);
       cfConfig.setReconnectAttempts(reconnectAttempts);
       cfConfig.setFailoverOnServerShutdown(failoverOnServerShutdown);
+      cfConfig.setFailoverOnInitialConnection(failoverOnInitialConnection);
       cfConfig.setGroupID(groupid);
       return cfConfig;
    }

Modified: trunk/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java
===================================================================
--- trunk/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -724,6 +724,7 @@
                                                     final double retryIntervalMultiplier,
                                                     final long maxRetryInterval,
                                                     final int reconnectAttempts,
+                                                    final boolean failoverOnInitialConnection,
                                                     final boolean failoverOnServerShutdown,
                                                     final String groupId,
                                                     String... jndiBindings) throws Exception
@@ -759,6 +760,7 @@
          configuration.setRetryIntervalMultiplier(retryIntervalMultiplier);
          configuration.setMaxRetryInterval(maxRetryInterval);
          configuration.setReconnectAttempts(reconnectAttempts);
+         configuration.setFailoverOnInitialConnection(failoverOnInitialConnection);
          configuration.setFailoverOnServerShutdown(failoverOnServerShutdown);
          configuration.setGroupID(groupId);
          createConnectionFactory(true, configuration, jndiBindings);
@@ -797,6 +799,7 @@
                                                     final double retryIntervalMultiplier,
                                                     final long maxRetryInterval,
                                                     final int reconnectAttempts,
+                                                    final boolean failoverOnInitialConnection,
                                                     final boolean failoverOnServerShutdown,
                                                     final String groupId,
                                                     final String... jndiBindings) throws Exception
@@ -837,6 +840,7 @@
          configuration.setRetryIntervalMultiplier(retryIntervalMultiplier);
          configuration.setMaxRetryInterval(maxRetryInterval);
          configuration.setReconnectAttempts(reconnectAttempts);
+         configuration.setFailoverOnInitialConnection(failoverOnInitialConnection);
          configuration.setFailoverOnServerShutdown(failoverOnServerShutdown);
          createConnectionFactory(true, configuration, jndiBindings);
       }
@@ -935,6 +939,7 @@
                                                                     final double retryIntervalMultiplier,
                                                                     final long maxRetryInterval,
                                                                     final int reconnectAttempts,
+                                                                    final boolean failoverOnInitialConnection,
                                                                     final boolean failoverOnServerShutdown,
                                                                     final String groupId) throws Exception
    {
@@ -972,6 +977,7 @@
          cf.setRetryIntervalMultiplier(retryIntervalMultiplier);
          cf.setMaxRetryInterval(maxRetryInterval);
          cf.setReconnectAttempts(reconnectAttempts);
+         cf.setFailoverOnInitialConnection(failoverOnInitialConnection);
          cf.setFailoverOnServerShutdown(failoverOnServerShutdown);
       }
 
@@ -1006,6 +1012,7 @@
                                                                     final double retryIntervalMultiplier,
                                                                     final long maxRetryInterval,
                                                                     final int reconnectAttempts,
+                                                                    final boolean failoverOnInitialConnection,
                                                                     final boolean failoverOnServerShutdown,
                                                                     final String groupId) throws Exception
    {
@@ -1040,6 +1047,7 @@
          cf.setRetryIntervalMultiplier(retryIntervalMultiplier);
          cf.setMaxRetryInterval(maxRetryInterval);
          cf.setReconnectAttempts(reconnectAttempts);
+         cf.setFailoverOnInitialConnection(failoverOnInitialConnection);
          cf.setFailoverOnServerShutdown(failoverOnServerShutdown);
          cf.setGroupID(groupId);
       }
@@ -1175,6 +1183,7 @@
                                               cfConfig.getRetryIntervalMultiplier(),
                                               cfConfig.getMaxRetryInterval(),
                                               cfConfig.getReconnectAttempts(),
+                                              cfConfig.isFailoverOnInitialConnection(),
                                               cfConfig.isFailoverOnServerShutdown(),
                                               cfConfig.getGroupID());
       }
@@ -1208,6 +1217,7 @@
                                               cfConfig.getRetryIntervalMultiplier(),
                                               cfConfig.getMaxRetryInterval(),
                                               cfConfig.getReconnectAttempts(),
+                                              cfConfig.isFailoverOnInitialConnection(),
                                               cfConfig.isFailoverOnServerShutdown(),
                                               cfConfig.getGroupID());
       }

Modified: trunk/tests/config/hornetq-jms-for-JMSServerDeployerTest.xml
===================================================================
--- trunk/tests/config/hornetq-jms-for-JMSServerDeployerTest.xml	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/config/hornetq-jms-for-JMSServerDeployerTest.xml	2010-04-21 13:10:13 UTC (rev 9143)
@@ -30,6 +30,7 @@
       <pre-acknowledge>true</pre-acknowledge>
       <connection-ttl>2345</connection-ttl>
       <discovery-initial-wait-timeout>678</discovery-initial-wait-timeout>
+      <failover-on-initial-connection>true</failover-on-initial-connection>
       <failover-on-server-shutdown>false</failover-on-server-shutdown>
       <connection-load-balancing-policy-class-name>FooClass</connection-load-balancing-policy-class-name>
       <reconnect-attempts>34</reconnect-attempts>

Modified: trunk/tests/config/hornetq-jms-for-JMSServerDeployerTest2.xml
===================================================================
--- trunk/tests/config/hornetq-jms-for-JMSServerDeployerTest2.xml	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/config/hornetq-jms-for-JMSServerDeployerTest2.xml	2010-04-21 13:10:13 UTC (rev 9143)
@@ -31,6 +31,7 @@
       <pre-acknowledge>true</pre-acknowledge>
       <connection-ttl>2345</connection-ttl>
       <discovery-initial-wait-timeout>678</discovery-initial-wait-timeout>
+      <failover-on-initial-connection>true</failover-on-initial-connection>
       <failover-on-server-shutdown>false</failover-on-server-shutdown>
       <connection-load-balancing-policy-class-name>FooClass</connection-load-balancing-policy-class-name>
       <reconnect-attempts>34</reconnect-attempts>

Modified: trunk/tests/jms-tests/src/org/hornetq/jms/tests/CTSMiscellaneousTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/hornetq/jms/tests/CTSMiscellaneousTest.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/jms-tests/src/org/hornetq/jms/tests/CTSMiscellaneousTest.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -92,6 +92,7 @@
                                                        HornetQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER,
                                                        HornetQClient.DEFAULT_MAX_RETRY_INTERVAL,
                                                        HornetQClient.DEFAULT_RECONNECT_ATTEMPTS,
+                                                       HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION,
                                                        HornetQClient.DEFAULT_FAILOVER_ON_SERVER_SHUTDOWN,
                                                        null,
                                                        "/StrictTCKConnectionFactory");

Modified: trunk/tests/jms-tests/src/org/hornetq/jms/tests/JMSTestCase.java
===================================================================
--- trunk/tests/jms-tests/src/org/hornetq/jms/tests/JMSTestCase.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/jms-tests/src/org/hornetq/jms/tests/JMSTestCase.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -88,6 +88,7 @@
                                                     HornetQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER,
                                                     HornetQClient.DEFAULT_MAX_RETRY_INTERVAL,
                                                     HornetQClient.DEFAULT_RECONNECT_ATTEMPTS,
+                                                    HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION,
                                                     HornetQClient.DEFAULT_FAILOVER_ON_SERVER_SHUTDOWN,
                                                     null,
                                                     "/testsuitecf");

Modified: trunk/tests/jms-tests/src/org/hornetq/jms/tests/tools/container/LocalTestServer.java
===================================================================
--- trunk/tests/jms-tests/src/org/hornetq/jms/tests/tools/container/LocalTestServer.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/jms-tests/src/org/hornetq/jms/tests/tools/container/LocalTestServer.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -318,6 +318,7 @@
                                                     HornetQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER,
                                                     HornetQClient.DEFAULT_MAX_RETRY_INTERVAL,
                                                     HornetQClient.DEFAULT_RECONNECT_ATTEMPTS,
+                                                    HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION,
                                                     HornetQClient.DEFAULT_FAILOVER_ON_SERVER_SHUTDOWN,
                                                     null,
                                                     jndiBindings);

Modified: trunk/tests/src/org/hornetq/tests/integration/client/IncompatibleVersionTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/client/IncompatibleVersionTest.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/src/org/hornetq/tests/integration/client/IncompatibleVersionTest.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -81,6 +81,7 @@
                                                                     HornetQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER,
                                                                     HornetQClient.DEFAULT_MAX_RETRY_INTERVAL,
                                                                     HornetQClient.DEFAULT_RECONNECT_ATTEMPTS,
+                                                                    HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION,
                                                                     executorService,
                                                                     scheduledexecutorService,
                                                                     null);

Modified: trunk/tests/src/org/hornetq/tests/integration/cluster/failover/FailoverTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/cluster/failover/FailoverTest.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/src/org/hornetq/tests/integration/cluster/failover/FailoverTest.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -45,19 +45,6 @@
  * 
  * A FailoverTest
  * 
- * Tests:
- * 
- * Failover via shared storage manager:
- * 
- * 
- * 5) Failover due to failure on create session
- * 
- * 6) Replicate above tests on JMS API
- * 
- * 7) Repeat above tests using replicated journal
- * 
- * 8) Test with different values of auto commit acks and autocomit sends
- * 
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  *
  */
@@ -231,7 +218,63 @@
 
       Assert.assertEquals(0, sf.numConnections());
    }
+   
+   // https://jira.jboss.org/jira/browse/HORNETQ-285
+   public void testFailoverOnInitialConnection() throws Exception
+   {
+      ClientSessionFactoryInternal sf = getSessionFactory();
 
+      sf.setBlockOnNonDurableSend(true);
+      sf.setBlockOnDurableSend(true);
+      sf.setFailoverOnInitialConnection(true);
+      
+      // Stop live server
+      
+      this.server0Service.stop();
+
+      ClientSession session = sf.createSession();
+
+      session.createQueue(FailoverTestBase.ADDRESS, FailoverTestBase.ADDRESS, null, true);
+
+      ClientProducer producer = session.createProducer(FailoverTestBase.ADDRESS);
+
+      final int numMessages = 100;
+
+      for (int i = 0; i < numMessages; i++)
+      {
+         ClientMessage message = session.createMessage(true);
+
+         setBody(i, message);
+
+         message.putIntProperty("counter", i);
+
+         producer.send(message);
+      }
+
+      ClientConsumer consumer = session.createConsumer(FailoverTestBase.ADDRESS);
+
+      session.start();
+
+      for (int i = 0; i < numMessages; i++)
+      {
+         ClientMessage message = consumer.receive(1000);
+
+         Assert.assertNotNull(message);
+
+         assertMessageBody(i, message);
+
+         Assert.assertEquals(i, message.getIntProperty("counter").intValue());
+
+         message.acknowledge();
+      }
+
+      session.close();
+
+      Assert.assertEquals(0, sf.numSessions());
+
+      Assert.assertEquals(0, sf.numConnections());
+   }
+
    /**
     * @param session
     * @param latch

Modified: trunk/tests/src/org/hornetq/tests/integration/jms/FloodServerTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/jms/FloodServerTest.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/src/org/hornetq/tests/integration/jms/FloodServerTest.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -156,6 +156,7 @@
                                             retryIntervalMultiplier,
                                             1000,
                                             reconnectAttempts,
+                                            HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION,
                                             failoverOnServerShutdown,
                                             null,
                                             "/cf");

Modified: trunk/tests/src/org/hornetq/tests/integration/jms/client/PreACKJMSTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/jms/client/PreACKJMSTest.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/src/org/hornetq/tests/integration/jms/client/PreACKJMSTest.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -226,6 +226,7 @@
                                         retryIntervalMultiplier,
                                         HornetQClient.DEFAULT_MAX_RETRY_INTERVAL,
                                         reconnectAttempts,
+                                        HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION,
                                         failoverOnServerShutdown,
                                         null,
                                         jndiBindings);

Modified: trunk/tests/src/org/hornetq/tests/integration/jms/client/ReSendMessageTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/jms/client/ReSendMessageTest.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/src/org/hornetq/tests/integration/jms/client/ReSendMessageTest.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -325,6 +325,7 @@
                                         retryIntervalMultiplier,
                                         HornetQClient.DEFAULT_MAX_RETRY_INTERVAL,
                                         reconnectAttempts,
+                                        HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION,
                                         failoverOnServerShutdown,
                                         null,
                                         jndiBindings);

Modified: trunk/tests/src/org/hornetq/tests/integration/jms/client/SessionClosedOnRemotingConnectionFailureTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/jms/client/SessionClosedOnRemotingConnectionFailureTest.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/src/org/hornetq/tests/integration/jms/client/SessionClosedOnRemotingConnectionFailureTest.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -94,6 +94,7 @@
                                         HornetQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER,
                                         HornetQClient.DEFAULT_MAX_RETRY_INTERVAL,
                                         0,
+                                        HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION,
                                         false,
                                         null,
                                         "/cffoo");

Modified: trunk/tests/src/org/hornetq/tests/integration/jms/client/TextMessageTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/jms/client/TextMessageTest.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/src/org/hornetq/tests/integration/jms/client/TextMessageTest.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -261,6 +261,7 @@
                                         retryIntervalMultiplier,
                                         HornetQClient.DEFAULT_MAX_RETRY_INTERVAL,
                                         reconnectAttempts,
+                                        HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION,
                                         failoverOnServerShutdown,
                                         null,
                                         jndiBindings);

Modified: trunk/tests/src/org/hornetq/tests/integration/jms/divert/DivertAndACKClientTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/jms/divert/DivertAndACKClientTest.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/src/org/hornetq/tests/integration/jms/divert/DivertAndACKClientTest.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -172,6 +172,7 @@
                                         retryIntervalMultiplier,
                                         HornetQClient.DEFAULT_MAX_RETRY_INTERVAL,
                                         reconnectAttempts,
+                                        HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION,
                                         failoverOnServerShutdown,
                                         null,
                                         jndiBindings);

Modified: trunk/tests/src/org/hornetq/tests/integration/jms/server/JMSServerDeployerTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/jms/server/JMSServerDeployerTest.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/src/org/hornetq/tests/integration/jms/server/JMSServerDeployerTest.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -220,6 +220,7 @@
          Assert.assertEquals(true, cf.isPreAcknowledge());
          Assert.assertEquals(2345, cf.getConnectionTTL());
          Assert.assertEquals(false, cf.isFailoverOnServerShutdown());
+         assertEquals(true, cf.isFailoverOnInitialConnection());
          Assert.assertEquals(34, cf.getReconnectAttempts());
          Assert.assertEquals(5, cf.getRetryInterval());
          Assert.assertEquals(6.0, cf.getRetryIntervalMultiplier());
@@ -304,6 +305,7 @@
          Assert.assertEquals(false, cf.isAutoGroup());
          Assert.assertEquals(true, cf.isPreAcknowledge());
          Assert.assertEquals(2345, cf.getConnectionTTL());
+         assertEquals(true, cf.isFailoverOnInitialConnection());
          Assert.assertEquals(false, cf.isFailoverOnServerShutdown());
          Assert.assertEquals(34, cf.getReconnectAttempts());
          Assert.assertEquals(5, cf.getRetryInterval());

Modified: trunk/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -724,6 +724,7 @@
                                      1.0d,
                                      0,
                                      1,
+                                     HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION,
                                      executor,
                                      scheduledExecutor,
                                      interceptors);

Modified: trunk/tests/src/org/hornetq/tests/util/JMSTestBase.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/util/JMSTestBase.java	2010-04-21 10:12:02 UTC (rev 9142)
+++ trunk/tests/src/org/hornetq/tests/util/JMSTestBase.java	2010-04-21 13:10:13 UTC (rev 9143)
@@ -210,6 +210,7 @@
                                         retryIntervalMultiplier,
                                         HornetQClient.DEFAULT_MAX_RETRY_INTERVAL,
                                         reconnectAttempts,
+                                        HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION,
                                         failoverOnServerShutdown,
                                         null,
                                         jndiBindings);



More information about the hornetq-commits mailing list