[jboss-cvs] JBoss Messaging SVN: r7602 - in trunk: examples/javaee and 46 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 22 09:46:40 EDT 2009
Author: ataylor
Date: 2009-07-22 09:46:38 -0400 (Wed, 22 Jul 2009)
New Revision: 7602
Added:
trunk/examples/javaee/mdb-bmp/
trunk/examples/javaee/mdb-bmp/build.xml
trunk/examples/javaee/mdb-bmp/config/
trunk/examples/javaee/mdb-bmp/config/ant.properties
trunk/examples/javaee/mdb-bmp/config/jndi.properties
trunk/examples/javaee/mdb-bmp/readme.html
trunk/examples/javaee/mdb-bmp/server/
trunk/examples/javaee/mdb-bmp/server/jbm-configuration.xml
trunk/examples/javaee/mdb-bmp/server/jbm-jms.xml
trunk/examples/javaee/mdb-bmp/server/jbm-users.xml
trunk/examples/javaee/mdb-bmp/src/
trunk/examples/javaee/mdb-bmp/src/org/
trunk/examples/javaee/mdb-bmp/src/org/jboss/
trunk/examples/javaee/mdb-bmp/src/org/jboss/javaee/
trunk/examples/javaee/mdb-bmp/src/org/jboss/javaee/example/
trunk/examples/javaee/mdb-bmp/src/org/jboss/javaee/example/MDB_BMPClientExample.java
trunk/examples/javaee/mdb-bmp/src/org/jboss/javaee/example/server/
trunk/examples/javaee/mdb-bmp/src/org/jboss/javaee/example/server/MDB_BMPExample.java
trunk/examples/javaee/mdb-cmp-setrollbackonly/
trunk/examples/javaee/mdb-cmp-setrollbackonly/build.xml
trunk/examples/javaee/mdb-cmp-setrollbackonly/config/
trunk/examples/javaee/mdb-cmp-setrollbackonly/config/ant.properties
trunk/examples/javaee/mdb-cmp-setrollbackonly/config/jndi.properties
trunk/examples/javaee/mdb-cmp-setrollbackonly/readme.html
trunk/examples/javaee/mdb-cmp-setrollbackonly/server/
trunk/examples/javaee/mdb-cmp-setrollbackonly/server/jbm-configuration.xml
trunk/examples/javaee/mdb-cmp-setrollbackonly/server/jbm-jms.xml
trunk/examples/javaee/mdb-cmp-setrollbackonly/server/jbm-users.xml
trunk/examples/javaee/mdb-cmp-setrollbackonly/src/
trunk/examples/javaee/mdb-cmp-setrollbackonly/src/org/
trunk/examples/javaee/mdb-cmp-setrollbackonly/src/org/jboss/
trunk/examples/javaee/mdb-cmp-setrollbackonly/src/org/jboss/javaee/
trunk/examples/javaee/mdb-cmp-setrollbackonly/src/org/jboss/javaee/example/
trunk/examples/javaee/mdb-cmp-setrollbackonly/src/org/jboss/javaee/example/MDB_CMP_SetRollbackOnlyClientExample.java
trunk/examples/javaee/mdb-cmp-setrollbackonly/src/org/jboss/javaee/example/server/
trunk/examples/javaee/mdb-cmp-setrollbackonly/src/org/jboss/javaee/example/server/MDB_CMP_SetRollbackOnlyExample.java
trunk/examples/javaee/mdb-cmp-tx-local/
trunk/examples/javaee/mdb-cmp-tx-local/build.xml
trunk/examples/javaee/mdb-cmp-tx-local/config/
trunk/examples/javaee/mdb-cmp-tx-local/config/ant.properties
trunk/examples/javaee/mdb-cmp-tx-local/config/jndi.properties
trunk/examples/javaee/mdb-cmp-tx-local/readme.html
trunk/examples/javaee/mdb-cmp-tx-local/server/
trunk/examples/javaee/mdb-cmp-tx-local/server/jbm-configuration.xml
trunk/examples/javaee/mdb-cmp-tx-local/server/jbm-jms.xml
trunk/examples/javaee/mdb-cmp-tx-local/server/jbm-users.xml
trunk/examples/javaee/mdb-cmp-tx-local/src/
trunk/examples/javaee/mdb-cmp-tx-local/src/org/
trunk/examples/javaee/mdb-cmp-tx-local/src/org/jboss/
trunk/examples/javaee/mdb-cmp-tx-local/src/org/jboss/javaee/
trunk/examples/javaee/mdb-cmp-tx-local/src/org/jboss/javaee/example/
trunk/examples/javaee/mdb-cmp-tx-local/src/org/jboss/javaee/example/MDB_CMP_TxLocalClientExample.java
trunk/examples/javaee/mdb-cmp-tx-local/src/org/jboss/javaee/example/server/
trunk/examples/javaee/mdb-cmp-tx-local/src/org/jboss/javaee/example/server/MDB_CMP_TxLocalExample.java
trunk/examples/javaee/mdb-cmp-tx-not-supported/
trunk/examples/javaee/mdb-cmp-tx-not-supported/build.xml
trunk/examples/javaee/mdb-cmp-tx-not-supported/config/
trunk/examples/javaee/mdb-cmp-tx-not-supported/config/ant.properties
trunk/examples/javaee/mdb-cmp-tx-not-supported/config/jndi.properties
trunk/examples/javaee/mdb-cmp-tx-not-supported/readme.html
trunk/examples/javaee/mdb-cmp-tx-not-supported/server/
trunk/examples/javaee/mdb-cmp-tx-not-supported/server/jbm-configuration.xml
trunk/examples/javaee/mdb-cmp-tx-not-supported/server/jbm-jms.xml
trunk/examples/javaee/mdb-cmp-tx-not-supported/server/jbm-users.xml
trunk/examples/javaee/mdb-cmp-tx-not-supported/src/
trunk/examples/javaee/mdb-cmp-tx-not-supported/src/org/
trunk/examples/javaee/mdb-cmp-tx-not-supported/src/org/jboss/
trunk/examples/javaee/mdb-cmp-tx-not-supported/src/org/jboss/javaee/
trunk/examples/javaee/mdb-cmp-tx-not-supported/src/org/jboss/javaee/example/
trunk/examples/javaee/mdb-cmp-tx-not-supported/src/org/jboss/javaee/example/MDB_CMP_TxNotSupportedClientExample.java
trunk/examples/javaee/mdb-cmp-tx-not-supported/src/org/jboss/javaee/example/server/
trunk/examples/javaee/mdb-cmp-tx-not-supported/src/org/jboss/javaee/example/server/MDB_CMP_TxNotSupported.java
trunk/examples/javaee/mdb-cmp-tx-required/
trunk/examples/javaee/mdb-cmp-tx-required/src/org/jboss/javaee/example/MDB_CMP_TxRequiredClientExample.java
trunk/examples/javaee/mdb-cmp-tx-required/src/org/jboss/javaee/example/server/MDB_CMP_TxRequiredExample.java
Removed:
trunk/examples/javaee/mdb-cmp-tx-required/src/org/jboss/javaee/example/MDBClientExample.java
trunk/examples/javaee/mdb-cmp-tx-required/src/org/jboss/javaee/example/server/MDBExample.java
trunk/examples/javaee/mdb/
Modified:
trunk/examples/javaee/common/build.xml
trunk/examples/javaee/jca-config/server2/ra.xml
trunk/examples/javaee/mdb-cmp-tx-required/build.xml
trunk/examples/javaee/mdb-cmp-tx-required/config/ant.properties
trunk/examples/javaee/messaging-javaee-examples.iml
trunk/messaging.ipr
trunk/src/config/ra.xml
trunk/src/main/org/jboss/messaging/ra/JBMRAProperties.java
trunk/src/main/org/jboss/messaging/ra/JBMResourceAdapter.java
trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivation.java
trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivationSpec.java
trunk/src/main/org/jboss/messaging/ra/inflow/JBMMessageHandler.java
trunk/tests/src/org/jboss/messaging/tests/unit/ra/ResourceAdapterTest.java
Log:
https://jira.jboss.org/jira/browse/JBMESSAGING-1687 - fixed jca to support BMP and transactions properly
Modified: trunk/examples/javaee/common/build.xml
===================================================================
--- trunk/examples/javaee/common/build.xml 2009-07-22 11:58:52 UTC (rev 7601)
+++ trunk/examples/javaee/common/build.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -138,7 +138,7 @@
</fileset>
</copy>
<exec dir="${jboss.home}/bin" executable="sh" osfamily="unix">
- <arg line="run.sh -c ${example.name}-example-profile"/>
+ <arg line="debug.sh -c ${example.name}-example-profile"/>
</exec>
<exec dir="${jboss.home}/bin" executable="cmd" osfamily="windows">
<arg line="/c run.bat -c ${example.name}-example-profile"/>
Modified: trunk/examples/javaee/jca-config/server2/ra.xml
===================================================================
--- trunk/examples/javaee/jca-config/server2/ra.xml 2009-07-22 11:58:52 UTC (rev 7601)
+++ trunk/examples/javaee/jca-config/server2/ra.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -56,12 +56,6 @@
<config-property-type>java.lang.String</config-property-type>
<config-property-value>jbm.remoting.netty.port=5445</config-property-value>
</config-property>
- <config-property>
- <description>Use XA methods to obtain connections?</description>
- <config-property-name>UseXA</config-property-name>
- <config-property-type>java.lang.Boolean</config-property-type>
- <config-property-value>true</config-property-value>
- </config-property>
<outbound-resourceadapter>
<connection-definition>
Added: trunk/examples/javaee/mdb-bmp/build.xml
===================================================================
--- trunk/examples/javaee/mdb-bmp/build.xml (rev 0)
+++ trunk/examples/javaee/mdb-bmp/build.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- =========================================================================================== -->
+<!-- -->
+<!-- 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 Java EE MDB Example">
+
+ <import file="../common/build.xml"/>
+
+ <target name="run">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.jboss.javaee.example.MDB_BMPClientExample"/>
+ </antcall>
+ </target>
+</project>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-bmp/config/ant.properties
===================================================================
--- trunk/examples/javaee/mdb-bmp/config/ant.properties (rev 0)
+++ trunk/examples/javaee/mdb-bmp/config/ant.properties 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1 @@
+example.name=mdb-bmp
\ No newline at end of file
Added: trunk/examples/javaee/mdb-bmp/config/jndi.properties
===================================================================
--- trunk/examples/javaee/mdb-bmp/config/jndi.properties (rev 0)
+++ trunk/examples/javaee/mdb-bmp/config/jndi.properties 2009-07-22 13:46:38 UTC (rev 7602)
@@ -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/javaee/mdb-bmp/readme.html
===================================================================
--- trunk/examples/javaee/mdb-bmp/readme.html (rev 0)
+++ trunk/examples/javaee/mdb-bmp/readme.html 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,100 @@
+<html>
+ <head>
+ <title>JBoss Messaging Java EE MDB Example</title>
+ <link rel="stylesheet" type="text/css" href="../../common/common.css">
+ </head>
+ <body>
+ <h1>Java EE MDB Example</h1>
+ <br>
+ <p>This example shows you how to send a message to an MDB</p>
+ <p>
+ The example will send deploy a simple MDB and demonstrate sending a message and the MDB consuming it
+ </p>
+
+ <h2>JBoss AS configuration</h2>
+
+ <p>Please refer to JBoss Messaging Quickstart guide to <a href="../../../docs/quickstart-guide/en/html_single/index.html#installation.jboss">install it in JBoss AS 5<a></p>
+
+ <h2>Example step-by-step</h2>
+ <p><i>To deploy and start the server, simply type <code>ant deploy</code> from the example directory</i></p>
+ <p><i>To run the example, simply type <code>ant</code> from the example directory</i></p>
+ <p><i>To remove the example profile, simply type <code>ant undeploy</code> from the example directory</i></p>
+ <p><i> ** make sure that JBOSS_HOME is set to the Jboss installation directory</i></p>
+ <br>
+ <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 it's properties from the <code>jndi.properties</code> file in the directory <code>config</code></li>
+ <pre>
+ <code>initialContext = new InitialContext();</code>
+ </pre>
+
+ <li>We look up the JMS queue object from JNDI</li>
+ <pre>
+ <code>Queue queue = (Queue) initialContext.lookup("/queue/testQueue");</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(queue);</code>
+ </pre>
+
+ <li>We create a JMS text messages that we are going to send.</li>
+ <pre>
+ <code> TextMessage message = session.createTextMessage("This is a text message");</code>
+ </pre>
+
+ <li>We send messages to the queue</li>
+ <pre>
+ <code>messageProducer.send(message);</code>
+ </pre>
+
+ <li>The MDB receives the message<br />
+ We know the message is a TextMessage so we cast to it.
+ </li>
+ <pre>
+ <code>TextMessage tm = (TextMessage)message;</code>
+ </pre>
+
+ <li>The MDB gets the text and prints it
+ </li>
+ <pre>
+ <code>String text = tm.getText();
+ System.out.println("message " + text + " received");
+ </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>
+ </body>
+</html>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-bmp/server/jbm-configuration.xml
===================================================================
--- trunk/examples/javaee/mdb-bmp/server/jbm-configuration.xml (rev 0)
+++ trunk/examples/javaee/mdb-bmp/server/jbm-configuration.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,67 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-configuration.xsd">
+
+ <bindings-directory>${jboss.server.data.dir}/messaging/bindings</bindings-directory>
+
+ <journal-directory>${jboss.server.data.dir}/messaging/journal</journal-directory>
+
+ <large-messages-directory>${jboss.server.data.dir}/messaging/largemessages</large-messages-directory>
+
+ <paging-directory>${jboss.server.data.dir}/messaging/paging</paging-directory>
+
+ <!-- Connectors -->
+ <connectors>
+ <connector name="netty">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+ <param key="jbm.remoting.netty.host" value="${jbm.remoting.netty.host:localhost}" type="String"/>
+ <param key="jbm.remoting.netty.port" value="${jbm.remoting.netty.port:5445}" type="Integer"/>
+ </connector>
+
+ <connector name="in-vm">
+ <factory-class>org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory</factory-class>
+ </connector>
+
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <!-- In VM acceptor -->
+ <acceptor name="in-vm">
+ <factory-class>org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory</factory-class>
+ <param key="jbm.remoting.invm.serverid" value="0" type="Integer"/>
+ </acceptor>
+
+ <!-- Netty TCP Acceptor -->
+ <acceptor name="netty">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+ <param key="jbm.remoting.netty.host" value="${jbm.remoting.netty.host:localhost}" type="String"/>
+ <param key="jbm.remoting.netty.port" value="${jbm.remoting.netty.port:5445}" type="Integer"/>
+ </acceptor>
+ </acceptors>
+
+ <security-settings>
+ <security-setting match="#">
+ <permission type="createTempQueue" roles="guest"/>
+ <permission type="deleteTempQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+ <address-settings>
+ <!--default for catch all-->
+ <address-setting match="#">
+ <clustered>false</clustered>
+ <dead-letter-address>jms.queue.DLQ</dead-letter-address>
+ <expiry-address>jms.queue.ExpiryQueue</expiry-address>
+ <redelivery-delay>0</redelivery-delay>
+ <max-size-bytes>-1</max-size-bytes>
+ <page-size-bytes>10485760</page-size-bytes>
+ <distribution-policy-class>org.jboss.messaging.core.server.impl.RoundRobinDistributor</distribution-policy-class>
+ <message-counter-history-day-limit>10</message-counter-history-day-limit>
+ </address-setting>
+ </address-settings>
+
+
+</configuration>
Added: trunk/examples/javaee/mdb-bmp/server/jbm-jms.xml
===================================================================
--- trunk/examples/javaee/mdb-bmp/server/jbm-jms.xml (rev 0)
+++ trunk/examples/javaee/mdb-bmp/server/jbm-jms.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,16 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-jms.xsd">
+
+ <connection-factory name="ConnectionFactory">
+ <connector-ref connector-name="netty"/>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ <entry name="XAConnectionFactory"/>
+ </entries>
+ </connection-factory>
+
+ <queue name="testQueue">
+ <entry name="/queue/testQueue"/>
+ </queue>
+</configuration>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-bmp/server/jbm-users.xml
===================================================================
--- trunk/examples/javaee/mdb-bmp/server/jbm-users.xml (rev 0)
+++ trunk/examples/javaee/mdb-bmp/server/jbm-users.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,7 @@
+<configuration xmlns="urn:jboss:messaging" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-users.xsd">
+ <!-- the default user. this is used where username is null-->
+ <defaultuser name="guest" password="guest">
+ <role name="guest"/>
+ </defaultuser>
+</configuration>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-bmp/src/org/jboss/javaee/example/MDB_BMPClientExample.java
===================================================================
--- trunk/examples/javaee/mdb-bmp/src/org/jboss/javaee/example/MDB_BMPClientExample.java (rev 0)
+++ trunk/examples/javaee/mdb-bmp/src/org/jboss/javaee/example/MDB_BMPClientExample.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,84 @@
+/*
+ * 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.javaee.example;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ */
+public class MDB_BMPClientExample
+{
+ public static void main(String[] args) throws Exception
+ {
+ Connection connection = null;
+ InitialContext initialContext = null;
+ try
+ {
+ //Step 1. Create an initial context to perform the JNDI lookup.
+ initialContext = new InitialContext();
+
+ //Step 2. Perfom a lookup on the queue
+ Queue queue = (Queue) initialContext.lookup("/queue/testQueue");
+
+ //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 and 10 in MDBExample
+ }
+ finally
+ {
+ //Step 11. Be sure to close our JMS resources!
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ if(connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/examples/javaee/mdb-bmp/src/org/jboss/javaee/example/server/MDB_BMPExample.java
===================================================================
--- trunk/examples/javaee/mdb-bmp/src/org/jboss/javaee/example/server/MDB_BMPExample.java (rev 0)
+++ trunk/examples/javaee/mdb-bmp/src/org/jboss/javaee/example/server/MDB_BMPExample.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,82 @@
+/*
+ * 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.javaee.example.server;
+
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.ejb.MessageDrivenContext;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+import javax.transaction.UserTransaction;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ */
+ at MessageDriven(name = "MDB_BMPExample",
+ activationConfig =
+ {
+ @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/testQueue"),
+ @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Dups-ok-acknowledge")
+ })
+ at TransactionManagement(value= TransactionManagementType.BEAN)
+public class MDB_BMPExample implements MessageListener
+{
+ @Resource
+ MessageDrivenContext ctx;
+
+ public void onMessage(Message message)
+ {
+ try
+ {
+ //Step 9. We know the client is sending a text message so we cast
+ TextMessage textMessage = (TextMessage)message;
+
+ //Step 10. get the text from the message.
+ String text = textMessage.getText();
+
+ System.out.println("message " + text + " received");
+
+ //Step 3. lets look at the user transaction to make sure there isn't one.
+ UserTransaction tx = ctx.getUserTransaction();
+
+ if(tx != null)
+ {
+ tx.begin();
+ System.out.println("we're in the middle of a transaction: " + tx);
+ tx.commit();
+ }
+ else
+ {
+ System.out.println("something is wrong, I was expecting a transaction");
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/examples/javaee/mdb-cmp-setrollbackonly/build.xml (from rev 7587, trunk/examples/javaee/mdb/build.xml)
===================================================================
--- trunk/examples/javaee/mdb-cmp-setrollbackonly/build.xml (rev 0)
+++ trunk/examples/javaee/mdb-cmp-setrollbackonly/build.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- =========================================================================================== -->
+<!-- -->
+<!-- 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 Java EE MDB Example">
+
+ <import file="../common/build.xml"/>
+
+ <target name="run">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.jboss.javaee.example.MDB_CMP_SetRollbackOnlyClientExample"/>
+ </antcall>
+ </target>
+</project>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-setrollbackonly/config/ant.properties
===================================================================
--- trunk/examples/javaee/mdb-cmp-setrollbackonly/config/ant.properties (rev 0)
+++ trunk/examples/javaee/mdb-cmp-setrollbackonly/config/ant.properties 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1 @@
+example.name=mdb-cmp-setrollbackonly
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-setrollbackonly/config/jndi.properties
===================================================================
--- trunk/examples/javaee/mdb-cmp-setrollbackonly/config/jndi.properties (rev 0)
+++ trunk/examples/javaee/mdb-cmp-setrollbackonly/config/jndi.properties 2009-07-22 13:46:38 UTC (rev 7602)
@@ -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
Copied: trunk/examples/javaee/mdb-cmp-setrollbackonly/readme.html (from rev 7587, trunk/examples/javaee/mdb/readme.html)
===================================================================
--- trunk/examples/javaee/mdb-cmp-setrollbackonly/readme.html (rev 0)
+++ trunk/examples/javaee/mdb-cmp-setrollbackonly/readme.html 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,100 @@
+<html>
+ <head>
+ <title>JBoss Messaging Java EE MDB Example</title>
+ <link rel="stylesheet" type="text/css" href="../../common/common.css">
+ </head>
+ <body>
+ <h1>Java EE MDB Example</h1>
+ <br>
+ <p>This example shows you how to send a message to an MDB</p>
+ <p>
+ The example will send deploy a simple MDB and demonstrate sending a message and the MDB consuming it
+ </p>
+
+ <h2>JBoss AS configuration</h2>
+
+ <p>Please refer to JBoss Messaging Quickstart guide to <a href="../../../docs/quickstart-guide/en/html_single/index.html#installation.jboss">install it in JBoss AS 5<a></p>
+
+ <h2>Example step-by-step</h2>
+ <p><i>To deploy and start the server, simply type <code>ant deploy</code> from the example directory</i></p>
+ <p><i>To run the example, simply type <code>ant</code> from the example directory</i></p>
+ <p><i>To remove the example profile, simply type <code>ant undeploy</code> from the example directory</i></p>
+ <p><i> ** make sure that JBOSS_HOME is set to the Jboss installation directory</i></p>
+ <br>
+ <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 it's properties from the <code>jndi.properties</code> file in the directory <code>config</code></li>
+ <pre>
+ <code>initialContext = new InitialContext();</code>
+ </pre>
+
+ <li>We look up the JMS queue object from JNDI</li>
+ <pre>
+ <code>Queue queue = (Queue) initialContext.lookup("/queue/testQueue");</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(queue);</code>
+ </pre>
+
+ <li>We create a JMS text messages that we are going to send.</li>
+ <pre>
+ <code> TextMessage message = session.createTextMessage("This is a text message");</code>
+ </pre>
+
+ <li>We send messages to the queue</li>
+ <pre>
+ <code>messageProducer.send(message);</code>
+ </pre>
+
+ <li>The MDB receives the message<br />
+ We know the message is a TextMessage so we cast to it.
+ </li>
+ <pre>
+ <code>TextMessage tm = (TextMessage)message;</code>
+ </pre>
+
+ <li>The MDB gets the text and prints it
+ </li>
+ <pre>
+ <code>String text = tm.getText();
+ System.out.println("message " + text + " received");
+ </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>
+ </body>
+</html>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-setrollbackonly/server/jbm-configuration.xml
===================================================================
--- trunk/examples/javaee/mdb-cmp-setrollbackonly/server/jbm-configuration.xml (rev 0)
+++ trunk/examples/javaee/mdb-cmp-setrollbackonly/server/jbm-configuration.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,67 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-configuration.xsd">
+
+ <bindings-directory>${jboss.server.data.dir}/messaging/bindings</bindings-directory>
+
+ <journal-directory>${jboss.server.data.dir}/messaging/journal</journal-directory>
+
+ <large-messages-directory>${jboss.server.data.dir}/messaging/largemessages</large-messages-directory>
+
+ <paging-directory>${jboss.server.data.dir}/messaging/paging</paging-directory>
+
+ <!-- Connectors -->
+ <connectors>
+ <connector name="netty">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+ <param key="jbm.remoting.netty.host" value="${jbm.remoting.netty.host:localhost}" type="String"/>
+ <param key="jbm.remoting.netty.port" value="${jbm.remoting.netty.port:5445}" type="Integer"/>
+ </connector>
+
+ <connector name="in-vm">
+ <factory-class>org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory</factory-class>
+ </connector>
+
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <!-- In VM acceptor -->
+ <acceptor name="in-vm">
+ <factory-class>org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory</factory-class>
+ <param key="jbm.remoting.invm.serverid" value="0" type="Integer"/>
+ </acceptor>
+
+ <!-- Netty TCP Acceptor -->
+ <acceptor name="netty">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+ <param key="jbm.remoting.netty.host" value="${jbm.remoting.netty.host:localhost}" type="String"/>
+ <param key="jbm.remoting.netty.port" value="${jbm.remoting.netty.port:5445}" type="Integer"/>
+ </acceptor>
+ </acceptors>
+
+ <security-settings>
+ <security-setting match="#">
+ <permission type="createTempQueue" roles="guest"/>
+ <permission type="deleteTempQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+ <address-settings>
+ <!--default for catch all-->
+ <address-setting match="#">
+ <clustered>false</clustered>
+ <dead-letter-address>jms.queue.DLQ</dead-letter-address>
+ <expiry-address>jms.queue.ExpiryQueue</expiry-address>
+ <redelivery-delay>0</redelivery-delay>
+ <max-size-bytes>-1</max-size-bytes>
+ <page-size-bytes>10485760</page-size-bytes>
+ <distribution-policy-class>org.jboss.messaging.core.server.impl.RoundRobinDistributor</distribution-policy-class>
+ <message-counter-history-day-limit>10</message-counter-history-day-limit>
+ </address-setting>
+ </address-settings>
+
+
+</configuration>
Added: trunk/examples/javaee/mdb-cmp-setrollbackonly/server/jbm-jms.xml
===================================================================
--- trunk/examples/javaee/mdb-cmp-setrollbackonly/server/jbm-jms.xml (rev 0)
+++ trunk/examples/javaee/mdb-cmp-setrollbackonly/server/jbm-jms.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,16 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-jms.xsd">
+
+ <connection-factory name="ConnectionFactory">
+ <connector-ref connector-name="netty"/>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ <entry name="XAConnectionFactory"/>
+ </entries>
+ </connection-factory>
+
+ <queue name="testQueue">
+ <entry name="/queue/testQueue"/>
+ </queue>
+</configuration>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-setrollbackonly/server/jbm-users.xml
===================================================================
--- trunk/examples/javaee/mdb-cmp-setrollbackonly/server/jbm-users.xml (rev 0)
+++ trunk/examples/javaee/mdb-cmp-setrollbackonly/server/jbm-users.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,7 @@
+<configuration xmlns="urn:jboss:messaging" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-users.xsd">
+ <!-- the default user. this is used where username is null-->
+ <defaultuser name="guest" password="guest">
+ <role name="guest"/>
+ </defaultuser>
+</configuration>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-setrollbackonly/src/org/jboss/javaee/example/MDB_CMP_SetRollbackOnlyClientExample.java
===================================================================
--- trunk/examples/javaee/mdb-cmp-setrollbackonly/src/org/jboss/javaee/example/MDB_CMP_SetRollbackOnlyClientExample.java (rev 0)
+++ trunk/examples/javaee/mdb-cmp-setrollbackonly/src/org/jboss/javaee/example/MDB_CMP_SetRollbackOnlyClientExample.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,84 @@
+/*
+ * 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.javaee.example;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ */
+public class MDB_CMP_SetRollbackOnlyClientExample
+{
+ public static void main(String[] args) throws Exception
+ {
+ Connection connection = null;
+ InitialContext initialContext = null;
+ try
+ {
+ //Step 1. Create an initial context to perform the JNDI lookup.
+ initialContext = new InitialContext();
+
+ //Step 2. Perfom a lookup on the queue
+ Queue queue = (Queue) initialContext.lookup("/queue/testQueue");
+
+ //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 and 10 in MDBExample
+ }
+ finally
+ {
+ //Step 11. Be sure to close our JMS resources!
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ if(connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-setrollbackonly/src/org/jboss/javaee/example/server/MDB_CMP_SetRollbackOnlyExample.java
===================================================================
--- trunk/examples/javaee/mdb-cmp-setrollbackonly/src/org/jboss/javaee/example/server/MDB_CMP_SetRollbackOnlyExample.java (rev 0)
+++ trunk/examples/javaee/mdb-cmp-setrollbackonly/src/org/jboss/javaee/example/server/MDB_CMP_SetRollbackOnlyExample.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,79 @@
+/*
+ * 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.javaee.example.server;
+
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.ejb.MessageDrivenContext;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ */
+ at MessageDriven(name = "MDB_CMP_SetRollbackOnlyExample",
+ activationConfig =
+ {
+ @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/testQueue")
+ })
+ at TransactionManagement(value= TransactionManagementType.CONTAINER)
+ at TransactionAttribute(value= TransactionAttributeType.REQUIRED)
+public class MDB_CMP_SetRollbackOnlyExample implements MessageListener
+{
+ @Resource
+ MessageDrivenContext ctx;
+
+ public void onMessage(Message message)
+ {
+ try
+ {
+ //Step 9. We know the client is sending a text message so we cast
+ TextMessage textMessage = (TextMessage)message;
+
+ //Step 10. get the text from the message.
+ String text = textMessage.getText();
+ if(!textMessage.getJMSRedelivered())
+ {
+ System.out.println("message " + text + " received for the first time");
+ ctx.setRollbackOnly();
+ }
+ else
+ {
+ System.out.println("message " + text + " received for the second time");
+ }
+
+
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-tx-local/build.xml
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-local/build.xml (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-local/build.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- =========================================================================================== -->
+<!-- -->
+<!-- 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 Java EE MDB Example">
+
+ <import file="../common/build.xml"/>
+
+ <target name="run">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.jboss.javaee.example.MDB_CMP_TxLocalClientExample"/>
+ </antcall>
+ </target>
+</project>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-tx-local/config/ant.properties
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-local/config/ant.properties (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-local/config/ant.properties 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1 @@
+example.name=mdb-cmp-tx-local
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-tx-local/config/jndi.properties
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-local/config/jndi.properties (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-local/config/jndi.properties 2009-07-22 13:46:38 UTC (rev 7602)
@@ -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/javaee/mdb-cmp-tx-local/readme.html
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-local/readme.html (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-local/readme.html 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,100 @@
+<html>
+ <head>
+ <title>JBoss Messaging Java EE MDB Example</title>
+ <link rel="stylesheet" type="text/css" href="../../common/common.css">
+ </head>
+ <body>
+ <h1>Java EE MDB Example</h1>
+ <br>
+ <p>This example shows you how to send a message to an MDB</p>
+ <p>
+ The example will send deploy a simple MDB and demonstrate sending a message and the MDB consuming it
+ </p>
+
+ <h2>JBoss AS configuration</h2>
+
+ <p>Please refer to JBoss Messaging Quickstart guide to <a href="../../../docs/quickstart-guide/en/html_single/index.html#installation.jboss">install it in JBoss AS 5<a></p>
+
+ <h2>Example step-by-step</h2>
+ <p><i>To deploy and start the server, simply type <code>ant deploy</code> from the example directory</i></p>
+ <p><i>To run the example, simply type <code>ant</code> from the example directory</i></p>
+ <p><i>To remove the example profile, simply type <code>ant undeploy</code> from the example directory</i></p>
+ <p><i> ** make sure that JBOSS_HOME is set to the Jboss installation directory</i></p>
+ <br>
+ <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 it's properties from the <code>jndi.properties</code> file in the directory <code>config</code></li>
+ <pre>
+ <code>initialContext = new InitialContext();</code>
+ </pre>
+
+ <li>We look up the JMS queue object from JNDI</li>
+ <pre>
+ <code>Queue queue = (Queue) initialContext.lookup("/queue/testQueue");</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(queue);</code>
+ </pre>
+
+ <li>We create a JMS text messages that we are going to send.</li>
+ <pre>
+ <code> TextMessage message = session.createTextMessage("This is a text message");</code>
+ </pre>
+
+ <li>We send messages to the queue</li>
+ <pre>
+ <code>messageProducer.send(message);</code>
+ </pre>
+
+ <li>The MDB receives the message<br />
+ We know the message is a TextMessage so we cast to it.
+ </li>
+ <pre>
+ <code>TextMessage tm = (TextMessage)message;</code>
+ </pre>
+
+ <li>The MDB gets the text and prints it
+ </li>
+ <pre>
+ <code>String text = tm.getText();
+ System.out.println("message " + text + " received");
+ </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>
+ </body>
+</html>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-tx-local/server/jbm-configuration.xml
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-local/server/jbm-configuration.xml (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-local/server/jbm-configuration.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,67 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-configuration.xsd">
+
+ <bindings-directory>${jboss.server.data.dir}/messaging/bindings</bindings-directory>
+
+ <journal-directory>${jboss.server.data.dir}/messaging/journal</journal-directory>
+
+ <large-messages-directory>${jboss.server.data.dir}/messaging/largemessages</large-messages-directory>
+
+ <paging-directory>${jboss.server.data.dir}/messaging/paging</paging-directory>
+
+ <!-- Connectors -->
+ <connectors>
+ <connector name="netty">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+ <param key="jbm.remoting.netty.host" value="${jbm.remoting.netty.host:localhost}" type="String"/>
+ <param key="jbm.remoting.netty.port" value="${jbm.remoting.netty.port:5445}" type="Integer"/>
+ </connector>
+
+ <connector name="in-vm">
+ <factory-class>org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory</factory-class>
+ </connector>
+
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <!-- In VM acceptor -->
+ <acceptor name="in-vm">
+ <factory-class>org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory</factory-class>
+ <param key="jbm.remoting.invm.serverid" value="0" type="Integer"/>
+ </acceptor>
+
+ <!-- Netty TCP Acceptor -->
+ <acceptor name="netty">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+ <param key="jbm.remoting.netty.host" value="${jbm.remoting.netty.host:localhost}" type="String"/>
+ <param key="jbm.remoting.netty.port" value="${jbm.remoting.netty.port:5445}" type="Integer"/>
+ </acceptor>
+ </acceptors>
+
+ <security-settings>
+ <security-setting match="#">
+ <permission type="createTempQueue" roles="guest"/>
+ <permission type="deleteTempQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+ <address-settings>
+ <!--default for catch all-->
+ <address-setting match="#">
+ <clustered>false</clustered>
+ <dead-letter-address>jms.queue.DLQ</dead-letter-address>
+ <expiry-address>jms.queue.ExpiryQueue</expiry-address>
+ <redelivery-delay>0</redelivery-delay>
+ <max-size-bytes>-1</max-size-bytes>
+ <page-size-bytes>10485760</page-size-bytes>
+ <distribution-policy-class>org.jboss.messaging.core.server.impl.RoundRobinDistributor</distribution-policy-class>
+ <message-counter-history-day-limit>10</message-counter-history-day-limit>
+ </address-setting>
+ </address-settings>
+
+
+</configuration>
Added: trunk/examples/javaee/mdb-cmp-tx-local/server/jbm-jms.xml
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-local/server/jbm-jms.xml (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-local/server/jbm-jms.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,16 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-jms.xsd">
+
+ <connection-factory name="ConnectionFactory">
+ <connector-ref connector-name="netty"/>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ <entry name="XAConnectionFactory"/>
+ </entries>
+ </connection-factory>
+
+ <queue name="testQueue">
+ <entry name="/queue/testQueue"/>
+ </queue>
+</configuration>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-tx-local/server/jbm-users.xml
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-local/server/jbm-users.xml (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-local/server/jbm-users.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,7 @@
+<configuration xmlns="urn:jboss:messaging" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-users.xsd">
+ <!-- the default user. this is used where username is null-->
+ <defaultuser name="guest" password="guest">
+ <role name="guest"/>
+ </defaultuser>
+</configuration>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-tx-local/src/org/jboss/javaee/example/MDB_CMP_TxLocalClientExample.java
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-local/src/org/jboss/javaee/example/MDB_CMP_TxLocalClientExample.java (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-local/src/org/jboss/javaee/example/MDB_CMP_TxLocalClientExample.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,84 @@
+/*
+ * 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.javaee.example;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ */
+public class MDB_CMP_TxLocalClientExample
+{
+ public static void main(String[] args) throws Exception
+ {
+ Connection connection = null;
+ InitialContext initialContext = null;
+ try
+ {
+ //Step 1. Create an initial context to perform the JNDI lookup.
+ initialContext = new InitialContext();
+
+ //Step 2. Perfom a lookup on the queue
+ Queue queue = (Queue) initialContext.lookup("/queue/testQueue");
+
+ //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 and 10 in MDBExample
+ }
+ finally
+ {
+ //Step 11. Be sure to close our JMS resources!
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ if(connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-tx-local/src/org/jboss/javaee/example/server/MDB_CMP_TxLocalExample.java
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-local/src/org/jboss/javaee/example/server/MDB_CMP_TxLocalExample.java (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-local/src/org/jboss/javaee/example/server/MDB_CMP_TxLocalExample.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,98 @@
+/*
+ * 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.javaee.example.server;
+
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ */
+ at MessageDriven(name = "MDB_CMP_TxLocalExample",
+ activationConfig =
+ {
+ @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/testQueue"),
+ @ActivationConfigProperty(propertyName = "useLocalTx", propertyValue = "true")
+ })
+ at TransactionManagement(value = TransactionManagementType.CONTAINER)
+ at TransactionAttribute(value = TransactionAttributeType.NOT_SUPPORTED)
+public class MDB_CMP_TxLocalExample implements MessageListener
+{
+ @Resource(mappedName = "java:/TransactionManager")
+ private TransactionManager tm;
+
+ public void onMessage(Message message)
+ {
+ try
+ {
+ //Step 9. We know the client is sending a text message so we cast
+ TextMessage textMessage = (TextMessage) message;
+
+ //Step 10. get the text from the message.
+ String text = textMessage.getText();
+
+ System.out.println("message " + text + " received");
+
+ if (!textMessage.getJMSRedelivered())
+ {
+ Transaction tx = tm.getTransaction();
+
+ if (tx != null)
+ {
+ System.out.println("something is wrong, there should be no global transaction: " + tx);
+ }
+ else
+ {
+ System.out.println("there is no global transaction, altho the messge delivery is using a local transaction");
+ System.out.println("lets throw an exception and see what happens");
+ throw new RuntimeException("DOH!");
+ }
+ }
+ else
+ {
+ System.out.println("The message was redelivered since the message delivery used a local transaction");
+ }
+
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ catch(SystemException e)
+ {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-tx-not-supported/build.xml
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-not-supported/build.xml (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-not-supported/build.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- =========================================================================================== -->
+<!-- -->
+<!-- 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 Java EE MDB Example">
+
+ <import file="../common/build.xml"/>
+
+ <target name="run">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.jboss.javaee.example.MDB_CMP_TxNotSupportedClientExample"/>
+ </antcall>
+ </target>
+</project>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-tx-not-supported/config/ant.properties
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-not-supported/config/ant.properties (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-not-supported/config/ant.properties 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1 @@
+example.name=mdb-cmp-tx-not-required
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-tx-not-supported/config/jndi.properties
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-not-supported/config/jndi.properties (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-not-supported/config/jndi.properties 2009-07-22 13:46:38 UTC (rev 7602)
@@ -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/javaee/mdb-cmp-tx-not-supported/readme.html
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-not-supported/readme.html (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-not-supported/readme.html 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,100 @@
+<html>
+ <head>
+ <title>JBoss Messaging Java EE MDB Example</title>
+ <link rel="stylesheet" type="text/css" href="../../common/common.css">
+ </head>
+ <body>
+ <h1>Java EE MDB Example</h1>
+ <br>
+ <p>This example shows you how to send a message to an MDB</p>
+ <p>
+ The example will send deploy a simple MDB and demonstrate sending a message and the MDB consuming it
+ </p>
+
+ <h2>JBoss AS configuration</h2>
+
+ <p>Please refer to JBoss Messaging Quickstart guide to <a href="../../../docs/quickstart-guide/en/html_single/index.html#installation.jboss">install it in JBoss AS 5<a></p>
+
+ <h2>Example step-by-step</h2>
+ <p><i>To deploy and start the server, simply type <code>ant deploy</code> from the example directory</i></p>
+ <p><i>To run the example, simply type <code>ant</code> from the example directory</i></p>
+ <p><i>To remove the example profile, simply type <code>ant undeploy</code> from the example directory</i></p>
+ <p><i> ** make sure that JBOSS_HOME is set to the Jboss installation directory</i></p>
+ <br>
+ <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 it's properties from the <code>jndi.properties</code> file in the directory <code>config</code></li>
+ <pre>
+ <code>initialContext = new InitialContext();</code>
+ </pre>
+
+ <li>We look up the JMS queue object from JNDI</li>
+ <pre>
+ <code>Queue queue = (Queue) initialContext.lookup("/queue/testQueue");</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(queue);</code>
+ </pre>
+
+ <li>We create a JMS text messages that we are going to send.</li>
+ <pre>
+ <code> TextMessage message = session.createTextMessage("This is a text message");</code>
+ </pre>
+
+ <li>We send messages to the queue</li>
+ <pre>
+ <code>messageProducer.send(message);</code>
+ </pre>
+
+ <li>The MDB receives the message<br />
+ We know the message is a TextMessage so we cast to it.
+ </li>
+ <pre>
+ <code>TextMessage tm = (TextMessage)message;</code>
+ </pre>
+
+ <li>The MDB gets the text and prints it
+ </li>
+ <pre>
+ <code>String text = tm.getText();
+ System.out.println("message " + text + " received");
+ </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>
+ </body>
+</html>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-tx-not-supported/server/jbm-configuration.xml
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-not-supported/server/jbm-configuration.xml (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-not-supported/server/jbm-configuration.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,67 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-configuration.xsd">
+
+ <bindings-directory>${jboss.server.data.dir}/messaging/bindings</bindings-directory>
+
+ <journal-directory>${jboss.server.data.dir}/messaging/journal</journal-directory>
+
+ <large-messages-directory>${jboss.server.data.dir}/messaging/largemessages</large-messages-directory>
+
+ <paging-directory>${jboss.server.data.dir}/messaging/paging</paging-directory>
+
+ <!-- Connectors -->
+ <connectors>
+ <connector name="netty">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+ <param key="jbm.remoting.netty.host" value="${jbm.remoting.netty.host:localhost}" type="String"/>
+ <param key="jbm.remoting.netty.port" value="${jbm.remoting.netty.port:5445}" type="Integer"/>
+ </connector>
+
+ <connector name="in-vm">
+ <factory-class>org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory</factory-class>
+ </connector>
+
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <!-- In VM acceptor -->
+ <acceptor name="in-vm">
+ <factory-class>org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory</factory-class>
+ <param key="jbm.remoting.invm.serverid" value="0" type="Integer"/>
+ </acceptor>
+
+ <!-- Netty TCP Acceptor -->
+ <acceptor name="netty">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+ <param key="jbm.remoting.netty.host" value="${jbm.remoting.netty.host:localhost}" type="String"/>
+ <param key="jbm.remoting.netty.port" value="${jbm.remoting.netty.port:5445}" type="Integer"/>
+ </acceptor>
+ </acceptors>
+
+ <security-settings>
+ <security-setting match="#">
+ <permission type="createTempQueue" roles="guest"/>
+ <permission type="deleteTempQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+ <address-settings>
+ <!--default for catch all-->
+ <address-setting match="#">
+ <clustered>false</clustered>
+ <dead-letter-address>jms.queue.DLQ</dead-letter-address>
+ <expiry-address>jms.queue.ExpiryQueue</expiry-address>
+ <redelivery-delay>0</redelivery-delay>
+ <max-size-bytes>-1</max-size-bytes>
+ <page-size-bytes>10485760</page-size-bytes>
+ <distribution-policy-class>org.jboss.messaging.core.server.impl.RoundRobinDistributor</distribution-policy-class>
+ <message-counter-history-day-limit>10</message-counter-history-day-limit>
+ </address-setting>
+ </address-settings>
+
+
+</configuration>
Added: trunk/examples/javaee/mdb-cmp-tx-not-supported/server/jbm-jms.xml
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-not-supported/server/jbm-jms.xml (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-not-supported/server/jbm-jms.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,16 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-jms.xsd">
+
+ <connection-factory name="ConnectionFactory">
+ <connector-ref connector-name="netty"/>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ <entry name="XAConnectionFactory"/>
+ </entries>
+ </connection-factory>
+
+ <queue name="testQueue">
+ <entry name="/queue/testQueue"/>
+ </queue>
+</configuration>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-tx-not-supported/server/jbm-users.xml
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-not-supported/server/jbm-users.xml (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-not-supported/server/jbm-users.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,7 @@
+<configuration xmlns="urn:jboss:messaging" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-users.xsd">
+ <!-- the default user. this is used where username is null-->
+ <defaultuser name="guest" password="guest">
+ <role name="guest"/>
+ </defaultuser>
+</configuration>
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-tx-not-supported/src/org/jboss/javaee/example/MDB_CMP_TxNotSupportedClientExample.java
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-not-supported/src/org/jboss/javaee/example/MDB_CMP_TxNotSupportedClientExample.java (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-not-supported/src/org/jboss/javaee/example/MDB_CMP_TxNotSupportedClientExample.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,84 @@
+/*
+ * 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.javaee.example;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ */
+public class MDB_CMP_TxNotSupportedClientExample
+{
+ public static void main(String[] args) throws Exception
+ {
+ Connection connection = null;
+ InitialContext initialContext = null;
+ try
+ {
+ //Step 1. Create an initial context to perform the JNDI lookup.
+ initialContext = new InitialContext();
+
+ //Step 2. Perfom a lookup on the queue
+ Queue queue = (Queue) initialContext.lookup("/queue/testQueue");
+
+ //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 and 10 in MDBExample
+ }
+ finally
+ {
+ //Step 11. Be sure to close our JMS resources!
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ if(connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/examples/javaee/mdb-cmp-tx-not-supported/src/org/jboss/javaee/example/server/MDB_CMP_TxNotSupported.java
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-not-supported/src/org/jboss/javaee/example/server/MDB_CMP_TxNotSupported.java (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-not-supported/src/org/jboss/javaee/example/server/MDB_CMP_TxNotSupported.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,83 @@
+/*
+ * 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.javaee.example.server;
+
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ */
+ at MessageDriven(name = "MDB_CMP_TxNotSupported",
+ activationConfig =
+ {
+ @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/testQueue"),
+ @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")
+ })
+ at TransactionManagement(value= TransactionManagementType.CONTAINER)
+ at TransactionAttribute(value= TransactionAttributeType.NOT_SUPPORTED)
+public class MDB_CMP_TxNotSupported implements MessageListener
+{
+ @Resource(mappedName = "java:/TransactionManager")
+ private TransactionManager tm;
+
+ public void onMessage(Message message)
+ {
+ try
+ {
+ //Step 9. We know the client is sending a text message so we cast
+ TextMessage textMessage = (TextMessage)message;
+
+ //Step 10. get the text from the message.
+ String text = textMessage.getText();
+
+ System.out.println("message " + text + " received");
+
+ //Step 3. lets look at the transaction to make sure there isn't one.
+ Transaction tx = tm.getTransaction();
+
+ if(tx == null)
+ {
+ System.out.println("tx is null, just as expected");
+ }
+ else
+ {
+ System.out.println("something is wrong, I wasn't expecting a transaction");
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/examples/javaee/mdb-cmp-tx-required (from rev 7587, trunk/examples/javaee/mdb)
Modified: trunk/examples/javaee/mdb-cmp-tx-required/build.xml
===================================================================
--- trunk/examples/javaee/mdb/build.xml 2009-07-19 09:25:34 UTC (rev 7587)
+++ trunk/examples/javaee/mdb-cmp-tx-required/build.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -31,7 +31,7 @@
<target name="run">
<antcall target="runExample">
- <param name="example.classname" value="org.jboss.javaee.example.MDBClientExample"/>
+ <param name="example.classname" value="org.jboss.javaee.example.MDB_CMP_TxRequiredClientExample"/>
</antcall>
</target>
</project>
\ No newline at end of file
Modified: trunk/examples/javaee/mdb-cmp-tx-required/config/ant.properties
===================================================================
--- trunk/examples/javaee/mdb/config/ant.properties 2009-07-19 09:25:34 UTC (rev 7587)
+++ trunk/examples/javaee/mdb-cmp-tx-required/config/ant.properties 2009-07-22 13:46:38 UTC (rev 7602)
@@ -1 +1 @@
-example.name=mdb
\ No newline at end of file
+example.name=mdb-cmp-tx-required
\ No newline at end of file
Deleted: trunk/examples/javaee/mdb-cmp-tx-required/src/org/jboss/javaee/example/MDBClientExample.java
===================================================================
--- trunk/examples/javaee/mdb/src/org/jboss/javaee/example/MDBClientExample.java 2009-07-19 09:25:34 UTC (rev 7587)
+++ trunk/examples/javaee/mdb-cmp-tx-required/src/org/jboss/javaee/example/MDBClientExample.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -1,84 +0,0 @@
-/*
- * 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.javaee.example;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.naming.InitialContext;
-
-/**
- * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
- */
-public class MDBClientExample
-{
- public static void main(String[] args) throws Exception
- {
- Connection connection = null;
- InitialContext initialContext = null;
- try
- {
- //Step 1. Create an initial context to perform the JNDI lookup.
- initialContext = new InitialContext();
-
- //Step 2. Perfom a lookup on the queue
- Queue queue = (Queue) initialContext.lookup("/queue/testQueue");
-
- //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 and 10 in MDBExample
- }
- finally
- {
- //Step 11. Be sure to close our JMS resources!
- if (initialContext != null)
- {
- initialContext.close();
- }
- if(connection != null)
- {
- connection.close();
- }
- }
- }
-}
Added: trunk/examples/javaee/mdb-cmp-tx-required/src/org/jboss/javaee/example/MDB_CMP_TxRequiredClientExample.java
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-required/src/org/jboss/javaee/example/MDB_CMP_TxRequiredClientExample.java (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-required/src/org/jboss/javaee/example/MDB_CMP_TxRequiredClientExample.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,84 @@
+/*
+ * 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.javaee.example;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ */
+public class MDB_CMP_TxRequiredClientExample
+{
+ public static void main(String[] args) throws Exception
+ {
+ Connection connection = null;
+ InitialContext initialContext = null;
+ try
+ {
+ //Step 1. Create an initial context to perform the JNDI lookup.
+ initialContext = new InitialContext();
+
+ //Step 2. Perfom a lookup on the queue
+ Queue queue = (Queue) initialContext.lookup("/queue/testQueue");
+
+ //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 and 10 in MDBExample
+ }
+ finally
+ {
+ //Step 11. Be sure to close our JMS resources!
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ if(connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+}
Deleted: trunk/examples/javaee/mdb-cmp-tx-required/src/org/jboss/javaee/example/server/MDBExample.java
===================================================================
--- trunk/examples/javaee/mdb/src/org/jboss/javaee/example/server/MDBExample.java 2009-07-19 09:25:34 UTC (rev 7587)
+++ trunk/examples/javaee/mdb-cmp-tx-required/src/org/jboss/javaee/example/server/MDBExample.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -1,60 +0,0 @@
-/*
- * 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.javaee.example.server;
-
-import javax.ejb.ActivationConfigProperty;
-import javax.ejb.MessageDriven;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.TextMessage;
-
-/**
- * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
- */
- at MessageDriven(name = "MessageMDBExample",
- activationConfig =
- {
- @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
- @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/testQueue"),
- @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")
- })
-public class MDBExample implements MessageListener
-{
- public void onMessage(Message message)
- {
- try
- {
- //Step 9. We know the client is sending a text message so we cast
- TextMessage tm = (TextMessage)message;
-
- //Step 10. get the text from the message.
- String text = tm.getText();
-
- System.out.println("message " + text + " received");
- }
- catch (JMSException e)
- {
- e.printStackTrace();
- }
- }
-}
Added: trunk/examples/javaee/mdb-cmp-tx-required/src/org/jboss/javaee/example/server/MDB_CMP_TxRequiredExample.java
===================================================================
--- trunk/examples/javaee/mdb-cmp-tx-required/src/org/jboss/javaee/example/server/MDB_CMP_TxRequiredExample.java (rev 0)
+++ trunk/examples/javaee/mdb-cmp-tx-required/src/org/jboss/javaee/example/server/MDB_CMP_TxRequiredExample.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -0,0 +1,88 @@
+/*
+ * 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.javaee.example.server;
+
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.org">Andy Taylor</a>
+ */
+ at MessageDriven(name = "MDB_CMP_TxRequiredExample",
+ activationConfig =
+ {
+ @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/testQueue")
+ })
+ at TransactionManagement(value= TransactionManagementType.CONTAINER)
+ at TransactionAttribute(value= TransactionAttributeType.REQUIRED)
+public class MDB_CMP_TxRequiredExample implements MessageListener
+{
+ @Resource(mappedName = "java:/TransactionManager")
+ private TransactionManager tm;
+
+ public void onMessage(Message message)
+ {
+ try
+ {
+ //Step 9. We know the client is sending a text message so we cast
+ TextMessage textMessage = (TextMessage)message;
+
+ //Step 10. get the text from the message.
+ String text = textMessage.getText();
+
+ System.out.println("message " + text + " received");
+
+ //Step 11. Lets take a look at the transaction and see whats happening.
+ Transaction tx = tm.getTransaction();
+
+ if(tx != null)
+ {
+ System.out.println("we're in the middle of a transaction: " + tx);
+ }
+ else
+ {
+ System.out.println("something is wrong, I was expecting a transaction");
+ }
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ catch (SystemException e)
+ {
+ e.printStackTrace();
+ }
+ }
+}
Modified: trunk/examples/javaee/messaging-javaee-examples.iml
===================================================================
--- trunk/examples/javaee/messaging-javaee-examples.iml 2009-07-22 11:58:52 UTC (rev 7601)
+++ trunk/examples/javaee/messaging-javaee-examples.iml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -56,11 +56,15 @@
<sourceFolder url="file://$MODULE_DIR$/hajndi/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/jca-config/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/jms-bridge/src" isTestSource="false" />
- <sourceFolder url="file://$MODULE_DIR$/mdb/src" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/mdb-bmp/src" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/mdb-cmp-setrollbackonly/src" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/mdb-cmp-tx-local/src" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/mdb-cmp-tx-not-supported/src" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/mdb-cmp-tx-required/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/servlet-ssl-example/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/servlet-transport/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/xarecovery/src" isTestSource="false" />
- <excludeFolder url="file://$MODULE_DIR$/mdb/build" />
+ <excludeFolder url="file://$MODULE_DIR$/mdb-cmp-tx-required/build" />
<excludeFolder url="file://$MODULE_DIR$/output" />
<excludeFolder url="file://$MODULE_DIR$/servlet-ssl-example/build" />
</content>
Modified: trunk/messaging.ipr
===================================================================
--- trunk/messaging.ipr 2009-07-22 11:58:52 UTC (rev 7601)
+++ trunk/messaging.ipr 2009-07-22 13:46:38 UTC (rev 7602)
@@ -122,7 +122,7 @@
<maximumStackSize value="32" />
<properties />
</buildFile>
- <buildFile url="file://$PROJECT_DIR$/examples/javaee/mdb/build.xml">
+ <buildFile url="file://$PROJECT_DIR$/examples/javaee/mdb-cmp-tx-required/build.xml">
<additionalClassPath />
<antReference projectDefault="true" />
<customJdkName value="" />
Modified: trunk/src/config/ra.xml
===================================================================
--- trunk/src/config/ra.xml 2009-07-22 11:58:52 UTC (rev 7601)
+++ trunk/src/config/ra.xml 2009-07-22 13:46:38 UTC (rev 7602)
@@ -54,13 +54,13 @@
<config-property-type>java.lang.String</config-property-type>
<config-property-value>jbm.remoting.invm.serverid=0</config-property-value>
</config-property>
- <config-property>
- <description>Use XA methods to obtain connections?</description>
- <config-property-name>UseXA</config-property-name>
+ <!-- <config-property>
+ <description>Use A local Transaction instead of XA?</description>
+ <config-property-name>UseLocalTx</config-property-name>
<config-property-type>java.lang.Boolean</config-property-type>
- <config-property-value>true</config-property-value>
+ <config-property-value>false</config-property-value>
</config-property>
- <!--<config-property>
+ <config-property>
<description>The user name used to login to the JMS server</description>
<config-property-name>UserName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
Modified: trunk/src/main/org/jboss/messaging/ra/JBMRAProperties.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMRAProperties.java 2009-07-22 11:58:52 UTC (rev 7601)
+++ trunk/src/main/org/jboss/messaging/ra/JBMRAProperties.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -50,8 +50,8 @@
/** The password */
private String password;
- /** Use XA */
- private Boolean useXA;
+ /** Use Local TX instead of XA */
+ private Boolean localTx = false;
/**
* Constructor
@@ -127,32 +127,32 @@
* Get the use XA flag
* @return The value
*/
- public Boolean getUseXA()
+ public Boolean getUseLocalTx()
{
if (trace)
{
- log.trace("getUseXA()");
+ log.trace("getUseLocalTx()");
}
- return useXA;
+ return localTx;
}
/**
* Set the use XA flag
- * @param xa The value
+ * @param localTx The value
*/
- public void setUseXA(final Boolean xa)
+ public void setUseLocalTx(final Boolean localTx)
{
if (trace)
{
- log.trace("setUseXA(" + xa + ")");
+ log.trace("setUseLocalTx(" + localTx + ")");
}
- useXA = xa;
+ this.localTx = localTx;
}
/**
- * Use XA for communication
+ * Use local tx instead of XA for
* @return The value
*/
public boolean isUseXA()
@@ -162,12 +162,8 @@
log.trace("isUseXA()");
}
- if (useXA == null)
- {
- return false;
- }
+ return localTx != null && localTx;
- return useXA.booleanValue();
}
}
Modified: trunk/src/main/org/jboss/messaging/ra/JBMResourceAdapter.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMResourceAdapter.java 2009-07-22 11:58:52 UTC (rev 7601)
+++ trunk/src/main/org/jboss/messaging/ra/JBMResourceAdapter.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -28,7 +28,6 @@
import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.jms.client.JBossConnectionFactory;
-import org.jboss.messaging.jms.client.JBossSession;
import org.jboss.messaging.ra.inflow.JBMActivation;
import org.jboss.messaging.ra.inflow.JBMActivationSpec;
@@ -1054,6 +1053,7 @@
{
return raProperties.getScheduledThreadPoolMaxSize();
}
+
public void setScheduledThreadPoolMaxSize(Integer scheduledThreadPoolMaxSize)
{
if (trace)
@@ -1077,11 +1077,11 @@
raProperties.setThreadPoolMaxSize(threadPoolMaxSize);
}
- public Boolean getUseGlobalPools()
- {
- return raProperties.isUseGlobalPools();
- }
-
+ public Boolean getUseGlobalPools()
+ {
+ return raProperties.isUseGlobalPools();
+ }
+
public void setUseGlobalPools(Boolean useGlobalPools)
{
if (trace)
@@ -1186,29 +1186,29 @@
*
* @return The value
*/
- public Boolean getUseXA()
+ public Boolean getUseLocalTx()
{
if (trace)
{
- log.trace("getUseXA()");
+ log.trace("getUseLocalTx()");
}
- return raProperties.getUseXA();
+ return raProperties.getUseLocalTx();
}
/**
* Set the use XA flag
*
- * @param xa The value
+ * @param localTx The value
*/
- public void setUseXA(final Boolean xa)
+ public void setUseLocalTx(final Boolean localTx)
{
if (trace)
{
- log.trace("setUseXA(" + xa + ")");
+ log.trace("setUseXA(" + localTx + ")");
}
- raProperties.setUseXA(xa);
+ raProperties.setUseLocalTx(localTx);
}
/**
@@ -1274,24 +1274,6 @@
return ctx.getWorkManager();
}
- public ClientSession createSession(final int ackMode,
- final String user,
- final String pass,
- final Boolean preAck,
- final Integer dupsOkBatchSize,
- final Integer transactionBatchSize,
- final boolean deliveryTransacted) throws Exception
- {
- return createSession(sessionFactory,
- ackMode,
- user,
- pass,
- preAck,
- dupsOkBatchSize,
- transactionBatchSize,
- deliveryTransacted);
- }
-
public ClientSession createSession(final ClientSessionFactory parameterFactory,
final int ackMode,
final String user,
@@ -1299,65 +1281,79 @@
final Boolean preAck,
final Integer dupsOkBatchSize,
final Integer transactionBatchSize,
- final boolean deliveryTransacted) throws Exception
+ final boolean deliveryTransacted,
+ final boolean useLocalTx) throws Exception
{
ClientSession result;
- boolean actPreAck = preAck != null ? preAck : ClientSessionFactoryImpl.DEFAULT_PRE_ACKNOWLEDGE;
- int actDupsOkBatchSize = dupsOkBatchSize != null ? dupsOkBatchSize
- : ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE;
- int actTxBatchSize = transactionBatchSize != null ? transactionBatchSize
- : ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE;
- switch (ackMode)
+ //if we are CMP or BMP using local tx we ignore the ack mode as we are transactional
+ if (deliveryTransacted || useLocalTx)
{
- case Session.SESSION_TRANSACTED:
+ int actTxBatchSize = transactionBatchSize != null ? transactionBatchSize
+ : ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE;
+ if (useLocalTx)
+ {
result = parameterFactory.createSession(user,
pass,
- deliveryTransacted,
false,
false,
- actPreAck,
- actTxBatchSize);
- break;
- case Session.AUTO_ACKNOWLEDGE:
- result = parameterFactory.createSession(user,
- pass,
- deliveryTransacted,
- true,
false,
- actPreAck,
+ false,
actTxBatchSize);
- break;
- case Session.DUPS_OK_ACKNOWLEDGE:
+ }
+ else
+ {
result = parameterFactory.createSession(user,
pass,
- deliveryTransacted,
true,
false,
- actPreAck,
- actDupsOkBatchSize);
- break;
- case Session.CLIENT_ACKNOWLEDGE:
- result = parameterFactory.createSession(user,
- pass,
- deliveryTransacted,
false,
false,
- actPreAck,
actTxBatchSize);
- break;
- case JBossSession.PRE_ACKNOWLEDGE:
+ }
+ }
+ else
+ {
+ if (preAck != null && preAck)
+ {
result = parameterFactory.createSession(user,
pass,
- deliveryTransacted,
false,
true,
- actPreAck,
- actTxBatchSize);
- break;
- default:
- throw new IllegalArgumentException("Invalid ackmode: " + ackMode);
+ true,
+ true,
+ -1);
+ }
+ else
+ {
+ //only auto ack and dups ok are supported
+ switch (ackMode)
+ {
+ case Session.AUTO_ACKNOWLEDGE:
+ result = parameterFactory.createSession(user,
+ pass,
+ false,
+ true,
+ true,
+ false,
+ 0);
+ break;
+ case Session.DUPS_OK_ACKNOWLEDGE:
+ int actDupsOkBatchSize = dupsOkBatchSize != null ? dupsOkBatchSize
+ : ClientSessionFactoryImpl.DEFAULT_ACK_BATCH_SIZE;
+ result = parameterFactory.createSession(user,
+ pass,
+ false,
+ true,
+ true,
+ false,
+ actDupsOkBatchSize);
+ break;
+ default:
+ throw new IllegalArgumentException("Invalid ackmode: " + ackMode);
+ }
+ }
}
log.debug("Using queue connection " + result);
@@ -1460,118 +1456,118 @@
{
cf.setBlockOnPersistentSend(val);
}
- val = overrideProperties.isFailoverOnServerShutdown() != null?overrideProperties.isFailoverOnServerShutdown():raProperties.isFailoverOnServerShutdown();
- if(val != null)
+ val = overrideProperties.isFailoverOnServerShutdown() != null ? overrideProperties.isFailoverOnServerShutdown() : raProperties.isFailoverOnServerShutdown();
+ if (val != null)
{
cf.setFailoverOnServerShutdown(val);
}
- val = overrideProperties.isPreAcknowledge() != null?overrideProperties.isPreAcknowledge():raProperties.isPreAcknowledge();
- if(val != null)
+ val = overrideProperties.isPreAcknowledge() != null ? overrideProperties.isPreAcknowledge() : raProperties.isPreAcknowledge();
+ if (val != null)
{
cf.setPreAcknowledge(val);
}
- val = overrideProperties.isUseGlobalPools() != null?overrideProperties.isUseGlobalPools():raProperties.isUseGlobalPools();
- if(val != null)
+ val = overrideProperties.isUseGlobalPools() != null ? overrideProperties.isUseGlobalPools() : raProperties.isUseGlobalPools();
+ if (val != null)
{
cf.setUseGlobalPools(val);
}
- Integer val2 = overrideProperties.getConsumerMaxRate() != null?overrideProperties.getConsumerMaxRate():raProperties.getConsumerMaxRate();
- if(val2 != null)
+ Integer val2 = overrideProperties.getConsumerMaxRate() != null ? overrideProperties.getConsumerMaxRate() : raProperties.getConsumerMaxRate();
+ if (val2 != null)
{
cf.setConsumerMaxRate(val2);
}
- val2 = overrideProperties.getConsumerWindowSize() != null?overrideProperties.getConsumerWindowSize():raProperties.getConsumerWindowSize();
- if(val2 != null)
+ val2 = overrideProperties.getConsumerWindowSize() != null ? overrideProperties.getConsumerWindowSize() : raProperties.getConsumerWindowSize();
+ if (val2 != null)
{
cf.setConsumerWindowSize(val2);
}
- val2 = overrideProperties.getDupsOKBatchSize() != null?overrideProperties.getDupsOKBatchSize():raProperties.getDupsOKBatchSize();
- if(val2 != null)
+ val2 = overrideProperties.getDupsOKBatchSize() != null ? overrideProperties.getDupsOKBatchSize() : raProperties.getDupsOKBatchSize();
+ if (val2 != null)
{
cf.setDupsOKBatchSize(val2);
}
- val2 = overrideProperties.getMaxConnections() != null?overrideProperties.getMaxConnections():raProperties.getMaxConnections();
- if(val2 != null)
+ val2 = overrideProperties.getMaxConnections() != null ? overrideProperties.getMaxConnections() : raProperties.getMaxConnections();
+ if (val2 != null)
{
cf.setMaxConnections(val2);
}
- val2 = overrideProperties.getMinLargeMessageSize() != null?overrideProperties.getMinLargeMessageSize():raProperties.getMinLargeMessageSize();
- if(val2 != null)
+ val2 = overrideProperties.getMinLargeMessageSize() != null ? overrideProperties.getMinLargeMessageSize() : raProperties.getMinLargeMessageSize();
+ if (val2 != null)
{
cf.setMinLargeMessageSize(val2);
}
- val2 = overrideProperties.getProducerMaxRate() != null?overrideProperties.getProducerMaxRate():raProperties.getProducerMaxRate();
- if(val2 != null)
+ val2 = overrideProperties.getProducerMaxRate() != null ? overrideProperties.getProducerMaxRate() : raProperties.getProducerMaxRate();
+ if (val2 != null)
{
cf.setProducerMaxRate(val2);
}
- val2 = overrideProperties.getProducerWindowSize() != null?overrideProperties.getProducerWindowSize():raProperties.getProducerWindowSize();
- if(val2 != null)
+ val2 = overrideProperties.getProducerWindowSize() != null ? overrideProperties.getProducerWindowSize() : raProperties.getProducerWindowSize();
+ if (val2 != null)
{
cf.setProducerWindowSize(val2);
}
- val2 = overrideProperties.getReconnectAttempts() != null?overrideProperties.getReconnectAttempts():raProperties.getReconnectAttempts();
- if(val2 != null)
+ val2 = overrideProperties.getReconnectAttempts() != null ? overrideProperties.getReconnectAttempts() : raProperties.getReconnectAttempts();
+ if (val2 != null)
{
cf.setReconnectAttempts(val2);
}
- val2 = overrideProperties.getThreadPoolMaxSize() != null?overrideProperties.getThreadPoolMaxSize():raProperties.getThreadPoolMaxSize();
- if(val2 != null)
+ val2 = overrideProperties.getThreadPoolMaxSize() != null ? overrideProperties.getThreadPoolMaxSize() : raProperties.getThreadPoolMaxSize();
+ if (val2 != null)
{
cf.setThreadPoolMaxSize(val2);
}
- val2 = overrideProperties.getScheduledThreadPoolMaxSize() != null?overrideProperties.getScheduledThreadPoolMaxSize():raProperties.getScheduledThreadPoolMaxSize();
- if(val2 != null)
+ val2 = overrideProperties.getScheduledThreadPoolMaxSize() != null ? overrideProperties.getScheduledThreadPoolMaxSize() : raProperties.getScheduledThreadPoolMaxSize();
+ if (val2 != null)
{
cf.setScheduledThreadPoolMaxSize(val2);
}
- val2 = overrideProperties.getTransactionBatchSize() != null?overrideProperties.getTransactionBatchSize():raProperties.getTransactionBatchSize();
- if(val2 != null)
+ val2 = overrideProperties.getTransactionBatchSize() != null ? overrideProperties.getTransactionBatchSize() : raProperties.getTransactionBatchSize();
+ if (val2 != null)
{
cf.setTransactionBatchSize(val2);
}
- Long val3 = overrideProperties.getClientFailureCheckPeriod() != null?overrideProperties.getClientFailureCheckPeriod():raProperties.getClientFailureCheckPeriod();
- if(val3 != null)
+ Long val3 = overrideProperties.getClientFailureCheckPeriod() != null ? overrideProperties.getClientFailureCheckPeriod() : raProperties.getClientFailureCheckPeriod();
+ if (val3 != null)
{
cf.setClientFailureCheckPeriod(val3);
}
- val3 = overrideProperties.getCallTimeout() != null?overrideProperties.getCallTimeout():raProperties.getCallTimeout();
- if(val3 != null)
+ val3 = overrideProperties.getCallTimeout() != null ? overrideProperties.getCallTimeout() : raProperties.getCallTimeout();
+ if (val3 != null)
{
cf.setCallTimeout(val3);
}
- val3 = overrideProperties.getConnectionTTL() != null?overrideProperties.getConnectionTTL():raProperties.getConnectionTTL();
- if(val3 != null)
+ val3 = overrideProperties.getConnectionTTL() != null ? overrideProperties.getConnectionTTL() : raProperties.getConnectionTTL();
+ if (val3 != null)
{
cf.setConnectionTTL(val3);
}
- val3 = overrideProperties.getDiscoveryInitialWaitTimeout() != null?overrideProperties.getDiscoveryInitialWaitTimeout():raProperties.getDiscoveryInitialWaitTimeout();
- if(val3 != null)
+ val3 = overrideProperties.getDiscoveryInitialWaitTimeout() != null ? overrideProperties.getDiscoveryInitialWaitTimeout() : raProperties.getDiscoveryInitialWaitTimeout();
+ if (val3 != null)
{
cf.setDiscoveryInitialWaitTimeout(val3);
}
- val3 = overrideProperties.getDiscoveryRefreshTimeout() != null?overrideProperties.getDiscoveryRefreshTimeout():raProperties.getDiscoveryRefreshTimeout();
- if(val3 != null)
+ val3 = overrideProperties.getDiscoveryRefreshTimeout() != null ? overrideProperties.getDiscoveryRefreshTimeout() : raProperties.getDiscoveryRefreshTimeout();
+ if (val3 != null)
{
cf.setDiscoveryRefreshTimeout(val3);
}
- val3 = overrideProperties.getRetryInterval() != null?overrideProperties.getRetryInterval():raProperties.getRetryInterval();
- if(val3 != null)
+ val3 = overrideProperties.getRetryInterval() != null ? overrideProperties.getRetryInterval() : raProperties.getRetryInterval();
+ if (val3 != null)
{
cf.setRetryInterval(val3);
}
- Double val4 = overrideProperties.getRetryIntervalMultiplier() != null?overrideProperties.getRetryIntervalMultiplier():raProperties.getRetryIntervalMultiplier();
- if(val4 != null)
+ Double val4 = overrideProperties.getRetryIntervalMultiplier() != null ? overrideProperties.getRetryIntervalMultiplier() : raProperties.getRetryIntervalMultiplier();
+ if (val4 != null)
{
cf.setRetryIntervalMultiplier(val4);
}
- String val5 = overrideProperties.getClientID() != null?overrideProperties.getClientID():raProperties.getClientID();
- if(val5 != null)
+ String val5 = overrideProperties.getClientID() != null ? overrideProperties.getClientID() : raProperties.getClientID();
+ if (val5 != null)
{
cf.setClientID(val5);
}
- val5 = overrideProperties.getConnectionLoadBalancingPolicyClassName() != null?overrideProperties.getConnectionLoadBalancingPolicyClassName():raProperties.getConnectionLoadBalancingPolicyClassName();
- if(val5 != null)
+ val5 = overrideProperties.getConnectionLoadBalancingPolicyClassName() != null ? overrideProperties.getConnectionLoadBalancingPolicyClassName() : raProperties.getConnectionLoadBalancingPolicyClassName();
+ if (val5 != null)
{
cf.setConnectionLoadBalancingPolicyClassName(val5);
}
Modified: trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivation.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivation.java 2009-07-22 11:58:52 UTC (rev 7601)
+++ trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivation.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -362,7 +362,8 @@
ra.getPreAcknowledge(),
ra.getDupsOKBatchSize(),
ra.getTransactionBatchSize(),
- isDeliveryTransacted);
+ isDeliveryTransacted,
+ spec.isUseLocalTx());
log.debug("Using queue connection " + result);
Modified: trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivationSpec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivationSpec.java 2009-07-22 11:58:52 UTC (rev 7601)
+++ trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivationSpec.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -93,32 +93,14 @@
/** The maximum number of sessions */
private Integer maxSession;
- /** The keep alive time for sessions */
- private Long keepAlive;
-
- /** Is the session transacted */
- private Boolean sessionTransacted;
-
- /** Unspecified redelivery */
- private Boolean redeliverUnspecified;
-
/** Transaction timeout */
private Integer transactionTimeout;
- /** Is same RM override */
- private Boolean isSameRMOverrideValue;
-
private boolean useJNDI = true;
- /** Force clear on shutdown */
- private Boolean forceClearOnShutdown;
+ /* use local tx instead of XA*/
+ private Boolean localTx;
- /** Force clear internal */
- private Long forceClearOnShutdownInterval;
-
- /** Force clear attempts */
- private Integer forceClearAttempts;
-
/**
* Constructor
*/
@@ -133,22 +115,15 @@
destination = null;
destinationType = null;
messageSelector = null;
- acknowledgeMode = Session.SESSION_TRANSACTED;
+ acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
subscriptionDurability = false;
subscriptionName = null;
user = null;
password = null;
- maxMessages = Integer.valueOf(1);
- minSession = Integer.valueOf(1);
- maxSession = Integer.valueOf(15);
- keepAlive = Long.valueOf(60000);
- sessionTransacted = Boolean.TRUE;
- redeliverUnspecified = Boolean.TRUE;
- transactionTimeout = Integer.valueOf(0);
- isSameRMOverrideValue = null;
- forceClearOnShutdown = Boolean.FALSE;
- forceClearOnShutdownInterval = Long.valueOf(1000);
- forceClearAttempts = Integer.valueOf(0);
+ maxMessages = 1;
+ minSession = 1;
+ maxSession = 15;
+ transactionTimeout = 0;
}
/**
@@ -296,12 +271,8 @@
log.trace("getAcknowledgeMode()");
}
- if (sessionTransacted.booleanValue())
+ if (Session.DUPS_OK_ACKNOWLEDGE == acknowledgeMode)
{
- return "Transacted";
- }
- else if (Session.DUPS_OK_ACKNOWLEDGE == acknowledgeMode)
- {
return "Dups-ok-acknowledge";
}
else
@@ -321,18 +292,14 @@
log.trace("setAcknowledgeMode(" + value + ")");
}
- if ("DUPS_OK_ACKNOWLEDGE".equals(value) || "Dups-ok-acknowledge".equals(value))
+ if ("DUPS_OK_ACKNOWLEDGE".equalsIgnoreCase(value) || "Dups-ok-acknowledge".equalsIgnoreCase(value))
{
acknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE;
}
- else if ("AUTO_ACKNOWLEDGE".equals(value) || "Auto-acknowledge".equals(value))
+ else if ("AUTO_ACKNOWLEDGE".equalsIgnoreCase(value) || "Auto-acknowledge".equalsIgnoreCase(value))
{
acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
}
- else if ("SESSION_TRANSACTED".equals(value))
- {
- acknowledgeMode = Session.SESSION_TRANSACTED;
- }
else
{
throw new IllegalArgumentException("Unsupported acknowledgement mode " + value);
@@ -349,11 +316,6 @@
log.trace("getAcknowledgeMode()");
}
- if (sessionTransacted.booleanValue())
- {
- return Session.SESSION_TRANSACTED;
- }
-
return acknowledgeMode;
}
@@ -548,7 +510,7 @@
return 0;
}
- return maxMessages.intValue();
+ return maxMessages;
}
/**
@@ -595,7 +557,7 @@
return 0;
}
- return minSession.intValue();
+ return minSession;
}
/**
@@ -642,132 +604,10 @@
return 0;
}
- return maxSession.intValue();
+ return maxSession;
}
/**
- * Get the keep alive
- * @return The value
- */
- public Long getKeepAlive()
- {
- if (trace)
- {
- log.trace("getKeepAlive()");
- }
-
- return keepAlive;
- }
-
- /**
- * Set the keep alive
- * @param value The value
- */
- public void setKeepAlive(final Long value)
- {
- if (trace)
- {
- log.trace("setKeepAlive(" + value + ")");
- }
-
- keepAlive = value;
- }
-
- /**
- * Get the keep alive
- * @return The value
- */
- public long getKeepAliveLong()
- {
- if (trace)
- {
- log.trace("getKeepAliveLong()");
- }
-
- if (keepAlive == null)
- {
- return 0;
- }
-
- return keepAlive.longValue();
- }
-
- /**
- * Get the session transacted
- * @return The value
- */
- public Boolean getSessionTransacted()
- {
- if (trace)
- {
- log.trace("getSessionTransacted()");
- }
-
- return sessionTransacted;
- }
-
- /**
- * Set the session transacted
- * @param value The value
- */
- public void setSessionTransacted(final Boolean value)
- {
- if (trace)
- {
- log.trace("setTransactionTimeout(" + value + ")");
- }
-
- sessionTransacted = value;
- }
-
- /**
- * Get the session transaced
- * @return THe value
- */
- public boolean isSessionTransacted()
- {
- if (trace)
- {
- log.trace("isSessionTransacted()");
- }
-
- if (sessionTransacted == null)
- {
- return false;
- }
-
- return sessionTransacted.booleanValue();
- }
-
- /**
- * Get the redeliver upspecified
- * @return The value
- */
- public Boolean getRedeliverUnspecified()
- {
- if (trace)
- {
- log.trace("getRedeliverUnspecified()");
- }
-
- return redeliverUnspecified;
- }
-
- /**
- * Set the redeliver unspecified
- * @param value The value
- */
- public void setRedeliverUnspecified(final Boolean value)
- {
- if (trace)
- {
- log.trace("setRedeliverUnspecified(" + value + ")");
- }
-
- redeliverUnspecified = value;
- }
-
- /**
* Get the transaction timeout
* @return The value
*/
@@ -795,138 +635,24 @@
transactionTimeout = value;
}
- /**
- * Get the is same rm override
- * @return The value
- */
- public Boolean getIsSameRMOverrideValue()
+ public Boolean isUseLocalTx()
{
- if (trace)
+ if(localTx == null)
{
- log.trace("getIsSameRMOverrideValue()");
+ return ra.getUseLocalTx();
}
-
- return isSameRMOverrideValue;
- }
-
- /**
- * Set the is same RM override
- * @param value The value
- */
- public void setIsSameRMOverrideValue(final Boolean value)
- {
- if (trace)
+ else
{
- log.trace("setIsSameRMOverrideValue(" + value + ")");
+ return localTx;
}
-
- isSameRMOverrideValue = value;
}
- /**
- * Get force clear on shutdown
- * @return The value
- */
- public Boolean getForceClearOnShutdown()
+ public void setUseLocalTx(Boolean localTx)
{
- if (trace)
- {
- log.trace("getForceClearOnShutdown()");
- }
-
- return forceClearOnShutdown;
+ this.localTx = localTx;
}
/**
- * Set the force clear on shutdown
- * @param value The value
- */
- public void setForceClearOnShutdown(final Boolean value)
- {
- if (trace)
- {
- log.trace("setForceClearOnShutdown(" + value + ")");
- }
-
- forceClearOnShutdown = value;
- }
-
- /**
- * Get force clear on shutdown
- * @return The value
- */
- public boolean isForceClearOnShutdown()
- {
- if (trace)
- {
- log.trace("isForceClearOnShutdown()");
- }
-
- if (forceClearOnShutdown == null)
- {
- return false;
- }
-
- return forceClearOnShutdown.booleanValue();
- }
-
- /**
- * Get force clear on shutdown interval
- * @return The value
- */
- public Long getForceClearOnShutdownInterval()
- {
- if (trace)
- {
- log.trace("getForceClearOnShutdownInterval()");
- }
-
- return forceClearOnShutdownInterval;
- }
-
- /**
- * Set the force clear on shutdown interval
- * @param value The value
- */
- public void setForceClearOnShutdownInterval(final Long value)
- {
- if (trace)
- {
- log.trace("setForceClearOnShutdownInterval(" + value + ")");
- }
-
- forceClearOnShutdownInterval = value;
- }
-
- /**
- * Get force clear attempts
- * @return The value
- */
- public Integer getForceClearAttempts()
- {
- if (trace)
- {
- log.trace("getForceClearAttempts()");
- }
-
- return forceClearAttempts;
- }
-
- /**
- * Set the force clear attempts
- * @param value The value
- */
- public void setForceClearAttempts(final Integer value)
- {
- if (trace)
- {
- log.trace("setForceClearAttempts(" + value + ")");
- }
-
- forceClearAttempts = value;
- }
-
- /**
* Validate
* @exception InvalidPropertyException Thrown if a validation exception occurs
*/
@@ -977,11 +703,7 @@
{
buffer.append(" selector=").append(messageSelector);
}
- buffer.append(" tx=").append(sessionTransacted);
- if (sessionTransacted == false)
- {
- buffer.append(" ack=").append(getAcknowledgeMode());
- }
+ buffer.append(" ack=").append(getAcknowledgeMode());
buffer.append(" durable=").append(subscriptionDurability);
if (subscriptionName != null)
{
@@ -995,7 +717,6 @@
buffer.append(" maxMessages=").append(maxMessages);
buffer.append(" minSession=").append(minSession);
buffer.append(" maxSession=").append(maxSession);
- buffer.append(" keepAlive=").append(keepAlive);
buffer.append(')');
return buffer.toString();
}
Modified: trunk/src/main/org/jboss/messaging/ra/inflow/JBMMessageHandler.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/inflow/JBMMessageHandler.java 2009-07-22 11:58:52 UTC (rev 7601)
+++ trunk/src/main/org/jboss/messaging/ra/inflow/JBMMessageHandler.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -33,13 +33,11 @@
import org.jboss.messaging.utils.SimpleString;
import javax.jms.InvalidClientIDException;
-import javax.jms.JMSException;
import javax.jms.MessageListener;
-import javax.jms.Session;
+import javax.resource.ResourceException;
import javax.resource.spi.endpoint.MessageEndpoint;
import javax.resource.spi.endpoint.MessageEndpointFactory;
-import javax.transaction.Status;
-import javax.transaction.Transaction;
+import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
import java.util.UUID;
@@ -167,9 +165,9 @@
consumer = session.createConsumer(queueName, selectorString);
}
- // Create the endpoint
+ // Create the endpoint, if we are transacted pass the sesion so it is enlisted, unless using Local TX
MessageEndpointFactory endpointFactory = activation.getMessageEndpointFactory();
- if (activation.isDeliveryTransacted())
+ if (activation.isDeliveryTransacted() && !activation.getActivationSpec().isUseLocalTx())
{
endpoint = endpointFactory.createEndpoint(session);
}
@@ -230,7 +228,7 @@
catch (Throwable throwable)
{
log.warn("Unable to create transaction: " + throwable.getMessage());
- txnStrategy = null;
+ txnStrategy = new NoTXTransactionDemarcationStrategy();
}
JBossMessage jbm = JBossMessage.createMessage(message, session);
@@ -238,6 +236,7 @@
try
{
jbm.doBeforeReceive();
+ message.acknowledge();
}
catch (Exception e)
{
@@ -246,48 +245,19 @@
return;
}
- if (activation.getActivationSpec().getAcknowledgeModeInt() == Session.SESSION_TRANSACTED || activation.getActivationSpec()
- .getAcknowledgeModeInt() == Session.CLIENT_ACKNOWLEDGE)
- {
- try
- {
- message.acknowledge();
- }
- catch (MessagingException e)
- {
- log.error("Failed to process message", e);
- }
- }
try
{
- endpoint.beforeDelivery(JBMActivation.ONMESSAGE);
- try
- {
- MessageListener listener = (MessageListener)endpoint;
- listener.onMessage(jbm);
- }
- finally
- {
- endpoint.afterDelivery();
- }
+ ((MessageListener)endpoint).onMessage(jbm);
}
catch (Throwable t)
{
log.error("Unexpected error delivering message " + message, t);
-
- if (txnStrategy != null)
- {
- txnStrategy.error();
- }
+ txnStrategy.error();
}
finally
{
- if (txnStrategy != null)
- {
- txnStrategy.end();
- }
+ txnStrategy.end();
}
-
}
/**
@@ -309,18 +279,33 @@
if (activation.isDeliveryTransacted())
{
- try
+ if (!activation.getActivationSpec().isUseLocalTx())
{
- return new XATransactionDemarcationStrategy();
+ try
+ {
+ return new XATransactionDemarcationStrategy();
+ }
+ catch (Throwable t)
+ {
+ log.error(this + " error creating transaction demarcation ", t);
+ }
}
- catch (Throwable t)
+ else
{
- log.error(this + " error creating transaction demarcation ", t);
+ return new LocalDemarcationStrategy();
}
+
}
else
{
- return new LocalDemarcationStrategy();
+ if (!activation.getActivationSpec().isUseLocalTx())
+ {
+ return new NoTXTransactionDemarcationStrategy();
+ }
+ else
+ {
+ return new LocalDemarcationStrategy();
+ }
}
return null;
@@ -353,6 +338,7 @@
*/
private class LocalDemarcationStrategy implements TransactionDemarcationStrategy
{
+ private boolean rolledBack = false;
/*
* Start
*/
@@ -371,34 +357,17 @@
log.trace("error()");
}
- final JBMActivationSpec spec = activation.getActivationSpec();
-
- if (spec.isSessionTransacted())
+ if (session != null)
{
- if (session != null)
+ try
{
- try
- {
- /*
- * Looks strange, but this basically means
- *
- * If the underlying connection was non-XA and the transaction
- * attribute is REQUIRED we rollback. Also, if the underlying
- * connection was non-XA and the transaction attribute is
- * NOT_SUPPORT and the non standard redelivery behavior is
- * enabled we rollback to force redelivery.
- *
- */
- if (activation.isDeliveryTransacted() || spec.getRedeliverUnspecified())
- {
- session.rollback();
- }
- }
- catch (MessagingException e)
- {
- log.error("Failed to rollback session transaction", e);
- }
+ session.rollback();
+ rolledBack = true;
}
+ catch (MessagingException e)
+ {
+ log.error("Failed to rollback session transaction", e);
+ }
}
}
@@ -409,12 +378,10 @@
{
if (trace)
{
- log.trace("error()");
+ log.trace("end()");
}
- final JBMActivationSpec spec = activation.getActivationSpec();
-
- if (spec.isSessionTransacted())
+ if (!rolledBack)
{
if (session != null)
{
@@ -436,8 +403,6 @@
*/
private class XATransactionDemarcationStrategy implements TransactionDemarcationStrategy
{
- private Transaction trans = null;
-
private final TransactionManager tm = activation.getTransactionManager();
public void start() throws Throwable
@@ -453,106 +418,54 @@
tm.setTransactionTimeout(timeout);
}
+ endpoint.beforeDelivery(JBMActivation.ONMESSAGE);
+ }
- tm.begin();
-
+ public void error()
+ {
try
{
- trans = tm.getTransaction();
-
- if (trace)
+ try
{
- log.trace(this + " using tx=" + trans);
+ tm.getTransaction().setRollbackOnly();
}
-
- if (!trans.enlistResource(session))
+ catch (SystemException e)
{
- throw new JMSException("could not enlist resource");
+ log.error("Unable to mark transaction as rollback only", e);
}
- if (trace)
- {
- log.trace(this + " XAResource '" + session + " enlisted.");
- }
-
+ endpoint.afterDelivery();
}
- catch (Throwable t)
+ catch (ResourceException e)
{
- try
- {
- tm.rollback();
- }
- catch (Throwable ignored)
- {
- log.trace(this + " ignored error rolling back after failed enlist", ignored);
- }
- throw t;
+ log.error("Error calling after delivery on endpoint", e);
}
}
- public void error()
+ public void end()
{
- // Mark for tollback TX via TM
try
{
- if (trace)
- {
- log.trace(this + " using TM to mark TX for rollback tx=" + trans);
- }
-
- trans.setRollbackOnly();
+ endpoint.afterDelivery();
}
- catch (Throwable t)
+ catch (ResourceException e)
{
- log.error(this + " failed to set rollback only", t);
+ log.error("Error calling after delivery on endpoint", e);
}
}
+ }
- public void end()
+ private class NoTXTransactionDemarcationStrategy implements TransactionDemarcationStrategy
+ {
+ public void start() throws Throwable
{
- try
- {
- // Use the TM to commit the Tx (assert the correct association)
- Transaction currentTx = tm.getTransaction();
- if (trans.equals(currentTx) == false)
- {
- throw new IllegalStateException("Wrong tx association: expected " + trans + " was " + currentTx);
- }
+ }
- // Marked rollback
- if (trans.getStatus() == Status.STATUS_MARKED_ROLLBACK)
- {
- if (trace)
- {
- log.trace(this + " rolling back JMS transaction tx=" + trans);
- }
+ public void error()
+ {
+ }
- // Actually roll it back
- tm.rollback();
-
- }
- else if (trans.getStatus() == Status.STATUS_ACTIVE)
- {
- // Commit tx
- // This will happen if
- // a) everything goes well
- // b) app. exception was thrown
- if (trace)
- {
- log.trace(this + " commiting the JMS transaction tx=" + trans);
- }
-
- tm.commit();
-
- }
- else
- {
- tm.suspend();
- }
- }
- catch (Throwable t)
- {
- log.error(this + " failed to commit/rollback", t);
- }
+ public void end()
+ {
}
}
}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/ra/ResourceAdapterTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/ra/ResourceAdapterTest.java 2009-07-22 11:58:52 UTC (rev 7601)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/ra/ResourceAdapterTest.java 2009-07-22 13:46:38 UTC (rev 7602)
@@ -326,13 +326,8 @@
JBMActivationSpec spec = new JBMActivationSpec();
spec.setAcknowledgeMode("DUPS_OK_ACKNOWLEDGE");
- spec.setSessionTransacted(false);
assertEquals("Dups-ok-acknowledge", spec.getAcknowledgeMode());
- spec.setSessionTransacted(true);
-
- assertEquals("Transacted", spec.getAcknowledgeMode());
-
spec.setSubscriptionDurability("Durable");
assertEquals("Durable", spec.getSubscriptionDurability());
@@ -382,7 +377,6 @@
JBMResourceAdapter ra = new JBMResourceAdapter();
ra.setConnectorClassName("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory");
ra.setConnectionParameters("bm.remoting.invm.serverid=0");
- ra.setUseXA(true);
ra.setUserName("userGlobal");
ra.setPassword("passwordGlobal");
ra.start(fakeCTX);
More information about the jboss-cvs-commits
mailing list