[hornetq-commits] JBoss hornetq SVN: r8454 - in trunk/examples/jms/reconnect-same-node: src/org/hornetq/jms/example and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Sun Nov 29 10:09:08 EST 2009


Author: ataylor
Date: 2009-11-29 10:09:08 -0500 (Sun, 29 Nov 2009)
New Revision: 8454

Added:
   trunk/examples/jms/reconnect-same-node/src/org/hornetq/jms/example/ReattachExample.java
Removed:
   trunk/examples/jms/reconnect-same-node/src/org/hornetq/jms/example/ReconnectSameNodeExample.java
Modified:
   trunk/examples/jms/reconnect-same-node/build.xml
   trunk/examples/jms/reconnect-same-node/readme.html
Log:
renamed example

Modified: trunk/examples/jms/reconnect-same-node/build.xml
===================================================================
--- trunk/examples/jms/reconnect-same-node/build.xml	2009-11-28 22:57:54 UTC (rev 8453)
+++ trunk/examples/jms/reconnect-same-node/build.xml	2009-11-29 15:09:08 UTC (rev 8454)
@@ -21,13 +21,13 @@
 
    <target name="run">
       <antcall target="runExample">
-         <param name="example.classname" value="org.hornetq.jms.example.ReconnectSameNodeExample"/>
+         <param name="example.classname" value="org.hornetq.jms.example.ReattachExample"/>
       </antcall>
    </target>
 
    <target name="runRemote">
       <antcall target="runExample">
-         <param name="example.classname" value="org.hornetq.jms.example.ReconnectSameNodeExample"/>
+         <param name="example.classname" value="org.hornetq.jms.example.ReattachExample"/>
          <param name="hornetq.example.runServer" value="false"/>
       </antcall>
    </target>

Modified: trunk/examples/jms/reconnect-same-node/readme.html
===================================================================
--- trunk/examples/jms/reconnect-same-node/readme.html	2009-11-28 22:57:54 UTC (rev 8453)
+++ trunk/examples/jms/reconnect-same-node/readme.html	2009-11-29 15:09:08 UTC (rev 8454)
@@ -1,36 +1,35 @@
 <html>
   <head>
-    <title>HornetQ JMS Automatic Reconnect Same Server Example</title>
+    <title>HornetQ JMS Automatic Reattach Example</title>
     <link rel="stylesheet" type="text/css" href="../../common/common.css" />
     <link rel="stylesheet" type="text/css" href="../../common/prettify.css" />
     <script type="text/javascript" src="../../common/prettify.js"></script>
   </head>
   <body onload="prettyPrint()">
-     <h1>HornetQ JMS Reconnect Same Server Example</h1>
+     <h1>HornetQ JMS Reattach Example</h1>
      <br>
      <p>This example demonstrates how HornetQ connections can be configured to be resilient to
      temporary network failures.</p>
      <p>In the case of a network failure being detected, either as a result of a failure to read/write to the connection,
      or the failure of a pong to arrive back from the server in good time after a ping is sent, instead of
      failing the connection immediately and notifying any user ExceptionListener objects, HornetQ
-     can be configured to automatically retry the connection, and reconnect to the server when it becomes
+     can be configured to automatically retry the connection, and reattach to the server when it becomes
      available again across the network.</p>
-     <p>In the case that the server didn't actually crash, i.e. the network was temporarily unavailable, the client will
-     be able to resume all its sessions and connections where it left off, 100% transparently.</p>
-     <p>In the case that the server <b>did</b> crash and was restarted, on reconnection the server session
-     clearly won't still exist, so the session will be unable to continue transparently, and any registered
-     ExceptionListener will be called, to allow any application layer reconnect logic to be called.</p>
-     <p>This example starts a single server, connects to it and performs some JMS operations. We then
+     <p>When the client reattaches to the server it will be able to resume using its sessions and connections
+     where it left off</p>
+     <p>This is different to client reconnect as the sessions, consumers etc still exist on the server. With reconnect
+     The client recreates its sessions and consumers as needed.</p>
+    <p>This example starts a single server, connects to it and performs some JMS operations. We then
      simulate failure of the network connection by temporarily stopping the network acceptor on the server.
      (This is done by sending management messages, but that is not central to the purpose of the example).</p>
-     <p>We then wait a few seconds, then restart the acceptor. The client reconnects and the session resumes
+     <p>We then wait a few seconds, then restart the acceptor. The client reattaches and the session resumes
      as if nothing happened.</p>
-     <p>The JMS Connection Factory is configured to reconnect automatically by specifying the various reconnect
-     related attributes in the <code>hornetq-jms.xml</code> file.</p>  
-             
+     <p>The JMS Connection Factory is configured to reattach automatically by specifying the various reconnect
+     related attributes in the <code>hornetq-jms.xml</code> file.</p>
+
      <p>For more details on how to configure this and for clustering in general
      please consult the HornetQ user manual.</p>
-          
+
      <br>
      <h2>Example step-by-step</h2>
      <p><i>To run the example, simply type <code>./build.sh</code> (or <code>build.bat</code> on windows) from this directory</i></p>
@@ -91,10 +90,10 @@
         <pre class="prettyprint">
            <code>stopAcceptor(initialContext);</code>
         </pre>
-        
+
         <li>We wait 10 seconds, before restarting the acceptor. During this period the client will be retrying
         to connect. When the acceptor is restarted it will be successful in reconnecting.</li>
-        
+
         <pre class="prettyprint">
            <code>
             Thread.sleep(10000);
@@ -102,9 +101,9 @@
             startAcceptor(initialContext);
            </code>
         </pre>
-        
-        <li>We receive the message after reconnection! Note that no exceptions were received by the client.</li>
-        
+
+        <li>We receive the message after reattachment! Note that no exceptions were received by the client.</li>
+
         <pre class="prettyprint">
            <code>
            TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000);

Copied: trunk/examples/jms/reconnect-same-node/src/org/hornetq/jms/example/ReattachExample.java (from rev 8453, trunk/examples/jms/reconnect-same-node/src/org/hornetq/jms/example/ReconnectSameNodeExample.java)
===================================================================
--- trunk/examples/jms/reconnect-same-node/src/org/hornetq/jms/example/ReattachExample.java	                        (rev 0)
+++ trunk/examples/jms/reconnect-same-node/src/org/hornetq/jms/example/ReattachExample.java	2009-11-29 15:09:08 UTC (rev 8454)
@@ -0,0 +1,166 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.  See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+package org.hornetq.jms.example;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+
+import org.hornetq.common.example.HornetQExample;
+import org.hornetq.jms.HornetQQueue;
+import org.hornetq.jms.server.management.impl.JMSManagementHelper;
+
+/**
+ * This examples demonstrates a connection created to a server. Failure of the network connection is then simulated
+ * 
+ * The network is brought back up and the client reconnects and resumes transparently.
+ *
+ * @author <a href="tim.fox at jboss.com>Tim Fox</a>
+ */
+public class ReattachExample extends HornetQExample
+{
+   public static void main(String[] args)
+   {
+      new ReattachExample().run(args);
+   }
+
+   public boolean runExample() throws Exception
+   {
+      Connection connection = null;
+      InitialContext initialContext = null;
+
+      try
+      {
+         // Step 1. Create an initial context to perform the JNDI lookup.
+         initialContext = getContext(0);
+
+         // Step 2. Perform a lookup on the queue
+         Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
+
+         // Step 3. Perform a lookup on the Connection Factory
+         ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
+
+         // Step 4. Create a JMS Connection
+         connection = cf.createConnection();
+
+         // Step 5. Create a JMS Session
+         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         // Step 6. Create a JMS Message Producer
+         MessageProducer producer = session.createProducer(queue);
+
+         // Step 7. Create a Text Message
+         TextMessage message = session.createTextMessage("This is a text message");
+
+         System.out.println("Sent message: " + message.getText());
+
+         // Step 8. Send the Message
+         producer.send(message);
+
+         // Step 9. Create a JMS Message Consumer
+         MessageConsumer messageConsumer = session.createConsumer(queue);
+
+         // Step 10. Start the Connection
+         connection.start();
+
+         // Step 11. To simulate a temporary problem on the network, we stop the remoting acceptor on the
+         // server which will close all connections
+         stopAcceptor(initialContext);
+
+         System.out.println("Acceptor now stopped, will wait for 10 seconds. This simulates the network connection failing for a while");
+
+         // Step 12. Wait a while then restart the acceptor
+         Thread.sleep(10000);
+
+         System.out.println("Re-starting acceptor");
+
+         startAcceptor(initialContext);
+
+         System.out.println("Restarted acceptor. The client will now reconnect.");
+
+         // Step 13. We receive the message
+         TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000);
+
+         System.out.println("Received message: " + messageReceived.getText());
+
+         return true;
+      }
+      finally
+      {
+         // Step 14. Be sure to close our JMS resources!
+         if (initialContext != null)
+         {
+            initialContext.close();
+         }
+
+         if (connection != null)
+         {
+            connection.close();
+         }
+      }
+   }
+
+   private void stopAcceptor(InitialContext ic) throws Exception
+   {
+      this.stopStartAcceptor(ic, true);
+   }
+
+   private void startAcceptor(InitialContext ic) throws Exception
+   {
+      this.stopStartAcceptor(ic, false);
+   }
+
+   // To do this we send a management message to close the acceptor, we do this on a different
+   // connection factory which uses a different remoting connection so we can still send messages
+   // when the main connection has been stopped
+   private void stopStartAcceptor(InitialContext initialContext, boolean stop) throws Exception
+   {
+      ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory2");
+
+      Connection connection = null;
+      try
+      {
+         connection = cf.createConnection();
+
+         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         Queue managementQueue = new HornetQQueue("hornetq.management", "hornetq.management");
+
+         MessageProducer producer = session.createProducer(managementQueue);
+
+         connection.start();
+
+         Message m = session.createMessage();
+
+         String oper = stop ? "stop" : "start";
+
+         JMSManagementHelper.putOperationInvocation(m, "core.acceptor.netty-acceptor", oper);
+
+         producer.send(m);
+      }
+      finally
+      {
+         if (connection != null)
+         {
+            connection.close();
+         }
+      }
+   }
+
+}

Deleted: trunk/examples/jms/reconnect-same-node/src/org/hornetq/jms/example/ReconnectSameNodeExample.java
===================================================================
--- trunk/examples/jms/reconnect-same-node/src/org/hornetq/jms/example/ReconnectSameNodeExample.java	2009-11-28 22:57:54 UTC (rev 8453)
+++ trunk/examples/jms/reconnect-same-node/src/org/hornetq/jms/example/ReconnectSameNodeExample.java	2009-11-29 15:09:08 UTC (rev 8454)
@@ -1,166 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat licenses this file to you under the Apache License, version
- * 2.0 (the "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *    http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied.  See the License for the specific language governing
- * permissions and limitations under the License.
- */
-package org.hornetq.jms.example;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.naming.InitialContext;
-
-import org.hornetq.common.example.HornetQExample;
-import org.hornetq.jms.HornetQQueue;
-import org.hornetq.jms.server.management.impl.JMSManagementHelper;
-
-/**
- * This examples demonstrates a connection created to a server. Failure of the network connection is then simulated
- * 
- * The network is brought back up and the client reconnects and resumes transparently.
- *
- * @author <a href="tim.fox at jboss.com>Tim Fox</a>
- */
-public class ReconnectSameNodeExample extends HornetQExample
-{
-   public static void main(String[] args)
-   {
-      new ReconnectSameNodeExample().run(args);
-   }
-
-   public boolean runExample() throws Exception
-   {
-      Connection connection = null;
-      InitialContext initialContext = null;
-
-      try
-      {
-         // Step 1. Create an initial context to perform the JNDI lookup.
-         initialContext = getContext(0);
-
-         // Step 2. Perform a lookup on the queue
-         Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
-
-         // Step 3. Perform a lookup on the Connection Factory
-         ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
-         // Step 4. Create a JMS Connection
-         connection = cf.createConnection();
-
-         // Step 5. Create a JMS Session
-         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-         // Step 6. Create a JMS Message Producer
-         MessageProducer producer = session.createProducer(queue);
-
-         // Step 7. Create a Text Message
-         TextMessage message = session.createTextMessage("This is a text message");
-
-         System.out.println("Sent message: " + message.getText());
-
-         // Step 8. Send the Message
-         producer.send(message);
-
-         // Step 9. Create a JMS Message Consumer
-         MessageConsumer messageConsumer = session.createConsumer(queue);
-
-         // Step 10. Start the Connection
-         connection.start();
-
-         // Step 11. To simulate a temporary problem on the network, we stop the remoting acceptor on the
-         // server which will close all connections
-         stopAcceptor(initialContext);
-
-         System.out.println("Acceptor now stopped, will wait for 10 seconds. This simulates the network connection failing for a while");
-
-         // Step 12. Wait a while then restart the acceptor
-         Thread.sleep(10000);
-
-         System.out.println("Re-starting acceptor");
-
-         startAcceptor(initialContext);
-
-         System.out.println("Restarted acceptor. The client will now reconnect.");
-
-         // Step 13. We receive the message
-         TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000);
-
-         System.out.println("Received message: " + messageReceived.getText());
-
-         return true;
-      }
-      finally
-      {
-         // Step 14. Be sure to close our JMS resources!
-         if (initialContext != null)
-         {
-            initialContext.close();
-         }
-
-         if (connection != null)
-         {
-            connection.close();
-         }
-      }
-   }
-
-   private void stopAcceptor(InitialContext ic) throws Exception
-   {
-      this.stopStartAcceptor(ic, true);
-   }
-
-   private void startAcceptor(InitialContext ic) throws Exception
-   {
-      this.stopStartAcceptor(ic, false);
-   }
-
-   // To do this we send a management message to close the acceptor, we do this on a different
-   // connection factory which uses a different remoting connection so we can still send messages
-   // when the main connection has been stopped
-   private void stopStartAcceptor(InitialContext initialContext, boolean stop) throws Exception
-   {
-      ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory2");
-
-      Connection connection = null;
-      try
-      {
-         connection = cf.createConnection();
-
-         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-         Queue managementQueue = new HornetQQueue("hornetq.management", "hornetq.management");
-
-         MessageProducer producer = session.createProducer(managementQueue);
-
-         connection.start();
-
-         Message m = session.createMessage();
-
-         String oper = stop ? "stop" : "start";
-
-         JMSManagementHelper.putOperationInvocation(m, "core.acceptor.netty-acceptor", oper);
-
-         producer.send(m);
-      }
-      finally
-      {
-         if (connection != null)
-         {
-            connection.close();
-         }
-      }
-   }
-
-}



More information about the hornetq-commits mailing list