[jboss-cvs] JBoss Messaging SVN: r3317 - in branches/Branch_Stable: docs/examples and 10 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Nov 13 10:23:34 EST 2007


Author: timfox
Date: 2007-11-13 10:23:33 -0500 (Tue, 13 Nov 2007)
New Revision: 3317

Added:
   branches/Branch_Stable/docs/examples/singleton/
   branches/Branch_Stable/docs/examples/singleton/build.xml
   branches/Branch_Stable/docs/examples/singleton/etc/
   branches/Branch_Stable/docs/examples/singleton/etc/META-INF/
   branches/Branch_Stable/docs/examples/singleton/etc/META-INF/ejb-jar.xml
   branches/Branch_Stable/docs/examples/singleton/etc/META-INF/jboss.xml
   branches/Branch_Stable/docs/examples/singleton/etc/destinations-noredist-service.xml
   branches/Branch_Stable/docs/examples/singleton/etc/jndi.properties
   branches/Branch_Stable/docs/examples/singleton/etc/log4j.xml
   branches/Branch_Stable/docs/examples/singleton/etc/singleton-connectionfactory-service.xml
   branches/Branch_Stable/docs/examples/singleton/src/
   branches/Branch_Stable/docs/examples/singleton/src/org/
   branches/Branch_Stable/docs/examples/singleton/src/org/jboss/
   branches/Branch_Stable/docs/examples/singleton/src/org/jboss/example/
   branches/Branch_Stable/docs/examples/singleton/src/org/jboss/example/jms/
   branches/Branch_Stable/docs/examples/singleton/src/org/jboss/example/jms/singleton/
   branches/Branch_Stable/docs/examples/singleton/src/org/jboss/example/jms/singleton/Sender.java
   branches/Branch_Stable/docs/examples/singleton/src/org/jboss/example/jms/singleton/SingletonExample.java
Modified:
   branches/Branch_Stable/.classpath
   branches/Branch_Stable/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-1149


Modified: branches/Branch_Stable/.classpath
===================================================================
--- branches/Branch_Stable/.classpath	2007-11-13 14:09:41 UTC (rev 3316)
+++ branches/Branch_Stable/.classpath	2007-11-13 15:23:33 UTC (rev 3317)
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry kind="src" path="docs/examples/queue-failover/src"/>
+	<classpathentry kind="src" path="docs/examples/singleton/src"/>
 	<classpathentry kind="src" path="docs/examples/bridge/src"/>
 	<classpathentry kind="src" path="docs/examples/stateless-clustered/src"/>
 	<classpathentry kind="src" path="docs/examples/web-service/src-client"/>

Added: branches/Branch_Stable/docs/examples/singleton/build.xml
===================================================================
--- branches/Branch_Stable/docs/examples/singleton/build.xml	                        (rev 0)
+++ branches/Branch_Stable/docs/examples/singleton/build.xml	2007-11-13 15:23:33 UTC (rev 3317)
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+
+   To run the example, set JBOSS_HOME and run ant (with no parameters)
+
+   $Id: build.xml 3140 2007-09-26 08:44:19Z ataylor $
+
+ -->
+
+<project name="SingletonExample" default="run">
+
+   <property environment="ENV"/>
+
+   <!-- These properties may be overriden by calling ants when this example is used in a smoke test -->
+   <property file="../examples.properties"/>
+   <property name="messaging.client.jar.path" value="../../"/>
+   <property name="messaging.client.jar.name" value="jboss-messaging-client.jar"/>
+   <property name="jboss.home" value="${ENV.JBOSS_HOME}"/>
+   <property name="jboss.configuration" value="messaging-node0"/>
+   <property name="example.queue.name" value="testNoRedistQueue"/>
+
+   <path id="common.compilation.classpath">
+      <fileset file="${jboss.home}/client/jboss-j2ee.jar"/>
+      <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>  
+      <fileset file="${jboss.home}/client/jboss-ejb3x.jar"/>    
+   </path>
+
+   <path id="example.compilation.classpath">
+      <path refid="common.compilation.classpath"/>
+      <pathelement path="../common/output/classes"/>
+      <fileset file="${jboss.home}/client/jboss-ejb3x.jar"/>
+   </path>
+
+   <path id="execution.classpath">
+      <pathelement path="./etc"/>
+      <pathelement path="../common/output/classes"/>
+      <pathelement path="./output/classes"/>
+      <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/jboss-remoting.jar"/>
+      <fileset file="${jboss.home}/client/jbossall-client.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/log4j.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/javassist.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/deploy/jboss-aop-jdk50.deployer/jboss-aop-jdk50.jar"/>
+      <fileset file="${jboss.home}/server/${jboss.configuration}/deploy/jboss-aop-jdk50.deployer/trove.jar"/>
+   </path>
+
+   <target name="identify">
+      <echo message="###########################################################################"/>
+      <echo message="#         Running the SINGLETON example            #"/>
+      <echo message="###########################################################################"/>
+      <echo message="The queue:      ${example.queue.name}"/>
+      <echo message="The client jar: ${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+   </target>
+
+   <target name="sanity-check" depends="identify">
+      <available property="client.jar.present" file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+      <fail message="Could not find client jar ${messaging.client.jar.path}/${messaging.client.jar.name}"
+            unless="client.jar.present"/>
+   </target>
+
+   <target name="init" depends="sanity-check">
+      <mkdir dir="./output/classes/META-INF"/>
+      <mkdir dir="./output/lib"/>
+      <mkdir dir="../common/output/classes"/>
+   </target>
+
+   <target name="compile" depends="init">
+      <javac destdir="../common/output/classes" debug="on" debuglevel="lines,vars,source">
+         <src path="../common/src"/>
+         <classpath refid="common.compilation.classpath"/>
+      </javac>
+      <javac destdir="./output/classes" debug="on" debuglevel="lines,vars,source">
+         <src path="./src"/>
+         <classpath refid="example.compilation.classpath"/>
+      </javac>
+   </target>
+
+   <target name="jar" depends="compile">
+      <copy todir="./output/classes/META-INF">
+         <fileset dir="./etc/META-INF" includes="*"/>
+      </copy>
+      <jar destfile="./output/lib/singleton-example.jar"
+           basedir="./output/classes"
+           includes="META-INF/**,org/jboss/example/jms/singleton/*.class"/>
+   </target>
+
+   <target name="deploy" depends="jar">
+      <copy file="./etc/destinations-noredist-service.xml"
+            todir="${jboss.home}/server/${jboss.configuration}/farm"/>
+      <copy file="./etc/singleton-connectionfactory-service.xml"
+            todir="${jboss.home}/server/${jboss.configuration}/farm"/>
+      <copy file="./output/lib/singleton-example.jar"
+            todir="${jboss.home}/server/${jboss.configuration}/farm"/>
+      <antcall target="sleep"><param name="sleep.interval" value="15"/></antcall>
+   </target>
+
+   <target name="run" depends="deploy">
+      <antcall target="send-and-receive"/>
+      <antcall target="undeploy"/>
+   </target>
+
+   <target name="send-and-receive">
+      <!-- The client expects to find the name of the queue to connect to as value of the
+           'example.queue.name' property, which *may* be defined by calling ants when this example
+            is used in a smoke test -->
+      <java classname="org.jboss.example.jms.singleton.Sender"
+            classpathref="execution.classpath" fork="yes" failonerror="true">
+         <sysproperty key="example.queue.name" value="${example.queue.name}"/>
+         <!--
+         <jvmarg line="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=y,suspend=y,address=example"/>
+          -->
+      </java>
+   </target>
+
+   <target name="undeploy">
+      <delete file="${jboss.home}/server/${jboss.configuration}/farm/singleton-example.jar"
+              quiet="true"/>
+      <delete file="${jboss.home}/server/${jboss.configuration}/farm/singleton-connectionfactory-service.xml"
+              quiet="true"/>
+      <delete file="${jboss.home}/server/${jboss.configuration}/farm/destinations-noredist-service.xml"
+              quiet="true"/>
+   </target>
+
+   <target name="clean" depends="undeploy">
+      <delete dir="./output" quiet="true"/>
+      <delete dir="../common/output" quiet="true"/>
+   </target>
+
+   <target name="sleep">
+      <echo message="Sleeping for ${sleep.interval} seconds ..."/>
+      <sleep seconds="${sleep.interval}"/>
+   </target>
+
+</project>
+

Added: branches/Branch_Stable/docs/examples/singleton/etc/META-INF/ejb-jar.xml
===================================================================
--- branches/Branch_Stable/docs/examples/singleton/etc/META-INF/ejb-jar.xml	                        (rev 0)
+++ branches/Branch_Stable/docs/examples/singleton/etc/META-INF/ejb-jar.xml	2007-11-13 15:23:33 UTC (rev 3317)
@@ -0,0 +1,25 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
+    "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
+
+<!-- $Id: ejb-jar.xml 892 2006-04-18 23:48:09Z ovidiu $ -->
+
+<!--
+    Note: This deployment descriptor (or any deployment descriptor) is NOT mandatory with EJB3 beans.
+          It is here to:
+          1. Demonstrate the use of deployment descriptors, in case you need to override
+             configuration at deployment.
+          2. Add a degree of flexibility to this example to be used with smoke tests.
+-->
+<ejb-jar>
+    <enterprise-beans>
+        <message-driven>
+            <ejb-name>SingletonExample</ejb-name>
+            <ejb-class>org.jboss.example.jms.singleton.SingletonExample</ejb-class>
+            <transaction-type>Container</transaction-type>
+            <message-driven-destination>
+               <destination-type>javax.jms.Queue</destination-type>
+            </message-driven-destination>
+        </message-driven>
+    </enterprise-beans>
+</ejb-jar>

Added: branches/Branch_Stable/docs/examples/singleton/etc/META-INF/jboss.xml
===================================================================
--- branches/Branch_Stable/docs/examples/singleton/etc/META-INF/jboss.xml	                        (rev 0)
+++ branches/Branch_Stable/docs/examples/singleton/etc/META-INF/jboss.xml	2007-11-13 15:23:33 UTC (rev 3317)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jboss PUBLIC
+   "-//JBoss//DTD JBOSS 3.0//EN"
+   "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd">
+
+<!-- $Id: jboss.xml 892 2006-04-18 23:48:09Z ovidiu $ -->
+
+<!--
+    Note: This deployment descriptor (or any deployment descriptor) is NOT mandatory with EJB3 beans.
+          It is here to:
+          1. Demonstrate the use of deployment descriptors, in case you need to override
+             configuration at deployment.
+          2. Add a degree of flexibility to this example to be used with smoke tests.
+-->
+<jboss>
+
+   <enterprise-beans>
+      <message-driven>
+         <ejb-name>SingletonExample</ejb-name>
+         <destination-jndi-name>queue/testNoRedistQueue</destination-jndi-name>
+      </message-driven>
+   </enterprise-beans>
+
+</jboss>
+

Added: branches/Branch_Stable/docs/examples/singleton/etc/destinations-noredist-service.xml
===================================================================
--- branches/Branch_Stable/docs/examples/singleton/etc/destinations-noredist-service.xml	                        (rev 0)
+++ branches/Branch_Stable/docs/examples/singleton/etc/destinations-noredist-service.xml	2007-11-13 15:23:33 UTC (rev 3317)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+   <mbean code="org.jboss.jms.server.destination.QueueService"
+      name="jboss.messaging.destination:service=Queue,name=testNoRedistQueue"
+      xmbean-dd="xmdesc/Queue-xmbean.xml">
+      <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+      <depends>jboss.messaging:service=PostOffice</depends>
+      <attribute name="Clustered">true</attribute>
+      <attribute name="DisableRedistribution">true</attribute>
+   </mbean>
+</server>

Added: branches/Branch_Stable/docs/examples/singleton/etc/jndi.properties
===================================================================
--- branches/Branch_Stable/docs/examples/singleton/etc/jndi.properties	                        (rev 0)
+++ branches/Branch_Stable/docs/examples/singleton/etc/jndi.properties	2007-11-13 15:23:33 UTC (rev 3317)
@@ -0,0 +1,4 @@
+### JBossNS properties - HA-JNDI
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=localhost:1200
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Added: branches/Branch_Stable/docs/examples/singleton/etc/log4j.xml
===================================================================
--- branches/Branch_Stable/docs/examples/singleton/etc/log4j.xml	                        (rev 0)
+++ branches/Branch_Stable/docs/examples/singleton/etc/log4j.xml	2007-11-13 15:23:33 UTC (rev 3317)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- $Id: log4j.xml 2742 2007-05-30 17:07:08Z sergeypk $ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+      <param name="Target" value="System.out"/>
+      <param name="Threshold" value="INFO"/>
+      <layout class="org.apache.log4j.PatternLayout">
+         <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p @%t [%c{1}] %m%n"/>
+      </layout>
+   </appender>
+
+   <root>
+      <appender-ref ref="CONSOLE"/>
+   </root>
+
+</log4j:configuration>

Added: branches/Branch_Stable/docs/examples/singleton/etc/singleton-connectionfactory-service.xml
===================================================================
--- branches/Branch_Stable/docs/examples/singleton/etc/singleton-connectionfactory-service.xml	                        (rev 0)
+++ branches/Branch_Stable/docs/examples/singleton/etc/singleton-connectionfactory-service.xml	2007-11-13 15:23:33 UTC (rev 3317)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<server>
+
+   <mbean code="org.jboss.jms.server.connectionfactory.ConnectionFactory"
+      name="jboss.messaging.destination:service=TestSingletonConnectionFactory"
+      xmbean-dd="xmdesc/ConnectionFactory-xmbean.xml">
+      <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
+      <depends optional-attribute-name="Connector">jboss.messaging:service=Connector,transport=bisocket</depends>
+      <attribute name="JNDIBindings">
+         <bindings>
+            <binding>/TestSingletonConnectionFactory</binding>
+         </bindings>
+      </attribute>
+      <attribute name="SupportsLoadBalancing">false</attribute>
+      <attribute name="Singleton">true</attribute>
+   </mbean>
+
+</server>

Added: branches/Branch_Stable/docs/examples/singleton/src/org/jboss/example/jms/singleton/Sender.java
===================================================================
--- branches/Branch_Stable/docs/examples/singleton/src/org/jboss/example/jms/singleton/Sender.java	                        (rev 0)
+++ branches/Branch_Stable/docs/examples/singleton/src/org/jboss/example/jms/singleton/Sender.java	2007-11-13 15:23:33 UTC (rev 3317)
@@ -0,0 +1,95 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.example.jms.singleton;
+
+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;
+
+import org.jboss.example.jms.common.ExampleSupport;
+
+/**
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: $</tt>
+ *
+ * $Id:  $
+ */
+public class Sender extends ExampleSupport
+{
+   public void example() throws Exception
+   {
+      String destinationName = getDestinationJNDIName();
+
+      InitialContext ic = new InitialContext();
+
+      ConnectionFactory cf = (ConnectionFactory)ic.lookup("/TestSingletonConnectionFactory");
+      
+      Queue queue = (Queue)ic.lookup(destinationName);
+
+      log("Queue " + destinationName + " exists");
+
+      Connection connection = null;
+      
+      try
+      {      
+         connection  = cf.createConnection();
+         
+         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         
+         MessageProducer sender = session.createProducer(queue);
+         
+         for (int i = 0; i < 100; i++)
+         {   
+            TextMessage message = session.createTextMessage("Hello " + i);
+            
+            sender.send(message);
+      
+            log("The " + message.getText() + " message was successfully sent to the " + queue.getQueueName() + " queue");
+         }
+   
+         connection.close();
+      }
+      finally
+      {
+         if (connection != null)
+         {
+            connection.close();
+         }
+      }
+   }
+
+   protected boolean isQueueExample()
+   {
+      return true;
+   }
+
+   public static void main(String[] args)
+   {
+      new Sender().run();
+   }
+
+}

Added: branches/Branch_Stable/docs/examples/singleton/src/org/jboss/example/jms/singleton/SingletonExample.java
===================================================================
--- branches/Branch_Stable/docs/examples/singleton/src/org/jboss/example/jms/singleton/SingletonExample.java	                        (rev 0)
+++ branches/Branch_Stable/docs/examples/singleton/src/org/jboss/example/jms/singleton/SingletonExample.java	2007-11-13 15:23:33 UTC (rev 3317)
@@ -0,0 +1,54 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.example.jms.singleton;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+import javax.ejb.*;
+
+/**
+ * A MDB3 EJB example.
+ *
+ * @author <a href="mailto:tim.fox at jboss.com>Tim Fox</a>
+ * @version <tt>$Revision: $</tt>
+
+ * $Id: x $
+ */
+ at MessageDriven(activationConfig =
+{
+      @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
+      @ActivationConfigProperty(propertyName="destination", propertyValue="queue/testNoRedistQueue"),
+      @ActivationConfigProperty(propertyName="DLQMaxResent", propertyValue="10")
+})
+public class SingletonExample implements MessageListener
+{
+   public void onMessage(Message m)
+   {
+      businessLogic(m);
+   }
+
+   private void businessLogic(Message m)
+   {
+      try
+      {
+         TextMessage tm = (TextMessage)m;
+
+         String text = tm.getText();
+         
+         System.out.println("message " + text + " received");
+      }
+      catch(JMSException e)
+      {
+         e.printStackTrace();
+      }      
+   }
+}
+
+
+

Modified: branches/Branch_Stable/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java
===================================================================
--- branches/Branch_Stable/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java	2007-11-13 14:09:41 UTC (rev 3316)
+++ branches/Branch_Stable/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactoryJNDIMapper.java	2007-11-13 15:23:33 UTC (rev 3317)
@@ -253,16 +253,21 @@
          throw new IllegalArgumentException("Cannot find endpoint with name " + uniqueName);
       }
 
-      JNDIBindings jndiBindings = endpoint.getJNDIBindings();
-
-      if (jndiBindings != null)
-      {
-         List jndiNames = jndiBindings.getNames();
-         for(Iterator i = jndiNames.iterator(); i.hasNext(); )
+      boolean singleton = endpoint.isSingleton();
+      
+      if (!singleton || (singleton && serverPeer.getPostOfficeInstance().isMaster()))
+      {         
+         JNDIBindings jndiBindings = endpoint.getJNDIBindings();
+   
+         if (jndiBindings != null)
          {
-            String jndiName = (String)i.next();
-            initialContext.unbind(jndiName);
-            log.debug(jndiName + " unregistered");
+            List jndiNames = jndiBindings.getNames();
+            for(Iterator i = jndiNames.iterator(); i.hasNext(); )
+            {
+               String jndiName = (String)i.next();
+               initialContext.unbind(jndiName);
+               log.debug(jndiName + " unregistered");
+            }
          }
       }
 




More information about the jboss-cvs-commits mailing list