You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2006/11/14 03:12:37 UTC

svn commit: r474626 [2/7] - /incubator/activemq/site/

Modified: incubator/activemq/site/cms.html
URL: http://svn.apache.org/viewvc/incubator/activemq/site/cms.html?view=diff&rev=474626&r1=474625&r2=474626
==============================================================================
--- incubator/activemq/site/cms.html (original)
+++ incubator/activemq/site/cms.html Mon Nov 13 18:12:35 2006
@@ -272,6 +272,7 @@
 #include <cms/ExceptionListener.h>
 #include <cms/MessageListener.h>
 #include <stdlib.h>
+#include <iostream>
 
 using namespace activemq::core;
 using namespace activemq::util;
@@ -281,27 +282,29 @@
 
 class HelloWorldProducer : <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">Runnable</SPAN> {
 <SPAN class="code-keyword">private</SPAN>:
-	
-	Connection* connection;
-	Session* session;
-	Destination* destination;
-	MessageProducer* producer;
-	<SPAN class="code-object">int</SPAN> numMessages;
+    
+    Connection* connection;
+    Session* session;
+    Destination* destination;
+    MessageProducer* producer;
+    <SPAN class="code-object">int</SPAN> numMessages;
+    bool useTopic;
 
 <SPAN class="code-keyword">public</SPAN>:
-	
-	HelloWorldProducer( <SPAN class="code-object">int</SPAN> numMessages ){
-		connection = NULL;
-    	session = NULL;
-    	destination = NULL;
-    	producer = NULL;
-    	<SPAN class="code-keyword">this</SPAN>-&gt;numMessages = numMessages;
-	}
-	
-	virtual ~HelloWorldProducer(){
-		cleanup();
-	}
-	
+    
+    HelloWorldProducer( <SPAN class="code-object">int</SPAN> numMessages, bool useTopic = <SPAN class="code-keyword">false</SPAN> ){
+        connection = NULL;
+        session = NULL;
+        destination = NULL;
+        producer = NULL;
+        <SPAN class="code-keyword">this</SPAN>-&gt;numMessages = numMessages;
+        <SPAN class="code-keyword">this</SPAN>-&gt;useTopic = useTopic;
+    }
+    
+    virtual ~HelloWorldProducer(){
+        cleanup();
+    }
+    
     virtual void run() {
         <SPAN class="code-keyword">try</SPAN> {
             <SPAN class="code-comment">// Create a ConnectionFactory
@@ -315,7 +318,11 @@
 </SPAN>            session = connection-&gt;createSession( Session::AUTO_ACKNOWLEDGE );
 
             <SPAN class="code-comment">// Create the destination (Topic or Queue)
-</SPAN>            destination = session-&gt;createQueue( <SPAN class="code-quote">&quot;TEST.FOO&quot;</SPAN> );
+</SPAN>            <SPAN class="code-keyword">if</SPAN>( useTopic ) {
+                destination = session-&gt;createTopic( <SPAN class="code-quote">&quot;TEST.FOO&quot;</SPAN> );
+            } <SPAN class="code-keyword">else</SPAN> {
+                destination = session-&gt;createQueue( <SPAN class="code-quote">&quot;TEST.FOO&quot;</SPAN> );
+            }
 
             <SPAN class="code-comment">// Create a MessageProducer from the Session to the Topic or Queue
 </SPAN>            producer = session-&gt;createProducer( destination );
@@ -328,15 +335,15 @@
 </SPAN>            string text = (string)<SPAN class="code-quote">&quot;Hello world! from thread &quot;</SPAN> + threadIdStr;
             
             <SPAN class="code-keyword">for</SPAN>( <SPAN class="code-object">int</SPAN> ix=0; ix&lt;numMessages; ++ix ){
-	            TextMessage* message = session-&gt;createTextMessage( text );
+                TextMessage* message = session-&gt;createTextMessage( text );
 
-    	        <SPAN class="code-comment">// Tell the producer to send the message
-</SPAN>        	    printf( <SPAN class="code-quote">&quot;Sent message from thread %s\n&quot;</SPAN>, threadIdStr.c_str() );
-            	producer-&gt;send( message );
-            	
-            	delete message;
+                <SPAN class="code-comment">// Tell the producer to send the message
+</SPAN>                printf( <SPAN class="code-quote">&quot;Sent message from thread %s\n&quot;</SPAN>, threadIdStr.c_str() );
+                producer-&gt;send( message );
+                
+                delete message;
             }
-			
+            
         }<SPAN class="code-keyword">catch</SPAN> ( CMSException&amp; e ) {
             e.printStackTrace();
         }
@@ -345,63 +352,65 @@
 <SPAN class="code-keyword">private</SPAN>:
 
     void cleanup(){
-    				
-			<SPAN class="code-comment">// Destroy resources.
-</SPAN>			<SPAN class="code-keyword">try</SPAN>{                        
-            	<SPAN class="code-keyword">if</SPAN>( destination != NULL ) delete destination;
-			}<SPAN class="code-keyword">catch</SPAN> ( CMSException&amp; e ) {}
-			destination = NULL;
-			
-			<SPAN class="code-keyword">try</SPAN>{
-	            <SPAN class="code-keyword">if</SPAN>( producer != NULL ) delete producer;
-			}<SPAN class="code-keyword">catch</SPAN> ( CMSException&amp; e ) {}
-			producer = NULL;
-			
-    		<SPAN class="code-comment">// Close open resources.
-</SPAN>    		<SPAN class="code-keyword">try</SPAN>{
-    			<SPAN class="code-keyword">if</SPAN>( session != NULL ) session-&gt;close();
-    			<SPAN class="code-keyword">if</SPAN>( connection != NULL ) connection-&gt;close();
-			}<SPAN class="code-keyword">catch</SPAN> ( CMSException&amp; e ) {}
-
-			<SPAN class="code-keyword">try</SPAN>{
-            	<SPAN class="code-keyword">if</SPAN>( session != NULL ) delete session;
-			}<SPAN class="code-keyword">catch</SPAN> ( CMSException&amp; e ) {}
-			session = NULL;
-			
+                    
+            <SPAN class="code-comment">// Destroy resources.
+</SPAN>            <SPAN class="code-keyword">try</SPAN>{                        
+                <SPAN class="code-keyword">if</SPAN>( destination != NULL ) delete destination;
+            }<SPAN class="code-keyword">catch</SPAN> ( CMSException&amp; e ) {}
+            destination = NULL;
+            
+            <SPAN class="code-keyword">try</SPAN>{
+                <SPAN class="code-keyword">if</SPAN>( producer != NULL ) delete producer;
+            }<SPAN class="code-keyword">catch</SPAN> ( CMSException&amp; e ) {}
+            producer = NULL;
+            
+            <SPAN class="code-comment">// Close open resources.
+</SPAN>            <SPAN class="code-keyword">try</SPAN>{
+                <SPAN class="code-keyword">if</SPAN>( session != NULL ) session-&gt;close();
+                <SPAN class="code-keyword">if</SPAN>( connection != NULL ) connection-&gt;close();
+            }<SPAN class="code-keyword">catch</SPAN> ( CMSException&amp; e ) {}
+
+            <SPAN class="code-keyword">try</SPAN>{
+                <SPAN class="code-keyword">if</SPAN>( session != NULL ) delete session;
+            }<SPAN class="code-keyword">catch</SPAN> ( CMSException&amp; e ) {}
+            session = NULL;
+            
             <SPAN class="code-keyword">try</SPAN>{
-            	<SPAN class="code-keyword">if</SPAN>( connection != NULL ) delete connection;
-			}<SPAN class="code-keyword">catch</SPAN> ( CMSException&amp; e ) {}
-    		connection = NULL;
+                <SPAN class="code-keyword">if</SPAN>( connection != NULL ) delete connection;
+            }<SPAN class="code-keyword">catch</SPAN> ( CMSException&amp; e ) {}
+            connection = NULL;
     }
 };
 
 class HelloWorldConsumer : <SPAN class="code-keyword">public</SPAN> ExceptionListener, 
                            <SPAN class="code-keyword">public</SPAN> MessageListener,
                            <SPAN class="code-keyword">public</SPAN> <SPAN class="code-object">Runnable</SPAN> {
-	
+    
 <SPAN class="code-keyword">private</SPAN>:
-	
-	Connection* connection;
-	Session* session;
-	Destination* destination;
-	MessageConsumer* consumer;
-	<SPAN class="code-object">long</SPAN> waitMillis;
-		
+    
+    Connection* connection;
+    Session* session;
+    Destination* destination;
+    MessageConsumer* consumer;
+    <SPAN class="code-object">long</SPAN> waitMillis;
+    bool useTopic;
+        
 <SPAN class="code-keyword">public</SPAN>: 
 
-	HelloWorldConsumer( <SPAN class="code-object">long</SPAN> waitMillis ){
-		connection = NULL;
-    	session = NULL;
-    	destination = NULL;
-    	consumer = NULL;
-    	<SPAN class="code-keyword">this</SPAN>-&gt;waitMillis = waitMillis;
-	}
-    virtual ~HelloWorldConsumer(){    	
-    	cleanup();
+    HelloWorldConsumer( <SPAN class="code-object">long</SPAN> waitMillis, bool useTopic = <SPAN class="code-keyword">false</SPAN> ){
+        connection = NULL;
+        session = NULL;
+        destination = NULL;
+        consumer = NULL;
+        <SPAN class="code-keyword">this</SPAN>-&gt;waitMillis = waitMillis;
+        <SPAN class="code-keyword">this</SPAN>-&gt;useTopic = useTopic;
+    }
+    virtual ~HelloWorldConsumer(){      
+        cleanup();
     }
     
     virtual void run() {
-    	    	
+                
         <SPAN class="code-keyword">try</SPAN> {
 
             <SPAN class="code-comment">// Create a ConnectionFactory
@@ -419,7 +428,11 @@
 </SPAN>            session = connection-&gt;createSession( Session::AUTO_ACKNOWLEDGE );
 
             <SPAN class="code-comment">// Create the destination (Topic or Queue)
-</SPAN>            destination = session-&gt;createQueue( <SPAN class="code-quote">&quot;TEST.FOO&quot;</SPAN> );
+</SPAN>            <SPAN class="code-keyword">if</SPAN>( useTopic ) {
+                destination = session-&gt;createTopic( <SPAN class="code-quote">&quot;TEST.FOO&quot;</SPAN> );
+            } <SPAN class="code-keyword">else</SPAN> {
+                destination = session-&gt;createQueue( <SPAN class="code-quote">&quot;TEST.FOO&quot;</SPAN> );
+            }
 
             <SPAN class="code-comment">// Create a MessageConsumer from the Session to the Topic or Queue
 </SPAN>            consumer = session-&gt;createConsumer( destination );
@@ -427,79 +440,109 @@
             consumer-&gt;setMessageListener( <SPAN class="code-keyword">this</SPAN> );
             
             <SPAN class="code-comment">// Sleep <SPAN class="code-keyword">while</SPAN> asynchronous messages come in.
-</SPAN>            <SPAN class="code-object">Thread</SPAN>::sleep( waitMillis );		
+</SPAN>            <SPAN class="code-object">Thread</SPAN>::sleep( waitMillis );        
             
         } <SPAN class="code-keyword">catch</SPAN> (CMSException&amp; e) {
             e.printStackTrace();
         }
     }
     
-    virtual void onMessage( <SPAN class="code-keyword">const</SPAN> Message* message ){
-    	
+    <SPAN class="code-comment">// Called from the consumer since <SPAN class="code-keyword">this</SPAN> class is a registered MessageListener.
+</SPAN>    virtual void onMessage( <SPAN class="code-keyword">const</SPAN> Message* message ){
+        
+        <SPAN class="code-keyword">static</SPAN> <SPAN class="code-object">int</SPAN> count = 0;
+        
         <SPAN class="code-keyword">try</SPAN>
         {
-    	    <SPAN class="code-keyword">const</SPAN> TextMessage* textMessage = 
+            count++;
+            <SPAN class="code-keyword">const</SPAN> TextMessage* textMessage = 
                 dynamic_cast&lt; <SPAN class="code-keyword">const</SPAN> TextMessage* &gt;( message );
             string text = textMessage-&gt;getText();
-            printf( <SPAN class="code-quote">&quot;Received: %s\n&quot;</SPAN>, text.c_str() );
+            printf( <SPAN class="code-quote">&quot;Message #%d Received: %s\n&quot;</SPAN>, count, text.c_str() );
         } <SPAN class="code-keyword">catch</SPAN> (CMSException&amp; e) {
             e.printStackTrace();
         }
     }
 
-    virtual void onException( <SPAN class="code-keyword">const</SPAN> CMSException&amp; ex ) {
+    <SPAN class="code-comment">// If something bad happens you see it here as <SPAN class="code-keyword">this</SPAN> class is also been
+</SPAN>    <SPAN class="code-comment">// registered as an ExceptionListener with the connection.
+</SPAN>    virtual void onException( <SPAN class="code-keyword">const</SPAN> CMSException&amp; ex ) {
         printf(<SPAN class="code-quote">&quot;JMS Exception occured.  Shutting down client.\n&quot;</SPAN>);
     }
     
 <SPAN class="code-keyword">private</SPAN>:
 
     void cleanup(){
-    	
-		<SPAN class="code-comment">// Destroy resources.
-</SPAN>		<SPAN class="code-keyword">try</SPAN>{                        
-        	<SPAN class="code-keyword">if</SPAN>( destination != NULL ) delete destination;
-		}<SPAN class="code-keyword">catch</SPAN> (CMSException&amp; e) {}
-		destination = NULL;
-		
-		<SPAN class="code-keyword">try</SPAN>{
+        
+        <SPAN class="code-comment">//*************************************************
+</SPAN>        <SPAN class="code-comment">// Always close destination, consumers and producers before
+</SPAN>        <SPAN class="code-comment">// you destroy their sessions and connection.
+</SPAN>        <SPAN class="code-comment">//*************************************************
+</SPAN>        
+        <SPAN class="code-comment">// Destroy resources.
+</SPAN>        <SPAN class="code-keyword">try</SPAN>{                        
+            <SPAN class="code-keyword">if</SPAN>( destination != NULL ) delete destination;
+        }<SPAN class="code-keyword">catch</SPAN> (CMSException&amp; e) {}
+        destination = NULL;
+        
+        <SPAN class="code-keyword">try</SPAN>{
             <SPAN class="code-keyword">if</SPAN>( consumer != NULL ) delete consumer;
-		}<SPAN class="code-keyword">catch</SPAN> (CMSException&amp; e) {}
-		consumer = NULL;
-		
-		<SPAN class="code-comment">// Close open resources.
-</SPAN>		<SPAN class="code-keyword">try</SPAN>{
-			<SPAN class="code-keyword">if</SPAN>( session != NULL ) session-&gt;close();
-			<SPAN class="code-keyword">if</SPAN>( connection != NULL ) connection-&gt;close();
-		}<SPAN class="code-keyword">catch</SPAN> (CMSException&amp; e) {}
-		
+        }<SPAN class="code-keyword">catch</SPAN> (CMSException&amp; e) {}
+        consumer = NULL;
+        
+        <SPAN class="code-comment">// Close open resources.
+</SPAN>        <SPAN class="code-keyword">try</SPAN>{
+            <SPAN class="code-keyword">if</SPAN>( session != NULL ) session-&gt;close();
+            <SPAN class="code-keyword">if</SPAN>( connection != NULL ) connection-&gt;close();
+        }<SPAN class="code-keyword">catch</SPAN> (CMSException&amp; e) {}
+        
+        <SPAN class="code-comment">// Now Destroy them
+</SPAN>        <SPAN class="code-keyword">try</SPAN>{
+            <SPAN class="code-keyword">if</SPAN>( session != NULL ) delete session;
+        }<SPAN class="code-keyword">catch</SPAN> (CMSException&amp; e) {}
+        session = NULL;
+        
         <SPAN class="code-keyword">try</SPAN>{
-        	<SPAN class="code-keyword">if</SPAN>( session != NULL ) delete session;
-		}<SPAN class="code-keyword">catch</SPAN> (CMSException&amp; e) {}
-		session = NULL;
-		
-		<SPAN class="code-keyword">try</SPAN>{
-        	<SPAN class="code-keyword">if</SPAN>( connection != NULL ) delete connection;
-		}<SPAN class="code-keyword">catch</SPAN> (CMSException&amp; e) {}
-		connection = NULL;
+            <SPAN class="code-keyword">if</SPAN>( connection != NULL ) delete connection;
+        }<SPAN class="code-keyword">catch</SPAN> (CMSException&amp; e) {}
+        connection = NULL;
     }
 };
     
 <SPAN class="code-object">int</SPAN> main(<SPAN class="code-object">int</SPAN> argc, <SPAN class="code-object">char</SPAN>* argv[]) {
+
+    std::cout &lt;&lt; <SPAN class="code-quote">&quot;=====================================================\n&quot;</SPAN>;    
+    std::cout &lt;&lt; <SPAN class="code-quote">&quot;Starting the example:&quot;</SPAN> &lt;&lt; std::endl;
+    std::cout &lt;&lt; <SPAN class="code-quote">&quot;-----------------------------------------------------\n&quot;</SPAN>;
+
+    <SPAN class="code-comment">//============================================================
+</SPAN>    <SPAN class="code-comment">// set to <SPAN class="code-keyword">true</SPAN> to use topics instead of queues
+</SPAN>    <SPAN class="code-comment">// Note in the code above that <SPAN class="code-keyword">this</SPAN> causes createTopic or
+</SPAN>    <SPAN class="code-comment">// createQueue to be used in both consumer an producer.
+</SPAN>    <SPAN class="code-comment">//============================================================    
+</SPAN>    bool useTopics = <SPAN class="code-keyword">false</SPAN>;  
+
+    HelloWorldProducer producer( 1000, useTopics );
+    HelloWorldConsumer consumer( 8000, useTopics );
+    
+    <SPAN class="code-comment">// Start the consumer thread.
+</SPAN>    <SPAN class="code-object">Thread</SPAN> consumerThread( &amp;consumer );
+    consumerThread.start();
     
-    HelloWorldProducer producer( 1000 );
-	HelloWorldConsumer consumer( 5000 );
-	
-	<SPAN class="code-comment">// Start the consumer thread.
-</SPAN>	<SPAN class="code-object">Thread</SPAN> consumerThread( &amp;consumer );
-	consumerThread.start();
-	
-	<SPAN class="code-comment">// Start the producer thread.
-</SPAN>	<SPAN class="code-object">Thread</SPAN> producerThread( &amp;producer );
-	producerThread.start();
-
-	<SPAN class="code-comment">// Wait <SPAN class="code-keyword">for</SPAN> the threads to complete.
-</SPAN>	producerThread.join();
-	consumerThread.join();
+    <SPAN class="code-comment">// Start the producer thread.
+</SPAN>    <SPAN class="code-object">Thread</SPAN> producerThread( &amp;producer );
+    producerThread.start();
+
+    <SPAN class="code-comment">// Wait <SPAN class="code-keyword">for</SPAN> the threads to complete.
+</SPAN>    producerThread.join();
+    consumerThread.join();
+
+    std::cout &lt;&lt; <SPAN class="code-quote">&quot;-----------------------------------------------------\n&quot;</SPAN>;    
+    std::cout &lt;&lt; <SPAN class="code-quote">&quot;Finished with the example, ignore errors from <SPAN class="code-keyword">this</SPAN>&quot;</SPAN> 
+              &lt;&lt; std::endl
+              &lt;&lt; <SPAN class="code-quote">&quot;point on as the sockets breaks when we shutdown.&quot;</SPAN>
+              &lt;&lt; std::endl;
+    std::cout &lt;&lt; <SPAN class="code-quote">&quot;=====================================================\n&quot;</SPAN>;    
 }</PRE>
 </DIV></DIV></DIV>
           

Modified: incubator/activemq/site/connectivity.html
URL: http://svn.apache.org/viewvc/incubator/activemq/site/connectivity.html?view=diff&rev=474626&r1=474625&r2=474626
==============================================================================
--- incubator/activemq/site/connectivity.html (original)
+++ incubator/activemq/site/connectivity.html Mon Nov 13 18:12:35 2006
@@ -41,7 +41,7 @@
           </TD>
           <TD align="right" valign="middle" nowrap="">
             <DIV id="site-quicklinks">
-<P><A href="downloa2.html" title="Downloa2">Downloa2</A> &#124; <SPAN class="nobr"><A href="http://incubator.apache.org/activemq/maven/activemq-core/apidocs/" title="Visit page outside Confluence" rel="nofollow">JavaDocs<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> <A href="javadocs.html" title="JavaDocs">More...</A> &#124; <A href="source.html" title="Source">Source</A> &#124; <A href="site.html" title="Site">Wiki</A> &#124;<SPAN class="nobr"><A href="irc://irc.codehaus.org/activemq" title="Visit page outside Confluence" rel="nofollow">IRC<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> &#124; <SPAN class="nobr"><A href="http://servlet.uwyn.com/drone/log/hausbot/activemq" title="Visit page outside Confluence" rel="nofollow">IRC Log<SUP><IMG cl
 ass="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> &#124; <A href="mailing-lists.html" title="Mailing Lists">Mailing Lists</A> &#124; <A href="discussion-forums.html" title="Discussion Forums">Discussion Forums</A> &#124; <A href="support.html" title="Support">Support</A></P>
+<P><A href="download.html" title="Download">Download</A> &#124; <SPAN class="nobr"><A href="http://incubator.apache.org/activemq/maven/activemq-core/apidocs/" title="Visit page outside Confluence" rel="nofollow">JavaDocs<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> <A href="javadocs.html" title="JavaDocs">More...</A> &#124; <A href="source.html" title="Source">Source</A> &#124; <A href="site.html" title="Site">Wiki</A> &#124;<SPAN class="nobr"><A href="irc://irc.codehaus.org/activemq" title="Visit page outside Confluence" rel="nofollow">IRC<SUP><IMG class="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> &#124; <SPAN class="nobr"><A href="http://servlet.uwyn.com/drone/log/hausbot/activemq" title="Visit page outside Confluence" rel="nofollow">IRC Log<SUP><IMG cl
 ass="rendericon" src="http://goopen.org/confluence/images/icons/linkext7.gif" height="0" width="0" align="absmiddle" alt="" border="0"></SUP></A></SPAN> &#124; <A href="mailing-lists.html" title="Mailing Lists">Mailing Lists</A> &#124; <A href="discussion-forums.html" title="Discussion Forums">Discussion Forums</A> &#124; <A href="support.html" title="Support">Support</A></P>
             </DIV>
           </TD>
         </TR> 
@@ -74,7 +74,7 @@
 	<LI><A href="faq.html" title="FAQ">FAQ</A></LI>
 	<LI><A href="site.html" title="Site">Site</A></LI>
 	<LI><A href="articles.html" title="Articles">Articles</A></LI>
-	<LI><A href="downloa2.html" title="Downloa2">Downloa2</A></LI>
+	<LI><A href="download.html" title="Download">Download</A></LI>
 </UL>