[jboss-cvs] JBoss Messaging SVN: r6371 - in trunk: examples/jms and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 8 12:17:01 EDT 2009


Author: jmesnil
Date: 2009-04-08 12:17:01 -0400 (Wed, 08 Apr 2009)
New Revision: 6371

Added:
   trunk/examples/jms/management/
   trunk/examples/jms/management/build.xml
   trunk/examples/jms/management/readme.html
   trunk/examples/jms/management/server0/
   trunk/examples/jms/management/server0/client-jndi.properties
   trunk/examples/jms/management/server0/jbm-configuration.xml
   trunk/examples/jms/management/server0/jbm-jms.xml
   trunk/examples/jms/management/server0/jbm-queues.xml
   trunk/examples/jms/management/server0/jbm-security.xml
   trunk/examples/jms/management/server0/jbm-standalone-beans.xml
   trunk/examples/jms/management/src/
   trunk/examples/jms/management/src/org/
   trunk/examples/jms/management/src/org/jboss/
   trunk/examples/jms/management/src/org/jboss/jms/
   trunk/examples/jms/management/src/org/jboss/jms/example/
   trunk/examples/jms/management/src/org/jboss/jms/example/ManagementExample.java
Modified:
   trunk/.classpath
Log:
Management Example

* example to show how to manage JBoss Messaging by sending JMS *management* messags

Modified: trunk/.classpath
===================================================================
--- trunk/.classpath	2009-04-08 15:55:54 UTC (rev 6370)
+++ trunk/.classpath	2009-04-08 16:17:01 UTC (rev 6371)
@@ -35,6 +35,7 @@
 	<classpathentry kind="src" path="examples/jms/topic-selector-example1/src"/>
 	<classpathentry kind="src" path="examples/jms/topic-selector-example2/src"/>
 	<classpathentry kind="src" path="examples/jms/transactional/src"/>
+	<classpathentry kind="src" path="examples/jms/management/src"/>
 	<classpathentry kind="lib" path="thirdparty/apache-log4j/lib/log4j.jar"/>
 	<classpathentry kind="lib" path="thirdparty/junit/lib/junit.jar"/>
 	<classpathentry kind="lib" path="thirdparty/jboss/profiler/jvmti/lib/jboss-profiler-jvmti.jar"/>


Property changes on: trunk/examples/jms/management
___________________________________________________________________
Name: svn:ignore
   + build
logs


Added: trunk/examples/jms/management/build.xml
===================================================================
--- trunk/examples/jms/management/build.xml	                        (rev 0)
+++ trunk/examples/jms/management/build.xml	2009-04-08 16:17:01 UTC (rev 6371)
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+      <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+      ]>
+
+<!-- =========================================================================================== -->
+<!--                                                                                             -->
+<!-- JBoss, Home of Professional Open Source                                                     -->
+<!-- Copyright 2005, JBoss Inc., and individual contributors as indicated                        -->
+<!-- by the @authors tag. See the copyright.txt in the distribution for a                        -->
+<!-- full listing of individual contributors.                                                    -->
+<!--                                                                                             -->
+<!-- This is free software; you can redistribute it and/or modify it                             -->
+<!-- under the terms of the GNU Lesser General Public License as                                 -->
+<!-- published by the Free Software Foundation; either version 2.1 of                            -->
+<!-- the License, or (at your option) any later version.                                         -->
+<!--                                                                                             -->
+<!-- This software is distributed in the hope that it will be useful,                            -->
+<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of                              -->
+<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU                            -->
+<!-- Lesser General Public License for more details.                                             -->
+<!--                                                                                             -->
+<!-- You should have received a copy of the GNU Lesser General Public                            -->
+<!-- License along with this software; if not, write to the Free                                 -->
+<!-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA                          -->
+<!-- 02110-1301 USA, or see the FSF site: http://www.fsf.org.                                    -->
+<!--                                                                                             -->
+<!-- =========================================================================================== -->
+
+
+<project default="run" name="JBoss Messaging Management Example">
+
+   <import file="../common/build.xml"/>
+
+   <target name="run">
+      <antcall target="runExample">
+         <param name="example.classname" value="org.jboss.jms.example.ManagementExample"/>
+      </antcall>
+   </target>
+
+   <target name="runRemote">
+      <antcall target="runExample">
+         <param name="example.classname" value="org.jboss.jms.example.ManagementExample"/>
+         <param name="jbm.example.runServer" value="false"/>
+      </antcall>
+   </target>
+
+</project>
\ No newline at end of file

Added: trunk/examples/jms/management/readme.html
===================================================================
--- trunk/examples/jms/management/readme.html	                        (rev 0)
+++ trunk/examples/jms/management/readme.html	2009-04-08 16:17:01 UTC (rev 6371)
@@ -0,0 +1,200 @@
+<html>
+  <head>
+    <title>JBoss Messaging Management Example</title>
+    <link rel="stylesheet" type="text/css" href="../common/common.css">
+  </head>
+  <body>
+     <h1> Management Example</h1>
+     <p>This example shows how to manage JBoss Messaging using JMS Messages to invoke management operations on the server.</a></p>
+     <p>To manage JBoss Messaging using JMX, see the <a href="../jmx/readme.html">JMX</a> example.</p>
+     
+     <h2>Example configuration</h2>
+
+     <p>JBoss Messaging can be managed by sending JMS messages with specific properties to its <em>management</em> queue.</p>
+     </p>By default, the management name is called <code>jbm.management</code> but this can be configured in <a href="server0/jbm-configuration.xml">jbm-configuration.xml</a>
+     <pre>
+         <code>&lt;management-address&gt;jbm.management&lt;/management-address&gt;</code>
+     </pre>
+     
+     <p>The management queue requires a "special" user permission <code>manage</code> to be able to receive management messages.
+         This is configured in <a href="server0/jbm-queues.xml">jbm-queues.xml</a></p>
+     <pre>
+         <code>&lt;security match="jbm.management"&gt;
+            &lt;permission type="manage" roles="guest" /&gt;
+         &lt;/security&gt;</code>
+     </pre>
+     
+     <h2>Example step-by-step</h2>
+     <p><em>To run the example, simply type <code>ant</code> from this directory</em></p>
+     <ol>
+        <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get its properties from <a href="server0/client-jndi.properties">client-jndi.properties</a></li>
+        <pre>
+            <code>InitialContext initialContext = getContext(0);</code>
+        </pre>
+
+        <li>We look up the JMS queue object from JNDI</li>
+        <pre>
+            <code>Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");</code>
+        </pre>
+
+        <li>We look up the JMS connection factory object from JNDI</li>
+        <pre>
+            <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code>
+        </pre>
+
+        <li>We create a JMS connection</li>
+        <pre>
+            <code>connection = cf.createConnection();</code>
+        </pre>
+        
+        <li>We create a JMS session. The session is created as non transacted and will auto acknowledge messages.</li>
+        <pre>
+            <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
+        </pre>
+
+        <li>We create a JMS message producer on the session. This will be used to send the messages.</li>
+        <pre>
+            <code>MessageProducer messageProducer = session.createProducer(topic);</code>
+       </pre>
+
+        <li>We create a JMS text message that we are going to send.</li>
+        <pre>
+            <code>TextMessage message = session.createTextMessage("This is a text message");</code>
+        </pre>
+
+        <li>We send message to the queue</li>
+        <pre>
+            <code>messageProducer.send(message);</code>
+        </pre>
+
+        <p><em>Now that we have a message in the queue, we will manage the queue by retrieving the number of messages in the queue
+            (i.e. 1) and by removing the message which has been sent in step 8.</em></p>
+            
+        <li>We create the JMS management queue. This is a <em>special</em> queue which is not looked up from JNDI but instantiated directly</li>
+        <pre>
+            <code>Queue managementQueue = new JBossQueue("jbm.management", "jbm.management");</code>
+        </pre>
+
+        <li>We create a <code>QueueRequestor</code> to send messages to the management queue and receive replies (see <a href="../queue-requestor/readme.html">queue-requestor example</a>)</li>
+        <pre>
+            <code>QueueRequestor requestor = new QueueRequestor(session, managementQueue);</code>
+        </pre>
+
+        <li>We start the connection to receive replies on the requestor</li>
+        <pre>
+           <code>connection.start()</code>
+        </pre>
+        
+        <li>We create a JMS message which will be used as a <em>management</em> message</li>
+        <pre>
+            <code>Message m = session.createMessage();</code>
+        </pre>
+        
+        <li>a <em>management</em> message has well-defined properties that JBoss Messaging server needs to know to perform management operations.<br />
+            We use a helper class <a href="../../../docs/api/org/jboss/messaging/jms/server/management/impl/JMSManagementHelper.html">JMSManagementHelper</a> to fill these properties:
+            <ul>
+                <li>The name of the resource to manage <code>jms.queue.exampleQueue</code> 
+                    (i.e. <code>jms.queue</code> followed by the name of the queue as defined in <a href="server0/jbm-jms.xml">jbm-jms.xml</a>)</li>
+                <li>In our case, the name of the attribute to retrieve <code>MessageCount</code></li>
+            </ul>
+        </li>
+        <pre>
+            <code>JMSManagementHelper.putAttribute(m, "jms.queue.exampleQueue", "MessageCount");</code>
+        </pre>
+        
+        <li>We send the <em>management</em> message using the requestor and wait for a reply</li>
+        <pre>
+            <code>ObjectMessage reply = (ObjectMessage)requestor.request(m);</code>
+        </pre>
+        
+        <li>The attribute value is returned as the body of an <code>ObjectMessage</code> (in this case, the <code>MessageCount</code> is an integer)
+        <pre>
+            <code>int messageCount = (Integer) reply.getObject();
+            System.out.println(queue.getQueueName() + " contains " + messageCount + " messages");</code>
+        </pre>
+        
+        <li>We create another JMS message to use as a management message</li>
+        <pre>
+            <code>m = session.createMessage();</code>
+        </pre>
+        
+        <li>This time, we fill the <em>management</em> message with properties to <em>invoke</em> a management operation on the queue
+            <ul>
+                <li>the name of the resource <code>jms.queue.exampleQueue</code></li>
+                <li>the name of the management operation <code>removeMessage</code></li>
+                <li>any parameters required to invoke the management operations (in our case, the JMS Message ID of the message sent in step 8)</li>
+            </ul>
+        </li>
+        <pre>
+            <code>JMSManagementHelper.putOperationInvocation(m, "jms.queue.exampleQueue", "removeMessage", message.getJMSMessageID());</code>
+        </pre>
+        
+        <li>Again, we use the requestor to send the management message and wait for a reply</li>
+        <pre>
+            <code>reply = (ObjectMessage)requestor.request(m);</code>
+        </pre>
+        
+        <li>We use the helper class to check that the operation was successfully invoked on the server</li>
+        <pre>
+            <code>boolean success = JMSManagementHelper.hasOperationSucceeded(reply);
+            System.out.println("operation invocation has succeeded: " + success);</code>
+        </pre>
+        
+        <li>The return value of the operation invocation is returned as the body of an ObjectMessage
+            (in our case, the <code>removeMessage</code> method returns a boolean)</li>
+        <pre>
+            <code>boolean messageRemoved = (Boolean) reply.getObject();
+            System.out.println("message has been removed: " + messageRemoved);</code>
+        </pre>
+            
+        <p><em>We will now consume the message from the queue but there will be none: the message sent at step 8 was removed by the management operation</em></p>
+            
+        <li>We create a JMS message consumer on the queue</li>
+        <pre>
+            <code>MessageConsumer messageConsumer = session.createConsumer(queue);</code>
+        </pre>
+
+        <li>We try to receive a message from the queue. Since there is none, the call will timeout after 5000ms and messageReceived will be null
+        </li>
+        <pre>
+            <code>TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
+            System.out.println("Received message: " + messageReceived);</code>
+        </pre>
+        
+        <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
+
+        <pre>
+           <code>finally
+           {
+              if (initialContext != null)
+              {
+                initialContext.close();
+              }
+              if (connection != null)
+              {
+                 connection.close();
+              }
+           }</code>
+        </pre>
+     </ol>
+     
+     <h2>More information</h2>
+     
+     <h3>How do I know the attributes and operations that can be managed using JMS messages?</h3>
+     <p>The attributes and operations that can be invoked are the <strong>same</strong> than the ones defined by JBoss Messaging MBeans.</p>
+     JBoss Messaging defines a set of MBeans for this core 
+         API (<a href="../../../docs/api/org/jboss/messaging/core/management/package-summary.html">org.jboss.messaging.core.management</a>
+          package) and its JMS API (in the <a href="../../../docs/api/org/jboss/messaging/jms/server/management/package-summary.html">org.jboss.messaging.jms.server.management</a> package)</p>
+     <p><strong>Please note that management attributes start with an upper case  character(<code><u>M</u>essageCount</code>), <em>not a lower case </em></strong></p>      
+
+     <h3>How do I know the name of the resource to manage?</h3>
+     <p><a href="../../../docs/api/org/jboss/messaging/core/management/ResourceNames.html">ResourceNames</a> is a helper class used to build the name of JBoss Messaging resources by messages<br />
+     The convention is simple: <code>jms.queue.</code> followed by the name of the queue for a JMS queue, <code>jms.topic.</code> followed by the name of a topic for a JMS topic, etc.<br />
+     The name for the JMS server resource is <code>jms.server</code>
+     </p>
+     
+     <p>Management address can be configured in the <a href="../../../docs/userguide/en/html/configuration.html#configuration.main">server configuration</a> by changing the <code>management-address</code> parameter.</p>
+         
+
+  </body>
+</html>
\ No newline at end of file


Property changes on: trunk/examples/jms/management/server0
___________________________________________________________________
Name: svn:ignore
   + data
logs


Added: trunk/examples/jms/management/server0/client-jndi.properties
===================================================================
--- trunk/examples/jms/management/server0/client-jndi.properties	                        (rev 0)
+++ trunk/examples/jms/management/server0/client-jndi.properties	2009-04-08 16:17:01 UTC (rev 6371)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Added: trunk/examples/jms/management/server0/jbm-configuration.xml
===================================================================
--- trunk/examples/jms/management/server0/jbm-configuration.xml	                        (rev 0)
+++ trunk/examples/jms/management/server0/jbm-configuration.xml	2009-04-08 16:17:01 UTC (rev 6371)
@@ -0,0 +1,19 @@
+<deployment xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-configuration.xsd">
+   <configuration>
+
+      <management-address>jbm.management</management-address>
+
+      <connector name="netty">
+         <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+      </connector>
+
+      <!-- Netty standard TCP acceptor -->
+      <acceptor name="netty">
+         <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+      </acceptor>
+
+   </configuration>
+
+</deployment>

Added: trunk/examples/jms/management/server0/jbm-jms.xml
===================================================================
--- trunk/examples/jms/management/server0/jbm-jms.xml	                        (rev 0)
+++ trunk/examples/jms/management/server0/jbm-jms.xml	2009-04-08 16:17:01 UTC (rev 6371)
@@ -0,0 +1,17 @@
+<deployment xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-jms.xsd ">
+   <!--the connection factory used by the example-->
+   <connection-factory name="ConnectionFactory">
+      <connector-ref connector-name="netty"/>
+      <entry name="ConnectionFactory"/>
+      <entry name="XAConnectionFactory"/>
+      <entry name="java:/ConnectionFactory"/>
+      <entry name="java:/XAConnectionFactory"/>
+   </connection-factory>
+
+   <!--the queue used by the example-->
+   <queue name="exampleQueue">
+      <entry name="/queue/exampleQueue"/>
+   </queue>
+</deployment>
\ No newline at end of file

Added: trunk/examples/jms/management/server0/jbm-queues.xml
===================================================================
--- trunk/examples/jms/management/server0/jbm-queues.xml	                        (rev 0)
+++ trunk/examples/jms/management/server0/jbm-queues.xml	2009-04-08 16:17:01 UTC (rev 6371)
@@ -0,0 +1,27 @@
+<settings xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-queues.xsd ">
+
+   <!--security for example queue-->
+   <security match="jms.queue.exampleQueue">
+      <permission type="createDurableQueue" roles="guest"/>
+      <permission type="deleteDurableQueue" roles="guest"/>
+      <permission type="createTempQueue" roles="guest"/>
+      <permission type="deleteTempQueue" roles="guest"/>
+      <permission type="consume" roles="guest"/>
+      <permission type="send" roles="guest"/>
+   </security>
+
+   <!--security for management queue-->
+   <security match="jbm.management">
+      <permission type="manage" roles="guest" />
+   </security>
+   
+   <!-- security settings for JMS temporary queue -->
+   <security match="queuetempjms.*">
+      <permission type="createTempQueue" roles="guest"/>
+      <permission type="deleteTempQueue" roles="guest"/>
+      <permission type="consume" roles="guest"/>
+      <permission type="send" roles="guest"/>
+   </security>
+</settings>

Added: trunk/examples/jms/management/server0/jbm-security.xml
===================================================================
--- trunk/examples/jms/management/server0/jbm-security.xml	                        (rev 0)
+++ trunk/examples/jms/management/server0/jbm-security.xml	2009-04-08 16:17:01 UTC (rev 6371)
@@ -0,0 +1,7 @@
+<deployment xmlns="urn:jboss:messaging" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-security.xsd ">
+   <!-- the default user.  this is used where username is null-->
+   <defaultuser name="guest" password="guest">
+      <role name="guest"/>
+   </defaultuser>
+</deployment>
\ No newline at end of file

Added: trunk/examples/jms/management/server0/jbm-standalone-beans.xml
===================================================================
--- trunk/examples/jms/management/server0/jbm-standalone-beans.xml	                        (rev 0)
+++ trunk/examples/jms/management/server0/jbm-standalone-beans.xml	2009-04-08 16:17:01 UTC (rev 6371)
@@ -0,0 +1,174 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="Naming" class="org.jnp.server.NamingBeanImpl"/>
+
+   <!-- JNDI server. Disable this if you don't want JNDI -->
+   <bean name="JNDIServer" class="org.jnp.server.Main">
+      <property name="namingInfo">
+         <inject bean="Naming"/>
+      </property>
+      <property name="port">1099</property>
+      <property name="bindAddress">localhost</property>
+      <property name="rmiPort">1098</property>
+      <property name="rmiBindAddress">localhost</property>
+   </bean>
+
+   <bean name="DeploymentManager" class="org.jboss.messaging.core.deployers.impl.FileDeploymentManager">
+      <constructor>
+         <!-- The scan time in milliseconds -->
+         <parameter>5000</parameter>
+      </constructor>
+   </bean>
+   
+   <bean name="Configuration" class="org.jboss.messaging.core.config.impl.FileConfiguration"/>
+
+   <!--<bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JBossASSecurityManager"/>-->
+
+   <bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl">
+   </bean>
+
+   <bean name="BasicSecurityDeployer" class="org.jboss.messaging.core.deployers.impl.BasicSecurityDeployer">
+      <constructor>
+         <parameter>
+            <inject bean="DeploymentManager"/>
+         </parameter>
+      </constructor>
+      <property name="jbmSecurityManager">
+         <inject bean="JBMSecurityManager"/>
+      </property>
+   </bean>
+
+   <bean name="MessagingServer" class="org.jboss.messaging.core.server.impl.MessagingServerImpl">
+      <depends>AddressSettingsDeployer</depends>
+      <depends>QueueDeployer</depends>
+      
+      <property name="storageManager">
+         <inject bean="StorageManager"/>
+      </property>
+      <property name="remotingService">
+         <inject bean="RemotingService"/>
+      </property>
+      <property name="configuration">
+         <inject bean="Configuration"/>
+      </property>
+      <property name="securityManager">
+         <inject bean="JBMSecurityManager"/>
+      </property>
+      <property name="managementService">
+         <inject bean="ManagementService"/>
+      </property>      
+   </bean>
+
+   <bean name="StorageManager" class="org.jboss.messaging.core.persistence.impl.journal.JournalStorageManager">
+      <constructor>
+         <parameter>
+            <inject bean="Configuration"/>
+         </parameter>
+      </constructor>
+   </bean>
+
+   <bean name="RemotingService" class="org.jboss.messaging.core.remoting.server.impl.RemotingServiceImpl">
+      <constructor>
+         <parameter>
+            <inject bean="Configuration"/>
+         </parameter>
+      </constructor>
+      <property name="managementService">
+         <inject bean="ManagementService"/>
+      </property>
+   </bean>
+   
+   <bean name="JMSServerManager" class="org.jboss.messaging.jms.server.impl.JMSServerManagerImpl">
+      <constructor>
+         <parameter>
+            <inject bean="MessagingServer" property="serverManagement"/>
+         </parameter>
+         <parameter>
+            <inject bean="MessagingServer" property="postOffice"/>
+         </parameter>
+         <parameter>
+            <inject bean="MessagingServer" property="storageManager"/>
+         </parameter>
+         <parameter>
+            <inject bean="MessagingServer" property="addressSettingsRepository"/>
+         </parameter>
+         <parameter>
+            <inject bean="JMSManagementService"/>
+         </parameter>
+      </constructor>
+   </bean>
+
+   <bean name="JMSServerDeployer" class="org.jboss.messaging.jms.server.impl.JMSServerDeployer">
+      <constructor>
+         <parameter>
+            <inject bean="DeploymentManager"/>
+         </parameter>
+          <parameter>
+            <inject bean="Configuration"/>
+         </parameter>
+      </constructor>
+      <property name="jmsServerManager">
+         <inject bean="JMSServerManager"/>
+      </property>
+   </bean>
+
+   <bean name="AddressSettingsDeployer" class="org.jboss.messaging.core.deployers.impl.AddressSettingsDeployer">
+      <constructor>
+         <parameter>
+            <inject bean="DeploymentManager"/>
+         </parameter>
+         <parameter>
+            <inject bean="MessagingServer" property="addressSettingsRepository" state="Configured"/>
+         </parameter>
+      </constructor>
+   </bean>
+
+   <bean name="QueueDeployer" class="org.jboss.messaging.core.deployers.impl.QueueDeployer">
+      <constructor>
+         <parameter>
+            <inject bean="DeploymentManager"/>
+         </parameter>
+         <parameter>
+            <inject bean="Configuration"/>
+         </parameter>
+      </constructor>
+   </bean>
+   
+   <bean name="SecurityDeployer" class="org.jboss.messaging.core.deployers.impl.SecurityDeployer">
+      <constructor>
+         <parameter>
+            <inject bean="DeploymentManager"/>
+         </parameter>
+         <parameter>
+            <inject bean="MessagingServer" property="securityRepository"/>
+         </parameter>
+      </constructor>
+   </bean>
+
+   <bean name="ManagementService" class="org.jboss.messaging.core.management.impl.ManagementServiceImpl">
+      <constructor>
+         <parameter>
+            <inject bean="MBeanServer"/>
+         </parameter>
+         <parameter>
+            <inject bean="Configuration" property="JMXManagementEnabled" />
+         </parameter>
+      </constructor>
+   </bean>
+   
+   <bean name="JMSManagementService" class="org.jboss.messaging.jms.server.management.impl.JMSManagementServiceImpl">
+      <constructor>
+         <parameter>
+            <inject bean="ManagementService"/>
+         </parameter>
+      </constructor>
+   </bean>
+   
+   <bean name="MBeanServer" class="javax.management.MBeanServer">
+      <constructor factoryClass="java.lang.management.ManagementFactory"
+                   factoryMethod="getPlatformMBeanServer"/>
+   </bean> 
+   
+</deployment>
\ No newline at end of file

Added: trunk/examples/jms/management/src/org/jboss/jms/example/ManagementExample.java
===================================================================
--- trunk/examples/jms/management/src/org/jboss/jms/example/ManagementExample.java	                        (rev 0)
+++ trunk/examples/jms/management/src/org/jboss/jms/example/ManagementExample.java	2009-04-08 16:17:01 UTC (rev 6371)
@@ -0,0 +1,154 @@
+/*
+   * JBoss, Home of Professional Open Source
+   * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+   * by the @authors tag. See the copyright.txt in the distribution for a
+   * full listing of individual contributors.
+   *
+   * This is free software; you can redistribute it and/or modify it
+   * under the terms of the GNU Lesser General Public License as
+   * published by the Free Software Foundation; either version 2.1 of
+   * the License, or (at your option) any later version.
+   *
+   * This software is distributed in the hope that it will be useful,
+   * but WITHOUT ANY WARRANTY; without even the implied warranty of
+   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   * Lesser General Public License for more details.
+   *
+   * You should have received a copy of the GNU Lesser General Public
+   * License along with this software; if not, write to the Free
+   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+   */
+package org.jboss.jms.example;
+
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueRequestor;
+import javax.jms.QueueSession;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+
+import org.jboss.messaging.jms.JBossQueue;
+import org.jboss.messaging.jms.server.management.impl.JMSManagementHelper;
+
+/**
+ * An example that shows how to manage JBoss Messaging using JMS messages.
+ *
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ */
+public class ManagementExample extends JMSExample
+{
+   public static void main(String[] args)
+   {
+      new ManagementExample().run(args);
+   }
+
+   public boolean runExample() throws Exception
+   {
+      QueueConnection connection = null;
+      InitialContext initialContext = null;
+      try
+      {
+         // Step 1. Create an initial context to perform the JNDI lookup.
+         initialContext = getContext(0);
+
+         // Step 2. Perfom a lookup on the queue
+         Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
+         
+         // Step 3. Perform a lookup on the Connection Factory
+         QueueConnectionFactory cf = (QueueConnectionFactory) initialContext.lookup("/ConnectionFactory");
+
+         // Step 4.Create a JMS Connection
+         connection = cf.createQueueConnection();
+
+         // Step 5. Create a JMS Session
+         QueueSession session = connection.createQueueSession(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 the JMS management queue.
+         // It is a "special" queue and it is not looked up from JNDI but constructed directly
+         Queue managementQueue = new JBossQueue("jbm.management", "jbm.management");
+         
+         // Step 10. Create a QueueRequestor for the management queue (see queue-requestor example)
+         QueueRequestor requestor = new QueueRequestor(session, managementQueue);
+         
+         // Step 11. Start the Connection to allow the queue requestor to receive replies
+         connection.start();
+
+         // Step 12. Create a JMS message which is used to send a management message
+         Message m = session.createMessage();
+                  
+         // Step 13. Use a helper class to fill the JMS message with management information:
+         // * the name of the resource to manage
+         // * in this case, we want to retrieve the value of the MessageCount of the queue
+         JMSManagementHelper.putAttribute(m, "jms.queue.exampleQueue", "MessageCount");
+         
+         // Step 14. Use the requestor to send the request and wait for the reply
+         ObjectMessage reply = (ObjectMessage)requestor.request(m);
+
+         // Step 15. The attribute value is returned as the body of an ObjectMessage (in this case, an integer)
+         int messageCount = (Integer) reply.getObject();
+         System.out.println(queue.getQueueName() + " contains " + messageCount + " messages");
+         
+         // Step 16. Create another JMS message to use as a management message
+         m = session.createMessage();
+         
+         // Step 17. Use a helper class to fill the JMS message with management information:
+         // * the object name of the resource to manage (i.e. the queue)
+         // * in this case, we want to call the "removeMessage" operation with the JMS MessageID
+         //   of the message sent to the queue in step 8.
+         JMSManagementHelper.putOperationInvocation(m, "jms.queue.exampleQueue", "removeMessage", message.getJMSMessageID());
+
+         // Step 18 Use the requestor to send the request and wait for the reply
+         reply = (ObjectMessage)requestor.request(m);
+         
+         // Step 19. Use a helper class to check that the operation has succeeded
+         boolean success = JMSManagementHelper.hasOperationSucceeded(reply);
+         System.out.println("operation invocation has succeeded: " + success);
+
+         // Step 20. The return value of the operation invocation is returned as the body of an ObjectMessage
+         // in that case, a boolean which is true if the message was removed, false else
+         boolean messageRemoved = (Boolean) reply.getObject();
+         System.out.println("message has been removed: " + messageRemoved);
+         
+         // Step 21. Create a JMS Message Consumer on the queue
+         MessageConsumer messageConsumer = session.createConsumer(queue);
+
+         // Step 22. Trying to receive a message. Since the only message in the queue was removed by a management operation,
+         // there is none to consume. The call will timeout after 5000ms and messageReceived will be null
+         TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
+         System.out.println("Received message: " + messageReceived);
+
+         initialContext.close();
+         
+         return true;
+      }
+      finally
+      {
+         //Step 23. Be sure to close our JMS resources!
+         if (initialContext != null)
+         {
+            initialContext.close();
+         }
+         if(connection != null)
+         {
+            connection.close();
+         }
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list