[jboss-cvs] JBoss Messaging SVN: r2720 - in trunk/docs/examples: stateless-clustered and 10 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon May 21 08:47:45 EDT 2007


Author: sergeypk
Date: 2007-05-21 08:47:45 -0400 (Mon, 21 May 2007)
New Revision: 2720

Added:
   trunk/docs/examples/stateless-clustered/
   trunk/docs/examples/stateless-clustered/README.html
   trunk/docs/examples/stateless-clustered/build.xml
   trunk/docs/examples/stateless-clustered/etc/
   trunk/docs/examples/stateless-clustered/etc/META-INF/
   trunk/docs/examples/stateless-clustered/etc/META-INF/ejb-jar.xml
   trunk/docs/examples/stateless-clustered/etc/META-INF/jboss.xml
   trunk/docs/examples/stateless-clustered/etc/destinations-farm-service.xml
   trunk/docs/examples/stateless-clustered/etc/jndi.properties
   trunk/docs/examples/stateless-clustered/etc/log4j.xml
   trunk/docs/examples/stateless-clustered/src/
   trunk/docs/examples/stateless-clustered/src/org/
   trunk/docs/examples/stateless-clustered/src/org/jboss/
   trunk/docs/examples/stateless-clustered/src/org/jboss/example/
   trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/
   trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/
   trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/bean/
   trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/bean/StatelessClusteredSessionExample.java
   trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/bean/StatelessClusteredSessionExampleBean.java
   trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/bean/StatelessClusteredSessionExampleHome.java
   trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/client/
   trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/client/Client.java
Log:
http://jira.jboss.com/jira/browse/JBMESSAGING-966 - Clustered EJB example/smoke test.


Property changes on: trunk/docs/examples/stateless-clustered
___________________________________________________________________
Name: svn:ignore
   + output


Added: trunk/docs/examples/stateless-clustered/README.html
===================================================================
--- trunk/docs/examples/stateless-clustered/README.html	                        (rev 0)
+++ trunk/docs/examples/stateless-clustered/README.html	2007-05-21 12:47:45 UTC (rev 2720)
@@ -0,0 +1,131 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+  <meta content="text/html; charset=ISO-8859-1"
+    http-equiv="content-type">
+  <title>JBoss Messaging Example - Managed Environment</title>
+</head>
+<body>
+
+<h1>Sending JMS messages from a Stateless Clustered Session Bean</h1>
+
+<p>$Revision$</p>
+
+<h2>Overview</h2>
+<p>
+This example deploys in a cluster a stateless session bean that can then
+send and receive messages from a queue. This is a very simple example that
+demonstrates using JBoss Messaging in a managed clustered environment.
+The client uses HA-JNDI to look up the session bean. It then invokes the
+session bean to send a message to a test queue and afterwards pulls the
+message from the queue from a different connection using the JMS API
+directly. The example is considered successful if the message is received
+correctly.
+</p>
+<p>
+This example relies on having access to a running JBoss Messaging cluster.
+The JBoss Messaging cluster must be installed and started according to
+the "JBoss Messaging Clustered Installation" chapter from the release
+documentation.&nbsp; However, the example will automatically deploy its own
+queue, unless a queue with the same name is already deployed.
+</p>
+<p>
+This example also relies on having access to <tt>jboss-messaging-client.jar</tt>
+archive that comes with the release bundle. If you run this example
+from an unzipped installation bundle, the example run script is correctly
+configured to find the client jar. Otherwise, you must modify example's
+<tt>build.xml</tt> accordingly.
+</p>
+<p><em>
+The example was designed to deploy its server-side artifacts under a JBoss'
+<tt>messaging-node0</tt> configuration, into the <tt>farm</tt> directory.
+If you intend to use the script with a JBoss configuration that is named
+differently, please modify the example's <tt>build.xml</tt>.
+</em></p>
+
+<h2>Running the example</h2>
+<p>
+1. Set up the JBOSS_HOME environment variable to point to the JBoss
+instance you deployed JBoss Messaging into. For example, if you
+deployed JBoss Messaging in <tt>C:\jboss-4.2.0.GA\server\messaging-node0\deploy</tt>,
+then your JBOSS_HOME value should be <tt>C:\jboss-4.2.0.GA</tt>.
+</p>
+<p>
+2. Go to the example's home directory
+</p>
+<blockquote>
+  <pre>cd ...\examples\stateless</pre>
+</blockquote>
+<p>
+3. Run the example:
+</p>
+<blockquote>
+  <pre>ant</pre>
+</blockquote>
+<p>
+The output of a successful run should be similar to:
+</p>
+<blockquote>
+  <pre>$ ant
+Buildfile: build.xml
+
+identify:
+     [echo] ###########################################################################
+     [echo] #         Running the STATELESS CLUSTERED SESSION BEAN example            #
+     [echo] ###########################################################################
+     [echo] The queue:      testFarmQueue
+     [echo] The client jar: ../../../output/lib/jboss-messaging-client.jar
+
+sanity-check:
+
+init:
+    [mkdir] Created dir: C:\java\messaging\docs\examples\stateless-clustered\output\classes\META-INF
+    [mkdir] Created dir: C:\java\messaging\docs\examples\stateless-clustered\output\lib
+
+compile:
+    [javac] Compiling 4 source files to C:\java\messaging\docs\examples\stateless-clustered\output\classes
+    [javac] Note: C:\java\messaging\docs\examples\stateless-clustered\src\org\jboss\example\jms\statelessclustered\bean\StatelessClusteredSessionExampleBean.java uses unchecked or unsafe operations.
+    [javac] Note: Recompile with -Xlint:unchecked for details.
+
+jar:
+     [copy] Copying 2 files to C:\java\messaging\docs\examples\stateless-clustered\output\classes\META-INF
+      [jar] Building jar: C:\java\messaging\docs\examples\stateless-clustered\output\lib\stateless-clustered-example.jar
+
+deploy:
+     [copy] Copying 1 file to C:\jboss-4.2.0.GA\server\messaging-node0\farm
+     [copy] Copying 1 file to C:\jboss-4.2.0.GA\server\messaging-node0\farm
+
+sleep:
+     [echo] Sleeping for 15 seconds ...
+
+run:
+
+send-and-receive:
+     [java] The Hello! message was successfully sent to the /queue/testFarmQueue queue
+     [java] Queue browse result: 1
+     [java] blocking to receive message from queue /queue/testFarmQueue ...
+     [java] Message Hello! received
+     [java] 
+     [java] #####################
+     [java] ###    SUCCESS!   ###
+     [java] #####################
+
+undeploy:
+   [delete] Deleting: C:\jboss-4.2.0.GA\server\messaging-node0\farm\stateless-clustered-example.jar
+   [delete] Deleting: C:\jboss-4.2.0.GA\server\messaging-node0\farm\destinations-farm-service.xml
+
+BUILD SUCCESSFUL
+Total time: 19 seconds
+</pre></blockquote>
+
+<h2>Troublesooting</h2>
+<h3>1. I get <tt>"javax.jms.JMSSecurityException: User null is NOT authenticated"</tt></h3>
+<p>
+You probably didn't install JBoss Messaging correctly. A fresh JBoss
+Messaging installation requires changes in the security configuration
+of the JBoss instance, specifically a properly configured "<tt>messaging</tt>"
+security domain. Follow the instructions from the "Installation" paragraph of
+the release documentation.
+</p>
+</body>
+</html>

Added: trunk/docs/examples/stateless-clustered/build.xml
===================================================================
--- trunk/docs/examples/stateless-clustered/build.xml	                        (rev 0)
+++ trunk/docs/examples/stateless-clustered/build.xml	2007-05-21 12:47:45 UTC (rev 2720)
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+
+   To run the example, set JBOSS_HOME and run ant (with no parameters)
+
+   $Id: build.xml 2705 2007-05-17 21:34:07Z clebert.suconic at jboss.com $
+
+ -->
+
+<project name="StatelessClusteredExample" default="run">
+
+   <property environment="ENV"/>
+
+   <!-- These properties may be overriden by calling ants when this example is used in a smoke test -->
+   <property file="../examples.properties"/>
+   <property name="messaging.client.jar.path" value="../../"/>
+   <property name="messaging.client.jar.name" value="jboss-messaging-client.jar"/>
+   <property name="jboss.home" value="${ENV.JBOSS_HOME}"/>
+   <property name="jboss.configuration" value="messaging-node0"/>
+   <property name="example.queue.name" value="testFarmQueue"/>
+
+   <path id="common.compilation.classpath">
+      <fileset file="${jboss.home}/client/jboss-j2ee.jar"/>
+      <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+   </path>
+
+   <path id="example.compilation.classpath">
+      <path refid="common.compilation.classpath"/>
+      <pathelement path="../common/output/classes"/>
+   </path>
+
+   <path id="execution.classpath">
+      <pathelement path="./etc"/>
+      <pathelement path="../common/output/classes"/>
+      <pathelement path="./output/classes"/>
+      <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+      <fileset file="${jboss.home}/client/jbossall-client.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/log4j.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/javassist.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/deploy/jboss-aop-jdk50.deployer/jboss-aop-jdk50.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/deploy/jboss-aop-jdk50.deployer/trove.jar"/>
+   </path>
+
+   <target name="identify">
+      <echo message="###########################################################################"/>
+      <echo message="#         Running the STATELESS CLUSTERED SESSION BEAN example            #"/>
+      <echo message="###########################################################################"/>
+      <echo message="The queue:      ${example.queue.name}"/>
+      <echo message="The client jar: ${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+   </target>
+
+   <target name="sanity-check" depends="identify">
+      <available property="client.jar.present" file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+      <fail message="Could not find client jar ${messaging.client.jar.path}/${messaging.client.jar.name}"
+            unless="client.jar.present"/>
+   </target>
+
+   <target name="init" depends="sanity-check">
+      <mkdir dir="./output/classes/META-INF"/>
+      <mkdir dir="./output/lib"/>
+      <mkdir dir="../common/output/classes"/>
+   </target>
+
+   <target name="compile" depends="init">
+      <javac destdir="../common/output/classes" debug="on" debuglevel="lines,vars,source">
+         <src path="../common/src"/>
+         <classpath refid="common.compilation.classpath"/>
+      </javac>
+      <javac destdir="./output/classes" debug="on" debuglevel="lines,vars,source">
+         <src path="./src"/>
+         <classpath refid="example.compilation.classpath"/>
+      </javac>
+   </target>
+
+   <target name="jar" depends="compile">
+      <copy todir="./output/classes/META-INF">
+         <fileset dir="./etc/META-INF" includes="*"/>
+      </copy>
+      <jar destfile="./output/lib/stateless-clustered-example.jar"
+           basedir="./output/classes"
+           includes="META-INF/**,org/jboss/example/jms/statelessclustered/bean/*.class"/>
+   </target>
+
+   <target name="deploy" depends="jar">
+      <copy file="./etc/destinations-farm-service.xml"
+            todir="${jboss.home}/server/${jboss.configuration}/farm"/>
+      <copy file="./output/lib/stateless-clustered-example.jar"
+            todir="${jboss.home}/server/${jboss.configuration}/farm"/>
+      <antcall target="sleep"><param name="sleep.interval" value="15"/></antcall>
+   </target>
+
+   <target name="run" depends="deploy">
+      <antcall target="send-and-receive"/>
+      <antcall target="undeploy"/>
+   </target>
+
+   <target name="send-and-receive">
+      <!-- The client expects to find the name of the queue to connect to as value of the
+           'example.queue.name' property, which *may* be defined by calling ants when this example
+            is used in a smoke test -->
+      <java classname="org.jboss.example.jms.statelessclustered.client.Client"
+            classpathref="execution.classpath" fork="yes" failonerror="true">
+         <sysproperty key="example.queue.name" value="${example.queue.name}"/>
+         <!--
+         <jvmarg line="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=y,suspend=y,address=example"/>
+          -->
+      </java>
+   </target>
+
+   <target name="undeploy">
+      <delete file="${jboss.home}/server/${jboss.configuration}/farm/stateless-clustered-example.jar"
+              quiet="true"/>
+      <delete file="${jboss.home}/server/${jboss.configuration}/farm/destinations-farm-service.xml"
+              quiet="true"/>
+   </target>
+
+   <target name="clean" depends="undeploy">
+      <delete dir="./output" quiet="true"/>
+      <delete dir="../common/output" quiet="true"/>
+   </target>
+
+   <target name="sleep">
+      <echo message="Sleeping for ${sleep.interval} seconds ..."/>
+      <sleep seconds="${sleep.interval}"/>
+   </target>
+
+</project>
+

Added: trunk/docs/examples/stateless-clustered/etc/META-INF/ejb-jar.xml
===================================================================
--- trunk/docs/examples/stateless-clustered/etc/META-INF/ejb-jar.xml	                        (rev 0)
+++ trunk/docs/examples/stateless-clustered/etc/META-INF/ejb-jar.xml	2007-05-21 12:47:45 UTC (rev 2720)
@@ -0,0 +1,16 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
+    "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
+
+<ejb-jar>
+    <enterprise-beans>
+        <session>
+            <ejb-name>StatelessClusteredSessionExample</ejb-name>
+            <home>org.jboss.example.jms.statelessclustered.bean.StatelessClusteredSessionExampleHome</home>
+            <remote>org.jboss.example.jms.statelessclustered.bean.StatelessClusteredSessionExample</remote>
+            <ejb-class>org.jboss.example.jms.statelessclustered.bean.StatelessClusteredSessionExampleBean</ejb-class>
+            <session-type>Stateless</session-type>
+            <transaction-type>Container</transaction-type>
+        </session>
+    </enterprise-beans>
+</ejb-jar>
\ No newline at end of file

Added: trunk/docs/examples/stateless-clustered/etc/META-INF/jboss.xml
===================================================================
--- trunk/docs/examples/stateless-clustered/etc/META-INF/jboss.xml	                        (rev 0)
+++ trunk/docs/examples/stateless-clustered/etc/META-INF/jboss.xml	2007-05-21 12:47:45 UTC (rev 2720)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jboss PUBLIC
+   "-//JBoss//DTD JBOSS 3.0//EN"
+   "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd">
+<jboss>
+   <enterprise-beans>
+      <session>
+         <ejb-name>StatelessClusteredSessionExample</ejb-name>
+         <jndi-name>ejb/StatelessClusteredSessionExample</jndi-name>
+         <clustered>True</clustered>
+      </session>
+   </enterprise-beans>
+</jboss>

Added: trunk/docs/examples/stateless-clustered/etc/destinations-farm-service.xml
===================================================================
--- trunk/docs/examples/stateless-clustered/etc/destinations-farm-service.xml	                        (rev 0)
+++ trunk/docs/examples/stateless-clustered/etc/destinations-farm-service.xml	2007-05-21 12:47:45 UTC (rev 2720)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+   <mbean code="org.jboss.jms.server.destination.QueueService"
+      name="jboss.messaging.destination:service=Queue,name=testFarmQueue"
+      xmbean-dd="xmdesc/Queue-xmbean.xml">
+      <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+      <depends>jboss.messaging:service=PostOffice</depends>
+      <attribute name="Clustered">true</attribute>
+   </mbean>
+</server>
\ No newline at end of file

Added: trunk/docs/examples/stateless-clustered/etc/jndi.properties
===================================================================
--- trunk/docs/examples/stateless-clustered/etc/jndi.properties	                        (rev 0)
+++ trunk/docs/examples/stateless-clustered/etc/jndi.properties	2007-05-21 12:47:45 UTC (rev 2720)
@@ -0,0 +1,4 @@
+### JBossNS properties
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Added: trunk/docs/examples/stateless-clustered/etc/log4j.xml
===================================================================
--- trunk/docs/examples/stateless-clustered/etc/log4j.xml	                        (rev 0)
+++ trunk/docs/examples/stateless-clustered/etc/log4j.xml	2007-05-21 12:47:45 UTC (rev 2720)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- $Id: log4j.xml 563 2005-12-30 22:04:19Z ovidiu $ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+      <param name="Target" value="System.out"/>
+      <param name="Threshold" value="INFO"/>
+      <layout class="org.apache.log4j.PatternLayout">
+         <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p @%t [%c{1}] %m%n"/>
+      </layout>
+   </appender>
+
+   <root>
+      <appender-ref ref="CONSOLE"/>
+   </root>
+
+</log4j:configuration>

Added: trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/bean/StatelessClusteredSessionExample.java
===================================================================
--- trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/bean/StatelessClusteredSessionExample.java	                        (rev 0)
+++ trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/bean/StatelessClusteredSessionExample.java	2007-05-21 12:47:45 UTC (rev 2720)
@@ -0,0 +1,29 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.example.jms.statelessclustered.bean;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.EJBObject;
+
+/**
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision: 1843 $</tt>
+
+ * $Id$
+ */
+
+public interface StatelessClusteredSessionExample extends EJBObject
+{
+   public void drain(String queueName) throws RemoteException, Exception;
+   
+   public void send(String txt, String queueName) throws RemoteException, Exception;
+   
+   public int browse(String queueName) throws RemoteException, Exception;
+   
+   public String receive(String queueName) throws RemoteException, Exception;
+}

Added: trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/bean/StatelessClusteredSessionExampleBean.java
===================================================================
--- trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/bean/StatelessClusteredSessionExampleBean.java	                        (rev 0)
+++ trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/bean/StatelessClusteredSessionExampleBean.java	2007-05-21 12:47:45 UTC (rev 2720)
@@ -0,0 +1,256 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.example.jms.statelessclustered.bean;
+
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import javax.ejb.EJBException;
+import javax.ejb.SessionBean;
+import javax.ejb.SessionContext;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+/**
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision: 1852 $</tt>
+ 
+ * $Id$
+ */
+public class StatelessClusteredSessionExampleBean implements SessionBean
+{
+   private ConnectionFactory cf = null;
+
+   public void drain(String queueName) throws Exception
+   {
+      InitialContext ic = new InitialContext();
+      Queue queue = (Queue)ic.lookup(queueName);
+      ic.close();
+      
+      Session session = null;
+      Connection conn = null;
+      
+      try
+      {
+         conn = getConnection();
+         session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         MessageConsumer consumer = session.createConsumer(queue);
+         int drainedCount = 0;
+         Message m = null;
+         do
+         {
+            m = consumer.receive(1L);
+            if (m != null) drainedCount++;
+         }
+         while(m != null);
+         System.out.println("Drained " + drainedCount + " messages from queue " + queueName);
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            closeConnection(conn);
+         }
+      }
+   }
+   
+   public void send(String txt, String queueName) throws Exception
+   {
+      InitialContext ic = new InitialContext();
+      Queue queue = (Queue)ic.lookup(queueName);
+      
+      ic.close();
+      
+      Session session = null;
+      Connection conn = null;
+      
+      try
+      {
+         conn = getConnection();
+         
+         session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         
+         MessageProducer producer = session.createProducer(queue);
+         
+         TextMessage tm = session.createTextMessage(txt);
+         
+         producer.send(tm);
+         
+         System.out.println("message " + txt + " sent to " + queueName);         
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            closeConnection(conn);
+         }
+      }
+   }
+   
+   public int browse(String queueName) throws Exception
+   {
+      InitialContext ic = new InitialContext();
+      Queue queue = (Queue)ic.lookup(queueName);
+      ic.close();
+      
+      Session session = null;
+      Connection conn = null;
+      
+      try
+      {
+         conn = getConnection();
+         session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         QueueBrowser browser = session.createBrowser(queue);
+         
+         ArrayList list = new ArrayList();
+         for(Enumeration e = browser.getEnumeration(); e.hasMoreElements(); )
+         {
+            list.add(e.nextElement());
+         }
+         
+         return list.size();
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            closeConnection(conn);
+         }
+      }
+   }
+   
+   public String receive(String queueName) throws Exception
+   {
+      InitialContext ic = new InitialContext();
+      Queue queue = (Queue)ic.lookup(queueName);
+      ic.close();
+      
+      Session session = null;
+      Connection conn = null;
+      
+      try
+      {
+         conn = getConnection();
+         session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         
+         MessageConsumer consumer = session.createConsumer(queue);
+         
+         System.out.println("blocking to receive message from queue " + queueName + " ...");
+         TextMessage tm = (TextMessage)consumer.receive(5000);
+         
+         if (tm == null)
+         {
+            throw new Exception("No message!");
+         }
+         
+         System.out.println("Message " + tm.getText() + " received");
+         
+         return tm.getText();         
+      }
+      finally
+      {
+         if (conn != null)
+         {
+            closeConnection(conn);
+         }
+      }
+   }
+   
+   public Connection getConnection() throws Exception
+   {
+      
+      Connection connection = null;
+      
+      try
+      {
+         connection = cf.createConnection();
+         
+         connection.start();         
+      }
+      catch(Exception e )
+      {
+         if(connection != null)
+         {
+            closeConnection(connection);
+         }
+         System.out.println("Failed to get connection...exception is " + e);
+         throw e;
+      }
+      
+      return connection;
+   }
+   
+   public void closeConnection(Connection con) throws Exception
+   {      
+      try
+      {
+         con.close();         
+      }
+      catch(JMSException jmse)
+      {
+         System.out.println("Could not close connection " + con +" exception was " + jmse);
+         throw jmse;
+      }
+   }
+   
+   public void setSessionContext(SessionContext ctx) throws EJBException, RemoteException
+   {      
+   }
+   
+   public void ejbCreate()
+   {
+      try
+      {
+         InitialContext ic = new InitialContext(); // Non-HA
+         
+         cf = (ConnectionFactory)ic.lookup("java:/JmsXA");
+         
+         ic.close();
+      }
+      catch(Exception e)
+      {
+         e.printStackTrace();
+         throw new EJBException("Initalization failure: " + e.getMessage(), e);
+      }
+   }
+   
+   public void ejbRemove() throws EJBException
+   {
+      try
+      {
+         if(cf != null)
+         {
+            cf = null;
+         }
+      }
+      catch(Exception e)
+      {
+         throw new EJBException("ejbRemove ", e);
+      }
+   }
+   
+   public void ejbActivate() throws EJBException, RemoteException
+   {
+   }
+   
+   public void ejbPassivate() throws EJBException, RemoteException
+   {
+   }
+      
+}

Added: trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/bean/StatelessClusteredSessionExampleHome.java
===================================================================
--- trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/bean/StatelessClusteredSessionExampleHome.java	                        (rev 0)
+++ trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/bean/StatelessClusteredSessionExampleHome.java	2007-05-21 12:47:45 UTC (rev 2720)
@@ -0,0 +1,25 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.example.jms.statelessclustered.bean;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.CreateException;
+import javax.ejb.EJBHome;
+/**
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision: 1843 $</tt>
+
+ * $Id$
+ */
+
+public interface StatelessClusteredSessionExampleHome extends EJBHome
+{
+   public StatelessClusteredSessionExample create() throws RemoteException, CreateException;
+}
+
+

Added: trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/client/Client.java
===================================================================
--- trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/client/Client.java	                        (rev 0)
+++ trunk/docs/examples/stateless-clustered/src/org/jboss/example/jms/statelessclustered/client/Client.java	2007-05-21 12:47:45 UTC (rev 2720)
@@ -0,0 +1,125 @@
+/*
+ * 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.
+ */
+package org.jboss.example.jms.statelessclustered.client;
+
+import java.util.Properties;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.TextMessage;
+import javax.jms.MessageConsumer;
+import javax.jms.Queue;
+import javax.jms.Session;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.example.jms.common.ExampleSupport;
+import org.jboss.example.jms.statelessclustered.bean.StatelessClusteredSessionExample;
+import org.jboss.example.jms.statelessclustered.bean.StatelessClusteredSessionExampleHome;
+
+/**
+ * This example deploys a simple clustered Stateless Session Bean that is used as a proxy to send
+ * and receive JMS messages in a managed environment.
+ *
+ * Since this example is also used by the smoke test, it is essential that the VM exits with exit
+ * code 0 in case of successful execution and a non-zero value on failure.
+ *
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision: 1843 $</tt>
+ *
+ * $Id: Client.java 1843 2006-12-21 23:41:19Z timfox $
+ */
+public class Client extends ExampleSupport
+{
+   private InitialContext createHAInitialContext() throws Exception
+   {
+      Properties p = new Properties();
+      p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+      p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
+      p.put(Context.PROVIDER_URL, "localhost:1100,localhost:1200");
+      return new InitialContext(p);
+   }
+
+   public void example() throws Exception
+   {            
+      InitialContext haic = createHAInitialContext();
+      
+      StatelessClusteredSessionExampleHome home =
+         (StatelessClusteredSessionExampleHome)haic.lookup("ejb/StatelessClusteredSessionExample");            
+      
+      StatelessClusteredSessionExample bean = home.create();
+
+      String queueName = getDestinationJNDIName();
+      String text = "Hello!";
+
+      bean.drain(queueName);
+
+      bean.send("Hello!", queueName);
+      log("The " + text + " message was successfully sent to the " + queueName + " queue");
+
+      int num = bean.browse(queueName);
+      bean.remove();
+
+      assertEquals(1, num);
+
+      log("Queue browse result: " + num);
+
+      Queue queue = (Queue)haic.lookup(queueName);
+      ConnectionFactory cf = (ConnectionFactory) new InitialContext().lookup("/XAConnectionFactory");
+      Connection conn = cf.createConnection();
+
+      try
+      {
+         conn.start();
+         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);         
+         MessageConsumer consumer = session.createConsumer(queue);
+         
+         System.out.println("blocking to receive message from queue " + queueName + " ...");
+         TextMessage tm = (TextMessage)consumer.receive(5000);
+         
+         if (tm == null)
+         {
+            throw new Exception("No message!");
+         }
+         
+         System.out.println("Message " + tm.getText() + " received");
+         
+         assertEquals("Hello!", tm.getText());
+      }
+      finally
+      {
+         conn.close();
+      }
+
+   }
+   
+   protected boolean isQueueExample()
+   {
+      return true;
+   }
+   
+   public static void main(String[] args)
+   {
+      new Client().run();
+   }   
+}




More information about the jboss-cvs-commits mailing list