[jboss-cvs] JBoss Messaging SVN: r1831 - in trunk: . docs/examples docs/examples/common docs/examples/common/etc docs/examples/common/etc/META-INF docs/examples/common/src/org/jboss/example/jms/common docs/examples/common/src/org/jboss/example/jms/common/bean docs/examples/distributed-topic docs/examples/distributed-topic/src/org/jboss/example/jms/distributedtopic docs/examples/queue-failover docs/examples/queue-failover/etc docs/examples/queue-failover/src docs/examples/queue-failover/src/org docs/examples/queue-failover/src/org/jboss docs/examples/queue-failover/src/org/jboss/example docs/examples/queue-failover/src/org/jboss/example/jms docs/examples/queue-failover/src/org/jboss/example/jms/failover
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Dec 20 04:35:20 EST 2006
Author: ovidiu.feodorov at jboss.com
Date: 2006-12-20 04:35:13 -0500 (Wed, 20 Dec 2006)
New Revision: 1831
Added:
trunk/docs/examples/common/etc/
trunk/docs/examples/common/etc/META-INF/
trunk/docs/examples/common/etc/META-INF/ejb-jar.xml
trunk/docs/examples/common/etc/META-INF/jboss.xml
trunk/docs/examples/common/src/org/jboss/example/jms/common/bean/
trunk/docs/examples/common/src/org/jboss/example/jms/common/bean/Management.java
trunk/docs/examples/common/src/org/jboss/example/jms/common/bean/ManagementBean.java
trunk/docs/examples/common/src/org/jboss/example/jms/common/bean/ManagementHome.java
trunk/docs/examples/queue-failover/
trunk/docs/examples/queue-failover/README.html
trunk/docs/examples/queue-failover/build.xml
trunk/docs/examples/queue-failover/do-not-distribute.properties
trunk/docs/examples/queue-failover/etc/
trunk/docs/examples/queue-failover/etc/jndi.properties
trunk/docs/examples/queue-failover/etc/log4j.xml
trunk/docs/examples/queue-failover/src/
trunk/docs/examples/queue-failover/src/org/
trunk/docs/examples/queue-failover/src/org/jboss/
trunk/docs/examples/queue-failover/src/org/jboss/example/
trunk/docs/examples/queue-failover/src/org/jboss/example/jms/
trunk/docs/examples/queue-failover/src/org/jboss/example/jms/failover/
trunk/docs/examples/queue-failover/src/org/jboss/example/jms/failover/QueueFailoverExample.java
Modified:
trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java
trunk/docs/examples/distributed-topic/build.xml
trunk/docs/examples/distributed-topic/do-not-distribute.properties
trunk/docs/examples/distributed-topic/src/org/jboss/example/jms/distributedtopic/DistributedTopicExample.java
trunk/messaging.iml
Log:
the first cut of distributed topic and queue failover examples
Added: trunk/docs/examples/common/etc/META-INF/ejb-jar.xml
===================================================================
--- trunk/docs/examples/common/etc/META-INF/ejb-jar.xml 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/docs/examples/common/etc/META-INF/ejb-jar.xml 2006-12-20 09:35:13 UTC (rev 1831)
@@ -0,0 +1,16 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
+ "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
+
+<ejb-jar>
+ <enterprise-beans>
+ <session>
+ <ejb-name>Management</ejb-name>
+ <home>org.jboss.example.jms.common.bean.ManagementHome</home>
+ <remote>org.jboss.example.jms.common.bean.Management</remote>
+ <ejb-class>org.jboss.example.jms.common.bean.ManagementBean</ejb-class>
+ <session-type>Stateless</session-type>
+ <transaction-type>Bean</transaction-type>
+ </session>
+ </enterprise-beans>
+</ejb-jar>
\ No newline at end of file
Added: trunk/docs/examples/common/etc/META-INF/jboss.xml
===================================================================
--- trunk/docs/examples/common/etc/META-INF/jboss.xml 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/docs/examples/common/etc/META-INF/jboss.xml 2006-12-20 09:35:13 UTC (rev 1831)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE jboss PUBLIC
+ "-//JBoss//DTD JBOSS 3.0//EN"
+ "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd">
+<jboss>
+ <enterprise-beans>
+ <session>
+ <ejb-name>Management</ejb-name>
+ <jndi-name>ejb/Management</jndi-name>
+ </session>
+ </enterprise-beans>
+</jboss>
Modified: trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java
===================================================================
--- trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/docs/examples/common/src/org/jboss/example/jms/common/ExampleSupport.java 2006-12-20 09:35:13 UTC (rev 1831)
@@ -6,7 +6,14 @@
*/
package org.jboss.example.jms.common;
+import org.jboss.jms.client.JBossConnection;
+import org.jboss.jms.client.delegate.DelegateSupport;
+import org.jboss.jms.client.state.ConnectionState;
+import org.jboss.example.jms.common.bean.ManagementHome;
+import org.jboss.example.jms.common.bean.Management;
+
import javax.jms.ConnectionMetaData;
+import javax.jms.Connection;
import javax.naming.InitialContext;
/**
@@ -24,6 +31,79 @@
// Static --------------------------------------------------------
+ public static int getServerID(Connection conn) throws Exception
+ {
+ if (!(conn instanceof JBossConnection))
+ {
+ throw new Exception("Connection not an instance of JBossConnection");
+ }
+
+ JBossConnection jbconn = (JBossConnection)conn;
+
+ DelegateSupport del = (DelegateSupport)jbconn.getDelegate();
+
+ ConnectionState state = (ConnectionState)del.getState();
+
+ return state.getServerID();
+ }
+
+ public static void assertEquals(Object o, Object o2)
+ {
+ if (o == null && o2 == null)
+ {
+ return;
+ }
+
+ if (o.equals(o2))
+ {
+ return;
+ }
+
+ throw new RuntimeException("Assertion failed, " + o + " != " + o2);
+ }
+
+ public static void assertEquals(int i, int i2)
+ {
+ if (i == i2)
+ {
+ return;
+ }
+
+ throw new RuntimeException("Assertion failed, " + i + " != " + i2);
+ }
+
+ public static void assertNotEquals(int i, int i2)
+ {
+ if (i != i2)
+ {
+ return;
+ }
+
+ throw new RuntimeException("Assertion failed, " + i + " == " + i2);
+ }
+
+
+ public static void killActiveNode() throws Exception
+ {
+ // Currently it will always kill the primary node, ignoring nodeID
+
+ try
+ {
+ InitialContext ic = new InitialContext();
+
+ ManagementHome home = (ManagementHome)ic.lookup("ejb/Management");
+ Management bean = home.create();
+ bean.killAS();
+ }
+ catch(Exception e)
+ {
+ // OK, I expect exceptions following a VM kill
+
+ //e.printStackTrace();
+ }
+ }
+
+
// Attributes ----------------------------------------------------
private boolean failure;
@@ -99,32 +179,6 @@
System.out.println(info);
}
- protected void assertEquals(Object o, Object o2)
- {
- if (o == null && o2 == null)
- {
- return;
- }
-
- if (o.equals(o2))
- {
- return;
- }
-
- throw new RuntimeException("Assertion failed, " + o + " != " + o2);
- }
-
- protected void assertEquals(int i, int i2)
- {
- if (i == i2)
- {
- return;
- }
-
- throw new RuntimeException("Assertion failed, " + i + " != " + i2);
- }
-
-
// Private -------------------------------------------------------
protected void setup() throws Exception
Added: trunk/docs/examples/common/src/org/jboss/example/jms/common/bean/Management.java
===================================================================
--- trunk/docs/examples/common/src/org/jboss/example/jms/common/bean/Management.java 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/docs/examples/common/src/org/jboss/example/jms/common/bean/Management.java 2006-12-20 09:35:13 UTC (rev 1831)
@@ -0,0 +1,25 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.example.jms.common.bean;
+
+import javax.ejb.EJBObject;
+import java.rmi.RemoteException;
+
+/**
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision: 1766 $</tt>
+
+ * $Id: StatelessSessionExample.java 1766 2006-12-11 22:29:27Z ovidiu.feodorov at jboss.com $
+ */
+
+public interface Management extends EJBObject
+{
+ /**
+ * It kills the VM running the node instance. Needed by the failover tests.
+ */
+ public void killAS() throws Exception, RemoteException;
+}
Added: trunk/docs/examples/common/src/org/jboss/example/jms/common/bean/ManagementBean.java
===================================================================
--- trunk/docs/examples/common/src/org/jboss/example/jms/common/bean/ManagementBean.java 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/docs/examples/common/src/org/jboss/example/jms/common/bean/ManagementBean.java 2006-12-20 09:35:13 UTC (rev 1831)
@@ -0,0 +1,73 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.example.jms.common.bean;
+
+import javax.ejb.SessionBean;
+import javax.ejb.SessionContext;
+import javax.ejb.EJBException;
+import javax.jms.ConnectionFactory;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.Connection;
+import javax.jms.MessageConsumer;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.TextMessage;
+import javax.jms.QueueBrowser;
+import javax.jms.JMSException;
+import javax.naming.InitialContext;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.rmi.RemoteException;
+
+/**
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision: 1766 $</tt>
+
+ * $Id: StatelessSessionExampleBean.java 1766 2006-12-11 22:29:27Z ovidiu.feodorov at jboss.com $
+ */
+public class ManagementBean implements SessionBean
+{
+ private SessionContext ctx;
+
+ public void killAS() throws Exception
+ {
+ System.out.println("######");
+ System.out.println("######");
+ System.out.println("######");
+ System.out.println("######");
+ System.out.println("###### SIMULATING A FAILURE, KILLING THE VM!");
+ System.out.println("######");
+ System.out.println("######");
+ System.out.println("######");
+ System.out.println("######");
+
+ Runtime.getRuntime().halt(1);
+ }
+
+ public void setSessionContext(SessionContext ctx) throws EJBException, RemoteException
+ {
+ this.ctx = ctx;
+ }
+
+ public void ejbCreate()
+ {
+ }
+
+ public void ejbRemove() throws EJBException
+ {
+ }
+
+ public void ejbActivate() throws EJBException, RemoteException
+ {
+ }
+
+ public void ejbPassivate() throws EJBException, RemoteException
+ {
+ }
+
+}
Added: trunk/docs/examples/common/src/org/jboss/example/jms/common/bean/ManagementHome.java
===================================================================
--- trunk/docs/examples/common/src/org/jboss/example/jms/common/bean/ManagementHome.java 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/docs/examples/common/src/org/jboss/example/jms/common/bean/ManagementHome.java 2006-12-20 09:35:13 UTC (rev 1831)
@@ -0,0 +1,23 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.example.jms.common.bean;
+
+import javax.ejb.EJBHome;
+import javax.ejb.CreateException;
+import java.rmi.RemoteException;
+
+/**
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision: 563 $</tt>
+
+ * $Id: StatelessSessionExampleHome.java 563 2005-12-30 22:04:19Z ovidiu $
+ */
+
+public interface ManagementHome extends EJBHome
+{
+ public Management create() throws RemoteException, CreateException;
+}
Modified: trunk/docs/examples/distributed-topic/build.xml
===================================================================
--- trunk/docs/examples/distributed-topic/build.xml 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/docs/examples/distributed-topic/build.xml 2006-12-20 09:35:13 UTC (rev 1831)
@@ -27,6 +27,7 @@
<path id="common.compilation.classpath">
<fileset file="${jboss.home}/client/jboss-j2ee.jar"/>
<fileset file="${jboss.home}/client/jboss-j2se.jar"/>
+ <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
</path>
<path id="example.compilation.classpath">
Modified: trunk/docs/examples/distributed-topic/do-not-distribute.properties
===================================================================
--- trunk/docs/examples/distributed-topic/do-not-distribute.properties 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/docs/examples/distributed-topic/do-not-distribute.properties 2006-12-20 09:35:13 UTC (rev 1831)
@@ -4,4 +4,4 @@
#
messaging.client.jar.path=../../../output/lib
messaging.client.jar.name=jboss-messaging-client.jar
-jboss.home=C:\\work\\src\\jboss-4.0.4.GA-src\\build\\output\\jboss-4.0.4.GA
+#jboss.home=C:\\work\\src\\jboss-4.0.4.GA-src\\build\\output\\jboss-4.0.4.GA
Modified: trunk/docs/examples/distributed-topic/src/org/jboss/example/jms/distributedtopic/DistributedTopicExample.java
===================================================================
--- trunk/docs/examples/distributed-topic/src/org/jboss/example/jms/distributedtopic/DistributedTopicExample.java 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/docs/examples/distributed-topic/src/org/jboss/example/jms/distributedtopic/DistributedTopicExample.java 2006-12-20 09:35:13 UTC (rev 1831)
@@ -51,14 +51,16 @@
{
public void example() throws Exception
{
+
String destinationName = getDestinationJNDIName();
+
InitialContext ic = null;
- InitialContext ic2 = null;
- Connection connection = null;
- Connection connection2 = null;
+ Connection connection0 = null;
+ Connection connection1 = null;
+
try
{
// connecting to the first node
@@ -69,58 +71,68 @@
Topic distributedTopic = (Topic)ic.lookup(destinationName);
log("Distributed topic " + destinationName + " exists");
- connection = cf.createConnection();
- Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer publisher = session.createProducer(distributedTopic);
- MessageConsumer subscriber = session.createConsumer(distributedTopic);
+ // When connecting to a messaging cluster, the ConnectionFactory has the capability of
+ // transparently creating physical connections to different cluster nodes, in a round
+ // robin fashion ...
- ExampleListener messageListener = new ExampleListener("MessageListener 1");
- subscriber.setMessageListener(messageListener);
- // connecting to the second node
+ // ... so this is a connection to a cluster node
+ connection0 = cf.createConnection();
- Hashtable environment = new Hashtable();
- environment.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
- environment.put("java.naming.provider.url", "jnp://localhost:1199");
- environment.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
+ // ... and this is a connection to a different cluster node
+ connection1 = cf.createConnection();
- ic2 = new InitialContext(environment);
+ // Let's make sure that (this example is also a smoke test)
+ assertNotEquals(getServerID(connection0), getServerID(connection1));
- ConnectionFactory cf2 = (ConnectionFactory)ic2.lookup("/ConnectionFactory");
- connection2 = cf2.createConnection();
- Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ // Create a session, a producer and consumer for the distributed topic, using connection0
- MessageConsumer subscriber2 = session2.createConsumer(distributedTopic);
+ Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);
- ExampleListener messageListener2 = new ExampleListener("MessageListener 2");
- subscriber2.setMessageListener(messageListener2);
+ MessageConsumer subscriber0 = session0.createConsumer(distributedTopic);
+ ExampleListener messageListener0 = new ExampleListener("MessageListener 0");
+ subscriber0.setMessageListener(messageListener0);
- // starting the connections
- connection.start();
- connection2.start();
+ MessageProducer publisher = session0.createProducer(distributedTopic);
- // sending the message
- TextMessage message = session.createTextMessage("Hello!");
+
+ // Create a session and a consumer for the distributed topic, using connection1
+
+ Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageConsumer subscriber1 = session1.createConsumer(distributedTopic);
+
+ ExampleListener messageListener1 = new ExampleListener("MessageListener 1");
+ subscriber1.setMessageListener(messageListener1);
+
+ // Starting the connections
+
+ connection0.start();
+ connection1.start();
+
+ // Sending the message
+
+ TextMessage message = session0.createTextMessage("Hello!");
publisher.send(message);
log("The message was successfully published on the distributed topic");
- messageListener.waitForMessage();
- messageListener2.waitForMessage();
+ messageListener0.waitForMessage();
+ messageListener1.waitForMessage();
- message = (TextMessage)messageListener.getMessage();
- log(messageListener.getName() + " received message: " + message.getText());
+ message = (TextMessage)messageListener0.getMessage();
+ log(messageListener0.getName() + " received message: " + message.getText());
assertEquals("Hello!", message.getText());
- message = (TextMessage)messageListener2.getMessage();
- log(messageListener2.getName() + " received message: " + message.getText());
+ message = (TextMessage)messageListener1.getMessage();
+ log(messageListener1.getName() + " received message: " + message.getText());
assertEquals("Hello!", message.getText());
- displayProviderInfo(connection.getMetaData());
+ displayProviderInfo(connection0.getMetaData());
}
finally
@@ -137,41 +149,29 @@
}
}
- if(ic2 != null)
- {
- try
- {
- ic2.close();
- }
- catch(Exception e)
- {
- throw e;
- }
- }
-
try
{
- if (connection != null)
+ if (connection0 != null)
{
- connection.close();
+ connection0.close();
}
}
catch(JMSException e)
{
- log("Could not close connection " + connection + ", exception was " + e);
+ log("Could not close connection " + connection0 + ", exception was " + e);
throw e;
}
try
{
- if (connection2 != null)
+ if (connection1 != null)
{
- connection2.close();
+ connection1.close();
}
}
catch(JMSException e)
{
- log("Could not close connection " + connection2 + ", exception was " + e);
+ log("Could not close connection " + connection1 + ", exception was " + e);
throw e;
}
}
Added: trunk/docs/examples/queue-failover/README.html
===================================================================
--- trunk/docs/examples/queue-failover/README.html 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/docs/examples/queue-failover/README.html 2006-12-20 09:35:13 UTC (rev 1831)
@@ -0,0 +1,155 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <meta content="text/html; charset=ISO-8859-1"
+ http-equiv="content-type">
+ <title>JBoss Messaging Example - JMS Topic</title>
+</head>
+<body>
+<br>
+<h1>JBoss Messaging Distributed Topic Example</h1>
+$Revision: 1017 $
+<h2>Overview</h2>
+<br>
+This example demonstrates how to write JMS code that connects to a
+JBoss Messaging cluster and sends messages to a distributed topic. The
+client code creates two distinct JMS connections to two different
+cluster nodes. Each connection is then used to create a subscriber for
+the distributed topic. The example is considered
+successful
+if both subscribers receive a message sent to the topic.<br>
+<br>
+<span style="font-weight: bold;">Note<br>
+</span>
+<div style="margin-left: 40px;">In order to create connections to
+different cluster nodes, the example looks up and downloads
+ConnectionFactories bound in the local JNDI space of each cluster node.
+This is done by explicitely configuring the JNDI client environment to
+point to different physical cluster nodes. This is just a temporary
+solution, used only by the current Alpha release. Subsequent releases
+will use HA-JNDI.<br>
+<span style="font-weight: bold;"></span></div>
+<br>
+<br>
+This example relies on having access to a running JBoss Messaging
+cluster with at least two nodes. The JBoss Messaging cluster must be
+installed and started according to
+the
+"Installation" paragraph from the clustering documentation, bundled
+with the release (<a href="../../docs/clustering/html/index.html">HTML</a>,
+<a href="../../docs/clustering/html_single/index.html">HTML-single</a>
+and <a href="../../docs/clustering/pdf/ClusteringGuide.pdf">PDF</a>).
+The
+clustering documentation is also available on-line at <a
+ href="http://labs.jboss.com/portal/jbossmessaging/docs/index.html">http://labs.jboss.com/portal/jbossmessaging/docs/index.html</a>.
+<br>
+<br>
+This example also relies on having access to the <span
+ style="font-family: monospace;">jboss-messaging-client.jar</span>
+archive included with the release bundle. If you run this example
+from
+an unzipped installation bundle, the example run script is correctly
+configured to find the client jar. Otherwise, you must modify example's
+<span style="font-family: monospace;">build.xml</span> accordingly.<br>
+<span style="font-style: italic;"></span><br>
+<h2>Running the example</h2>
+<span style="font-family: monospace;"></span><span
+ style="font-family: monospace;"></span><br>
+1. Make sure that a JBoss Messaging cluster with at least two nodes is
+up and running.<br>
+<br>
+2. Go to the example's home directory<br>
+<br>
+<div style="margin-left: 40px;"><span style="font-family: monospace;">cd
+...\examples\distributed-topic</span><br>
+</div>
+<br>
+3. Run the example:<br>
+<br>
+<div style="margin-left: 40px;"><span style="font-family: monospace;">ant</span>
+<br>
+<br>
+<br>
+</div>
+The output of a successful run should be similar to:<br>
+<div style="margin-left: 40px;"><br>
+</div>
+<table
+ style="width: 90%; text-align: left; font-family: monospace; background-color: rgb(204, 204, 204); margin-left: 40px;"
+ border="1" cellpadding="2" cellspacing="2">
+ <tbody>
+ <tr>
+ <td style="vertical-align: top;">
+ <div style="margin-left: 40px;"><br>
+ </div>
+$ ant<br>
+Buildfile: build.xml<br>
+ <br>
+identify:<br>
+ [echo]
+###########################################################################<br>
+ [echo]
+#
+Running the DISTRIBUTED TOPIC
+example
+#<br>
+ [echo]
+###########################################################################<br>
+ [echo] The
+topic: testDistributedTopic<br>
+ [echo] The client jar:
+../../../output/lib/jboss-messaging-client.jar<br>
+ <br>
+sanity-check:<br>
+ <br>
+init:<br>
+ [mkdir] Created dir:
+C:\work\src\svn\messaging\docs\examples\distributed-topic\output<br>
+ [mkdir] Created dir:
+C:\work\src\svn\messaging\docs\examples\common\output<br>
+ <br>
+compile:<br>
+ [javac] Compiling 2 source files to
+C:\work\src\svn\messaging\docs\examples\common\output<br>
+ [javac] Compiling 2 source files to
+C:\work\src\svn\messaging\docs\examples\distributed-topic\output<br>
+ <br>
+run:<br>
+ [java] Distributed topic
+/topic/testDistributedTopic exists<br>
+ [java] The message was successfully published
+on the distributed topic<br>
+ [java] MessageListener 1 received message:
+Hello!<br>
+ [java] MessageListener 2 received message:
+Hello!<br>
+ [java] The example connected to JBoss
+Messaging version 1.2.0.Alpha1 (1.2)<br>
+ <br>
+ [java] #####################<br>
+ [java] ###
+SUCCESS! ###<br>
+ [java] #####################<br>
+ <br>
+BUILD SUCCESSFUL<br>
+Total time: 4 seconds<br>
+ <br>
+ <br>
+ </td>
+ </tr>
+ </tbody>
+</table>
+<div style="margin-left: 40px;"><br>
+</div>
+<br>
+<br>
+<br>
+<hr style="width: 100%; height: 2px;"><br>
+<br>
+<br>
+<br>
+<br>
+<br>
+<br>
+</body>
+</html>
Added: trunk/docs/examples/queue-failover/build.xml
===================================================================
--- trunk/docs/examples/queue-failover/build.xml 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/docs/examples/queue-failover/build.xml 2006-12-20 09:35:13 UTC (rev 1831)
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+
+ To run the example, set JBOSS_HOME and run ant (with no parameters)
+
+ $Id: build.xml 974 2006-05-22 21:35:38 -0600 (Mon, 22 May 2006) ovidiu $
+
+ -->
+
+<project name="DistributedTopicExample" default="run">
+
+ <property environment="ENV"/>
+
+ <!--
+ If you don't find this file in the current directory, it's ok, it's intended to provide
+ defaults for in-workarea testing and it's not meant for distribution with the example bundle.
+ -->
+ <property file="do-not-distribute.properties"/>
+
+ <!-- These properties may be overriden by calling ants when this example is used in a smoke test -->
+ <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="example.queue.name" value="testDistributedQueue"/>
+
+ <path id="common.compilation.classpath">
+ <fileset file="${jboss.home}/client/jboss-j2ee.jar"/>
+ <fileset file="${jboss.home}/client/jboss-j2se.jar"/>
+ <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+ </path>
+
+ <path id="example.compilation.classpath">
+ <path refid="common.compilation.classpath"/>
+ <pathelement path="../common/output"/>
+ </path>
+
+ <path id="execution.classpath">
+ <pathelement path="./etc"/>
+ <pathelement path="../common/output"/>
+ <pathelement path="./output"/>
+ <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
+ <fileset dir="${jboss.home}/client" includes="*.jar"/>
+ </path>
+
+ <target name="identify">
+ <echo message="###########################################################################"/>
+ <echo message="# Running the QUEUE FAILOVER 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/lib"/>
+ <mkdir dir="../common/output"/>
+ </target>
+
+ <target name="compile" depends="init">
+ <javac destdir="../common/output" debug="on" debuglevel="lines,vars,source">
+ <src path="../common/src"/>
+ <classpath refid="common.compilation.classpath"/>
+ </javac>
+ <javac destdir="./output" debug="on" debuglevel="lines,vars,source">
+ <src path="./src"/>
+ <classpath refid="example.compilation.classpath"/>
+ </javac>
+ </target>
+
+ <target name="jar" depends="compile">
+ <jar destfile="./output/lib/application-server-killer.jar">
+ <fileset dir="../common/etc" includes="META-INF/**"/>
+ <fileset dir="../common/output" includes="org/jboss/example/jms/common/bean/*.class"/>
+ </jar>
+ </target>
+
+ <target name="deploy" depends="jar">
+ <copy file="./output/lib/application-server-killer.jar"
+ todir="${jboss.home}/server/messaging-node0/deploy"/>
+ <antcall target="sleep"><param name="sleep.interval" value="5"/></antcall>
+ </target>
+
+
+ <target name="run" depends="deploy">
+ <!--
+ DistributedTopicExample expects to find the name of the topic to connect to as value of
+ the 'example.topic.name' property, which *may* be defined by calling ant when this
+ example is used in a smoke test.
+ -->
+ <java classname="org.jboss.example.jms.failover.QueueFailoverExample"
+ 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>
+ <antcall target="undeploy"/>
+ </target>
+
+ <target name="undeploy">
+ <delete file="${jboss.home}/server/messaging-node0/deploy/application-server-killer.jar" quiet="true"/>
+ </target>
+
+ <target name="clean" depends="undeploy">
+ <delete dir="./output" quiet="true"/>
+ <delete dir="../common/output" quiet="true"/>
+ </target>
+
+ <target name="sleep">
+ <echo message="Sleeping for ${sleep.interval} seconds ..."/>
+ <sleep seconds="${sleep.interval}"/>
+ </target>
+
+</project>
+
Added: trunk/docs/examples/queue-failover/do-not-distribute.properties
===================================================================
--- trunk/docs/examples/queue-failover/do-not-distribute.properties 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/docs/examples/queue-failover/do-not-distribute.properties 2006-12-20 09:35:13 UTC (rev 1831)
@@ -0,0 +1,7 @@
+#
+# This file provides values for in-workarea example testing.
+# DO NOT DISTRIBUTE!
+#
+messaging.client.jar.path=../../../output/lib
+messaging.client.jar.name=jboss-messaging-client.jar
+#jboss.home=C:\\work\\src\\jboss-4.0.4.GA-src\\build\\output\\jboss-4.0.4.GA
Added: trunk/docs/examples/queue-failover/etc/jndi.properties
===================================================================
--- trunk/docs/examples/queue-failover/etc/jndi.properties 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/docs/examples/queue-failover/etc/jndi.properties 2006-12-20 09:35:13 UTC (rev 1831)
@@ -0,0 +1,4 @@
+### JBossNS properties
+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/docs/examples/queue-failover/etc/log4j.xml
===================================================================
--- trunk/docs/examples/queue-failover/etc/log4j.xml 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/docs/examples/queue-failover/etc/log4j.xml 2006-12-20 09:35:13 UTC (rev 1831)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- $Id: log4j.xml 536 2005-12-22 00:28:39 -0600 (Thu, 22 Dec 2005) ovidiu $ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out"/>
+ <param name="Threshold" value="INFO"/>
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p @%t [%c{1}] %m%n"/>
+ </layout>
+ </appender>
+
+ <root>
+ <appender-ref ref="CONSOLE"/>
+ </root>
+
+</log4j:configuration>
Added: trunk/docs/examples/queue-failover/src/org/jboss/example/jms/failover/QueueFailoverExample.java
===================================================================
--- trunk/docs/examples/queue-failover/src/org/jboss/example/jms/failover/QueueFailoverExample.java 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/docs/examples/queue-failover/src/org/jboss/example/jms/failover/QueueFailoverExample.java 2006-12-20 09:35:13 UTC (rev 1831)
@@ -0,0 +1,152 @@
+/*
+* 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.failover;
+
+import javax.naming.InitialContext;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Session;
+import javax.jms.MessageProducer;
+import javax.jms.MessageConsumer;
+import javax.jms.TextMessage;
+import javax.jms.JMSException;
+import javax.jms.Queue;
+
+import org.jboss.example.jms.common.ExampleSupport;
+
+/**
+ * The example creates a connection to a clustered messaging instance and sends a message to a
+ * clustered queue. The example then kills the cluster node the connection was created to and then
+ * shows how the client code can receive the message with using the *same* connection (that, in
+ * the mean time, have transparently failed over to another cluster node).
+ *
+ * Since this example is also used as a smoke test, it is essential that the VM exits with exit
+ * code 0 in case of successful execution and a non-zero value on failure.
+ *
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision: 1001 $</tt>
+ *
+ * $Id: TopicExample.java 1001 2006-06-24 09:05:40Z timfox $
+ */
+public class QueueFailoverExample extends ExampleSupport
+{
+ public void example() throws Exception
+ {
+
+ String destinationName = getDestinationJNDIName();
+
+
+ InitialContext ic = null;
+
+
+ Connection connection = null;
+
+ try
+ {
+ // Create a connection to the clustered messaging instance
+
+ ic = new InitialContext();
+
+ ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
+ Queue distributedQueue = (Queue)ic.lookup(destinationName);
+ log("Distributed queue " + destinationName + " exists");
+
+
+ // When connecting to a messaging cluster, the ConnectionFactory has the capability of
+ // transparently creating physical connections to different cluster nodes, in a round
+ // robin fashion ...
+
+ connection = cf.createConnection();
+
+ connection.start();
+
+ // Send a message to the queue
+
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(distributedQueue);
+ TextMessage message = session.createTextMessage("Hello!");
+
+ producer.send(message);
+
+
+ log("The message was successfully sent to the distributed queue");
+
+
+
+ // Kill the active node
+ killActiveNode();
+
+
+ Thread.sleep(30000); // TODO not necesare after we install the client valve
+
+
+ // Transparenty create a consumer and receive the message
+
+ MessageConsumer consumer = session.createConsumer(distributedQueue);
+
+ message = (TextMessage)consumer.receive(2000);
+ log("Received message: " + message.getText());
+ assertEquals("Hello!", message.getText());
+
+ displayProviderInfo(connection.getMetaData());
+
+ }
+ finally
+ {
+ if(ic != null)
+ {
+ try
+ {
+ ic.close();
+ }
+ catch(Exception e)
+ {
+ throw e;
+ }
+ }
+
+ try
+ {
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }
+ catch(JMSException e)
+ {
+ log("Could not close connection " + connection + ", exception was " + e);
+ throw e;
+ }
+ }
+ }
+
+ protected boolean isQueueExample()
+ {
+ return true;
+ }
+
+ public static void main(String[] args)
+ {
+ new QueueFailoverExample().run();
+ }
+
+}
Modified: trunk/messaging.iml
===================================================================
--- trunk/messaging.iml 2006-12-20 06:36:47 UTC (rev 1830)
+++ trunk/messaging.iml 2006-12-20 09:35:13 UTC (rev 1831)
@@ -9,6 +9,7 @@
<sourceFolder url="file://$MODULE_DIR$/docs/examples/distributed-topic/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/docs/examples/http/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/docs/examples/mdb/src" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/docs/examples/queue-failover/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/docs/examples/queue/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/docs/examples/secure-socket/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/docs/examples/stateless/src" isTestSource="false" />
More information about the jboss-cvs-commits
mailing list