[jboss-cvs] JBoss Messaging SVN: r4189 - in trunk: docs and 15 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed May 14 08:08:30 EDT 2008
Author: ataylor
Date: 2008-05-14 08:08:30 -0400 (Wed, 14 May 2008)
New Revision: 4189
Added:
trunk/examples/
trunk/examples/build.properties
trunk/examples/jms/
trunk/examples/jms/build.xml
trunk/examples/jms/etc/
trunk/examples/jms/etc/jndi.properties
trunk/examples/jms/etc/log4j.xml
trunk/examples/jms/src/
trunk/examples/jms/src/org/
trunk/examples/jms/src/org/jboss/
trunk/examples/jms/src/org/jboss/jms/
trunk/examples/jms/src/org/jboss/jms/example/
trunk/examples/jms/src/org/jboss/jms/example/DurableSubscriberExample.java
trunk/examples/jms/src/org/jboss/jms/example/PerfExample.java
trunk/examples/jms/src/org/jboss/jms/example/QueueExample.java
trunk/examples/jms/src/org/jboss/jms/example/TopicExample.java
trunk/examples/jms/src/org/jboss/jms/util/
trunk/examples/jms/src/org/jboss/jms/util/PerfParams.java
trunk/examples/messaging/
trunk/examples/messaging/build.xml
trunk/examples/messaging/src/
trunk/examples/messaging/src/org/
trunk/examples/messaging/src/org/jboss/
trunk/examples/messaging/src/org/jboss/messaging/
trunk/examples/messaging/src/org/jboss/messaging/example/
trunk/examples/messaging/src/org/jboss/messaging/example/SSLClient.java
trunk/examples/messaging/src/org/jboss/messaging/example/SimpleClient.java
trunk/examples/messaging/src/org/jboss/messaging/example/SimpleExample.java
Removed:
trunk/docs/examples/
Modified:
trunk/build-messaging.xml
trunk/build.xml
Log:
moved examples up one directory
Modified: trunk/build-messaging.xml
===================================================================
--- trunk/build-messaging.xml 2008-05-14 11:49:48 UTC (rev 4188)
+++ trunk/build-messaging.xml 2008-05-14 12:08:30 UTC (rev 4189)
@@ -68,10 +68,11 @@
<property name="src.etc.dir" value="${src.dir}/etc"/>
<property name="src.bin.dir" value="${src.dir}/bin"/>
<property name="doc.dir" value="docs"/>
- <property name="doc.examples.dir" value="${doc.dir}/examples"/>
+ <property name="doc.examples.dir" value="examples"/>
<property name="doc.build.dir" value="${doc.dir}/userguide/build"/>
<property name="build.api.dir" value="${build.dir}/api"/>
<property name="native.bin.dir" value="native/bin"/>
+ <property name="examples.dir" value="examples"/>
<property name="build.distro.dir"
value="${build.dir}/${module.name}-${messaging.version.major}.${messaging.version.minor}.${messaging.version.micro}.${messaging.version.suffix}"/>
@@ -79,7 +80,7 @@
<property name="build.distro.config.dir" value="${build.distro.dir}/config"/>
<property name="build.distro.bin.dir" value="${build.distro.dir}/bin"/>
<property name="build.distro.api.dir" value="${build.distro.dir}/docs/api"/>
- <property name="build.distro.examples.dir" value="${build.distro.dir}/docs/examples"/>
+ <property name="build.distro.examples.dir" value="${build.distro.dir}/examples"/>
<!-- ======================================================================================== -->
<!-- Thirdparty Dependency Definitions -->
<!-- ======================================================================================== -->
@@ -113,7 +114,7 @@
<property name="test.src.dir" value="${test.dir}/src"/>
<property name="test-mask" value="*Test"/>
<property name="test.classes.dir" value="${test.build.dir}/classes"/>
- <property name="test.output.dir" value="${test.dir}/output"/>
+ <property name="test.output.dir" value="${test.dir}/build"/>
<property name="test.reports.dir" value="${test.output.dir}/reports"/>
<property name="test.stylesheets.dir" value="${test.output.dir}/stylesheets"/>
<property name="test.src.stylesheets.dir" value="${test.src.dir}/stylesheets"/>
@@ -373,6 +374,7 @@
<include name="org/jboss/messaging/core/message/**/*.class"/>
<include name="org/jboss/messaging/core/version/**/*.class"/>
<include name="org/jboss/messaging/core/server/JournalType.class"/>
+ <include name="org/jboss/messaging/core/journal/EncodingSupport.class"/>
<include name="org/jboss/messaging/core/server/ServerMessage.class"/>
</fileset>
</jar>
@@ -527,7 +529,7 @@
<exclude name="build.properties"/>
</fileset>
</copy>
- <echo message="lib.dir=../../../lib${line.separator}client.jar=../../../lib/jboss-messaging-client.jar${line.separator}config.dir=../../../config${line.separator}server.jar=../../../lib/jboss-messaging.jar"
+ <echo message="lib.dir=../../lib${line.separator}client.jar=../../lib/jboss-messaging-client.jar${line.separator}config.dir=../../config${line.separator}server.jar=../../lib/jboss-messaging.jar"
file="${build.distro.examples.dir}/build.properties"/>
<echo message="java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory${line.separator}java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces"
file="${build.distro.config.dir}/jndi.properties"/>
@@ -748,4 +750,36 @@
<echo message="${test.execution.classpath.unix}" file="${test.execution.classpath.file}"/>
</target>
+ <!--examples-->
+ <target name="queueExample" depends="client-jar">
+ <ant dir="${examples.dir}/jms" antfile="build.xml" target="queueExample"/>
+ </target>
+
+ <target name="topicExample" depends="client-jar">
+ <ant dir="${examples.dir}/jms" antfile="build.xml" target="topicExample"/>
+ </target>
+
+ <target name="DurSubExample" depends="client-jar">
+ <ant dir="${examples.dir}/jms" antfile="build.xml" target="DurSubExample"/>
+ </target>
+
+ <target name="perfListener" depends="client-jar">
+ <ant dir="${examples.dir}/jms" antfile="build.xml" target="perfListener"/>
+ </target>
+
+ <target name="perfSender" depends="client-jar">
+ <ant dir="${examples.dir}/jms" antfile="build.xml" target="perfSender"/>
+ </target>
+
+ <target name="SimpleClient" depends="client-jar">
+ <ant dir="${examples.dir}/messaging" antfile="build.xml" target="SimpleClient"/>
+ </target>
+
+ <target name="SSLClient" depends="client-jar">
+ <ant dir="${examples.dir}/messaging" antfile="build.xml" target="SSLClient"/>
+ </target>
+
+ <target name="SimpleExample" depends="client-jar">
+ <ant dir="${examples.dir}/messaging" antfile="build.xml" target="SimpleExample"/>
+ </target>
</project>
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2008-05-14 11:49:48 UTC (rev 4188)
+++ trunk/build.xml 2008-05-14 12:08:30 UTC (rev 4189)
@@ -125,4 +125,37 @@
<ant antfile="build-messaging.xml" target="compile-reports"/>
</target>
+
+ <!--example targets-->
+ <target name="queueExample" depends="createthirdparty">
+ <ant antfile="build-messaging.xml" target="queueExample"/>
+ </target>
+
+ <target name="topicExample" depends="createthirdparty">
+ <ant antfile="build-messaging.xml" target="topicExample"/>
+ </target>
+
+ <target name="DurSubExample" depends="createthirdparty">
+ <ant antfile="build-messaging.xml" target="DurSubExample"/>
+ </target>
+
+ <target name="perfListener" depends="createthirdparty">
+ <ant antfile="build-messaging.xml" target="perfListener"/>
+ </target>
+
+ <target name="perfSender" depends="createthirdparty">
+ <ant antfile="build-messaging.xml" target="perfSender"/>
+ </target>
+
+ <target name="SimpleClient" depends="createthirdparty">
+ <ant antfile="build-messaging.xml" target="SimpleClient"/>
+ </target>
+
+ <target name="SSLClient" depends="createthirdparty">
+ <ant antfile="build-messaging.xml" target="SSLClient"/>
+ </target>
+
+ <target name="SimpleExample" depends="createthirdparty">
+ <ant antfile="build-messaging.xml" target="SimpleExample"/>
+ </target>
</project>
\ No newline at end of file
Copied: trunk/examples/build.properties (from rev 4186, trunk/docs/examples/build.properties)
===================================================================
--- trunk/examples/build.properties (rev 0)
+++ trunk/examples/build.properties 2008-05-14 12:08:30 UTC (rev 4189)
@@ -0,0 +1,4 @@
+lib.dir=../../thirdparty
+client.jar=../../build/jars/jboss-messaging-client.jar
+server.jar=../../build/jars/jboss-messaging.jar
+config.dir=../../tests/etc/
Copied: trunk/examples/jms/build.xml (from rev 4186, trunk/docs/examples/jms/build.xml)
===================================================================
--- trunk/examples/jms/build.xml (rev 0)
+++ trunk/examples/jms/build.xml 2008-05-14 12:08:30 UTC (rev 4189)
@@ -0,0 +1,121 @@
+<?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. -->
+<!-- -->
+<!-- =========================================================================================== -->
+
+
+<!-- =========================================================================================== -->
+<!-- -->
+<!-- $Id: build.xml 4037 2008-04-11 13:12:57Z ataylor $ -->
+<!-- -->
+<!-- =========================================================================================== -->
+
+
+<project default="help" name="JBoss Messaging JMS Examples">
+
+ <property file="../build.properties"/>
+
+ <property name="src.dir" value="src"/>
+ <property name="etc.dir" value="etc"/>
+ <property name="build.dir" value="build"/>
+
+ <!--perf props-->
+ <property name="message.count" value="10000"/>
+ <property name="delivery.mode" value="NON_PERSISTENT"/>
+ <property name="sample.period" value="1"/>
+
+ <path id="compile.classpath">
+ <fileset dir="${lib.dir}">
+ <include name="**/*.jar"/>
+ </fileset>
+ <pathelement location="${client.jar}"/>
+ </path>
+
+ <path id="runtime.classpath">
+ <path refid="compile.classpath"/>
+ <pathelement location="${build.dir}"/>
+ <pathelement location="${etc.dir}"/>
+ </path>
+
+ <target name="help">
+ <echo>*****************************************************************</echo>
+ <echo>* to run examples execute one of the following *</echo>
+ <echo>* ant queueExample *</echo>
+ <echo>* ant topicExample *</echo>
+ <echo>* ant DurSubExample *</echo>
+ <echo>* ant perfListener followed by ant perfSender *</echo>
+ <echo>*****************************************************************</echo>
+ </target>
+
+ <target name="clean">
+ <delete dir="${build.dir}"/>
+ </target>
+
+ <target name="init">
+ <mkdir dir="${build.dir}"/>
+ </target>
+
+
+ <target name="compile" depends="init">
+ <javac srcdir="${src.dir}" destdir="${build.dir}" debug="on"
+ source="1.5">
+ <classpath refid="compile.classpath"/>
+ </javac>
+ </target>
+
+ <target name="queueExample" depends="compile">
+ <java classname="org.jboss.jms.example.QueueExample" fork="true">
+ <classpath refid="runtime.classpath"/>
+ </java>
+ </target>
+
+ <target name="topicExample" depends="compile">
+ <java classname="org.jboss.jms.example.TopicExample" fork="true">
+ <classpath refid="runtime.classpath"/>
+ </java>
+ </target>
+
+ <target name="DurSubExample" depends="compile">
+ <java classname="org.jboss.jms.example.DurableSubscriberExample" fork="true">
+ <classpath refid="runtime.classpath"/>
+ </java>
+ </target>
+
+ <target name="perfListener" depends="compile">
+ <java classname="org.jboss.jms.example.PerfExample" fork="true">
+ <classpath refid="runtime.classpath"/>
+ <arg value="-l"/>
+ </java>
+ </target>
+
+ <target name="perfSender" depends="compile">
+ <java classname="org.jboss.jms.example.PerfExample" fork="true">
+ <classpath refid="runtime.classpath"/>
+ <arg value="-s"/>
+ <arg value="${message.count}"/>
+ <arg value="${delivery.mode}"/>
+ <arg value="${sample.period}"/>
+ </java>
+ </target>
+</project>
\ No newline at end of file
Copied: trunk/examples/jms/etc/jndi.properties (from rev 4186, trunk/docs/examples/jms/etc/jndi.properties)
===================================================================
--- trunk/examples/jms/etc/jndi.properties (rev 0)
+++ trunk/examples/jms/etc/jndi.properties 2008-05-14 12:08:30 UTC (rev 4189)
@@ -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
\ No newline at end of file
Copied: trunk/examples/jms/etc/log4j.xml (from rev 4186, trunk/docs/examples/jms/etc/log4j.xml)
===================================================================
--- trunk/examples/jms/etc/log4j.xml (rev 0)
+++ trunk/examples/jms/etc/log4j.xml 2008-05-14 12:08:30 UTC (rev 4189)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- $Id: log4j.xml 2318 2007-02-15 02:11:43Z ovidiu.feodorov at jboss.com $ -->
+
+<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>
Copied: trunk/examples/jms/src/org/jboss/jms/example/DurableSubscriberExample.java (from rev 4186, trunk/docs/examples/jms/src/org/jboss/jms/example/DurableSubscriberExample.java)
===================================================================
--- trunk/examples/jms/src/org/jboss/jms/example/DurableSubscriberExample.java (rev 0)
+++ trunk/examples/jms/src/org/jboss/jms/example/DurableSubscriberExample.java 2008-05-14 12:08:30 UTC (rev 4189)
@@ -0,0 +1,84 @@
+/*
+ * 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.jms.example;
+
+import javax.jms.*;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * A simple JMS Durable Subscriber example.
+ *
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class DurableSubscriberExample
+{
+ public static void main(String[] args)
+ {
+ Connection connection = null;
+ try
+ {
+ //create an initial context, env will be picked up from jndi.properties
+ InitialContext initialContext = new InitialContext();
+ Topic topic = (Topic) initialContext.lookup("/topic/testTopic");
+ ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
+ connection = cf.createConnection();
+ connection.setClientID("myclientid");
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ session.createDurableSubscriber(topic, "myuniqueid");
+ connection.close();
+
+ connection = cf.createConnection();
+ connection.setClientID("myclientid");
+ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer messageProducer = session.createProducer(topic);
+ Message message = session.createTextMessage("This is a text message!");
+ messageProducer.send(message);
+ TopicSubscriber topicSubscriber = session.createDurableSubscriber(topic, "myuniqueid");
+ connection.start();
+ TextMessage message2 = (TextMessage) topicSubscriber.receive();
+ System.out.println("message = " + message2.getText());
+ topicSubscriber.close();
+ session.unsubscribe("myuniqueid");
+ }
+ catch (NamingException e)
+ {
+ e.printStackTrace();
+ }
+ catch (JMSException jmsException)
+ {
+ jmsException.printStackTrace();
+ }
+ finally
+ {
+ if (connection != null)
+ try
+ {
+ connection.close();
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+}
Copied: trunk/examples/jms/src/org/jboss/jms/example/PerfExample.java (from rev 4186, trunk/docs/examples/jms/src/org/jboss/jms/example/PerfExample.java)
===================================================================
--- trunk/examples/jms/src/org/jboss/jms/example/PerfExample.java (rev 0)
+++ trunk/examples/jms/src/org/jboss/jms/example/PerfExample.java 2008-05-14 12:08:30 UTC (rev 4189)
@@ -0,0 +1,253 @@
+/*
+ * 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.jms.example;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.jms.util.PerfParams;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.jms.*;
+import java.util.concurrent.*;
+
+/**
+ * a performance example that can be used to gather simple performance figures.
+ *
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class PerfExample
+{
+ private static Logger log = Logger.getLogger(PerfExample.class);
+ private Queue queue;
+ private Connection connection;
+ private int messageCount = 0;
+ private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
+ private Session session;
+ private Sampler command = new Sampler();
+
+ public static void main(String[] args)
+ {
+ PerfExample perfExample = new PerfExample();
+ if (args[0].equalsIgnoreCase("-l"))
+ {
+ perfExample.runListener();
+ }
+ else
+ {
+ int noOfMessages = Integer.parseInt(args[1]);
+ int deliveryMode = args[2].equalsIgnoreCase("persistent")? DeliveryMode.PERSISTENT: DeliveryMode.NON_PERSISTENT;
+ long samplePeriod = Long.parseLong(args[3]);
+ perfExample.runSender(noOfMessages, deliveryMode, samplePeriod);
+ }
+
+ }
+
+ private void init()
+ throws NamingException, JMSException
+ {
+ InitialContext initialContext = new InitialContext();
+ queue = (Queue) initialContext.lookup("/queue/testPerfQueue");
+ ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
+ connection = cf.createConnection();
+ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ }
+
+ public void runSender(int noOfMessage, int deliveryMode, long samplePeriod)
+ {
+ try
+ {
+ init();
+ MessageProducer producer = session.createProducer(queue);
+ producer.setDeliveryMode(deliveryMode);
+ ObjectMessage m = session.createObjectMessage();
+ PerfParams perfParams = new PerfParams();
+ perfParams.setNoOfMessagesToSend(noOfMessage);
+ perfParams.setDeliveryMode(deliveryMode);
+ perfParams.setSamplePeriod(samplePeriod);
+ m.setObject(perfParams);
+ producer.send(m);
+ scheduler.scheduleAtFixedRate(command, perfParams.getSamplePeriod(), perfParams.getSamplePeriod(), TimeUnit.SECONDS);
+ for (int i = 1; i <= noOfMessage; i++)
+ {
+ TextMessage textMessage = session.createTextMessage("" + i);
+ producer.send(textMessage);
+ messageCount++;
+ }
+ scheduler.shutdownNow();
+ log.info("average " + command.getAverage() + " per " + (perfParams.getSamplePeriod()/1000) + " secs" );
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ if (connection != null)
+ try
+ {
+ connection.close();
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void runListener()
+ {
+ try
+ {
+ init();
+ MessageConsumer messageConsumer = session.createConsumer(queue);
+ CountDownLatch countDownLatch = new CountDownLatch(1);
+ connection.start();
+ log.info("emptying queue");
+ while (true)
+ {
+ Message m = messageConsumer.receive(500);
+ if (m == null)
+ {
+ break;
+ }
+ }
+ messageConsumer.setMessageListener(new PerfListener(countDownLatch));
+ log.info("READY!!!");
+ countDownLatch.await();
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ if (connection != null)
+ try
+ {
+ connection.close();
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+
+ /**
+ * a message listener
+ */
+ class PerfListener implements MessageListener
+ {
+ private boolean started = false;
+ private PerfParams params = null;
+ int count = 0;
+ private CountDownLatch countDownLatch;
+
+
+ public PerfListener(CountDownLatch countDownLatch)
+ {
+ this.countDownLatch = countDownLatch;
+ }
+
+ public void onMessage(Message message)
+ {
+ if (!started)
+ {
+ started = true;
+ ObjectMessage m = (ObjectMessage) message;
+ try
+ {
+ params = (PerfParams) m.getObject();
+ }
+ catch (JMSException e)
+ {
+ params = new PerfParams();
+ }
+ log.info("params = " + params);
+ scheduler.scheduleAtFixedRate(command, params.getSamplePeriod(), params.getSamplePeriod(), TimeUnit.SECONDS);
+ }
+ else
+ {
+ try
+ {
+ TextMessage m = (TextMessage) message;
+ messageCount++;
+ int count = Integer.parseInt(m.getText());
+ if (count == params.getNoOfMessagesToSend())
+ {
+ countDownLatch.countDown();
+ /* try
+ {
+ Thread.sleep(params.getSamplePeriod());
+ }
+ catch (InterruptedException e)
+ {
+ //ignore
+ }*/
+ scheduler.shutdownNow();
+ log.info("average " + command.getAverage() + " per " + (params.getSamplePeriod()/1000) + " secs" );
+ }
+ }
+ catch (JMSException e)
+ {
+ log.info(e);
+ countDownLatch.countDown();
+ scheduler.shutdownNow();
+ }
+ }
+ }
+ }
+
+ /**
+ * simple class to gather performance figures
+ */
+ class Sampler implements Runnable
+ {
+ int sampleCount = 0;
+
+ long startTime = 0;
+
+ long samplesTaken = 0;
+
+ public void run()
+ {
+ if(startTime == 0)
+ {
+ startTime = System.currentTimeMillis();
+ }
+ long elapsed = System.currentTimeMillis() - startTime;
+ int lastCount = sampleCount;
+ sampleCount = messageCount;
+ samplesTaken++;
+ log.info(" time elapsed " + (elapsed / 1000) + " secs, message count " + (sampleCount) + " : this period " + (sampleCount - lastCount));
+ }
+
+ public long getAverage()
+ {
+ return sampleCount/samplesTaken;
+ }
+
+ }
+}
Copied: trunk/examples/jms/src/org/jboss/jms/example/QueueExample.java (from rev 4186, trunk/docs/examples/jms/src/org/jboss/jms/example/QueueExample.java)
===================================================================
--- trunk/examples/jms/src/org/jboss/jms/example/QueueExample.java (rev 0)
+++ trunk/examples/jms/src/org/jboss/jms/example/QueueExample.java 2008-05-14 12:08:30 UTC (rev 4189)
@@ -0,0 +1,83 @@
+/*
+ * 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.jms.example;
+
+import org.jboss.messaging.core.logging.Logger;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.jms.*;
+import java.util.ResourceBundle;
+import java.util.Properties;
+
+/**
+ * A simple JMS Queue example that creates a producer and consumer on a queue and sends a message.
+ *
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class QueueExample
+{
+ final static Logger log = Logger.getLogger(QueueExample.class);
+ public static void main(String[] args)
+ {
+ Connection connection = null;
+ try
+ {
+ //create an initial context, env will be picked up from jndi.properties
+ InitialContext initialContext = new InitialContext();
+ Queue queue = (Queue) initialContext.lookup("/queue/testQueue");
+ ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
+ connection = cf.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(queue);
+ Message message = session.createTextMessage("This is a text message!");
+ log.info("sending message to queue");
+ producer.send(message);
+ MessageConsumer messageConsumer = session.createConsumer(queue);
+ connection.start();
+ TextMessage message2 = (TextMessage) messageConsumer.receive(5000);
+ log.info("message received from queue");
+ log.info("message = " + message2.getText());
+ }
+ catch (NamingException e)
+ {
+ e.printStackTrace();
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ if(connection != null)
+ try
+ {
+ connection.close();
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ }
+}
Copied: trunk/examples/jms/src/org/jboss/jms/example/TopicExample.java (from rev 4186, trunk/docs/examples/jms/src/org/jboss/jms/example/TopicExample.java)
===================================================================
--- trunk/examples/jms/src/org/jboss/jms/example/TopicExample.java (rev 0)
+++ trunk/examples/jms/src/org/jboss/jms/example/TopicExample.java 2008-05-14 12:08:30 UTC (rev 4189)
@@ -0,0 +1,102 @@
+/*
+ * 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.jms.example;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.jms.*;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * A simple JMS Topic example that creates a producer and consumer on a queue and sends and receives a message via a
+ * Message Listener..
+ *
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class TopicExample
+{
+ public static void main(String[] args)
+ {
+ Connection connection = null;
+ try
+ {
+ //create an initial context, env will be picked up from jndi.properties
+ InitialContext initialContext = new InitialContext();
+ Topic topic = (Topic) initialContext.lookup("/topic/testTopic");
+ ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
+ connection = cf.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer messageProducer = session.createProducer(topic);
+
+ MessageConsumer messageConsumer = session.createConsumer(topic);
+ Message message = session.createTextMessage("This is a text message!");
+ final CountDownLatch latch = new CountDownLatch(1);
+ messageConsumer.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message message)
+ {
+ try
+ {
+ TextMessage textMessage = (TextMessage) message;
+ System.out.println("message = " + textMessage.getText());
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ latch.countDown();
+ }
+ });
+ connection.start();
+
+ messageProducer.send(message);
+
+ try
+ {
+ latch.await();
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+ catch (NamingException e)
+ {
+ e.printStackTrace();
+ }
+ catch (JMSException jmsException)
+ {
+ jmsException.printStackTrace();
+ }
+ finally
+ {
+ if (connection != null)
+ try
+ {
+ connection.close();
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+}
Copied: trunk/examples/jms/src/org/jboss/jms/util/PerfParams.java (from rev 4186, trunk/docs/examples/jms/src/org/jboss/jms/util/PerfParams.java)
===================================================================
--- trunk/examples/jms/src/org/jboss/jms/util/PerfParams.java (rev 0)
+++ trunk/examples/jms/src/org/jboss/jms/util/PerfParams.java 2008-05-14 12:08:30 UTC (rev 4189)
@@ -0,0 +1,71 @@
+/*
+ * 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.jms.util;
+
+import javax.jms.DeliveryMode;
+import java.io.Serializable;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+*/
+public class PerfParams implements Serializable
+{
+ int noOfMessagesToSend = 1000;
+ long samplePeriod = 1000;
+ int deliveryMode = DeliveryMode.NON_PERSISTENT;
+
+ public int getNoOfMessagesToSend()
+ {
+ return noOfMessagesToSend;
+ }
+
+ public void setNoOfMessagesToSend(int noOfMessagesToSend)
+ {
+ this.noOfMessagesToSend = noOfMessagesToSend;
+ }
+
+ public long getSamplePeriod()
+ {
+ return samplePeriod;
+ }
+
+ public void setSamplePeriod(long samplePeriod)
+ {
+ this.samplePeriod = samplePeriod;
+ }
+
+ public int getDeliveryMode()
+ {
+ return deliveryMode;
+ }
+
+ public void setDeliveryMode(int deliveryMode)
+ {
+ this.deliveryMode = deliveryMode;
+ }
+
+ public String toString()
+ {
+ return "message to send = " + noOfMessagesToSend + " samplePeriod = " + samplePeriod + "ms" + " DeliveryMode = " +
+ (deliveryMode == DeliveryMode.PERSISTENT?"PERSISTENT":"NON_PERSISTENT");
+ }
+}
Copied: trunk/examples/messaging/build.xml (from rev 4186, trunk/docs/examples/messaging/build.xml)
===================================================================
--- trunk/examples/messaging/build.xml (rev 0)
+++ trunk/examples/messaging/build.xml 2008-05-14 12:08:30 UTC (rev 4189)
@@ -0,0 +1,99 @@
+<?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. -->
+<!-- -->
+<!-- =========================================================================================== -->
+
+
+<!-- =========================================================================================== -->
+<!-- -->
+<!-- $Id: build.xml 4037 2008-04-11 13:12:57Z ataylor $ -->
+<!-- -->
+<!-- =========================================================================================== -->
+
+
+<project default="help" name="JBoss Messaging Examples">
+
+ <property file="../build.properties"/>
+
+ <property name="src.dir" value="src"/>
+ <property name="build.dir" value="build"/>
+
+ <path id="compile.classpath">
+ <fileset dir="${lib.dir}">
+ <include name="**/*.jar"/>
+ </fileset>
+ <pathelement location="${client.jar}"/>
+ <pathelement location="${server.jar}"/>
+ </path>
+
+ <path id="runtime.classpath">
+ <path refid="compile.classpath"/>
+ <pathelement location="${build.dir}"/>
+ <pathelement location="${config.dir}"/>
+ </path>
+
+ <target name="help">
+ <echo>*****************************************************************</echo>
+ <echo>* to run examples execute one of the following *</echo>
+ <echo>* ant SimpleClient *</echo>
+ <echo>* ant SSLClient (configure server for SSL) *</echo>
+ <echo>* ant SimpleExample (no server needed) *</echo>
+ <echo>*****************************************************************</echo>
+ </target>
+
+ <target name="clean">
+ <delete dir="${build.dir}"/>
+ </target>
+
+ <target name="init">
+ <mkdir dir="${build.dir}"/>
+ </target>
+
+
+ <target name="compile" depends="init">
+ <javac srcdir="${src.dir}" destdir="${build.dir}" debug="on"
+ source="1.5">
+ <classpath refid="compile.classpath"/>
+ </javac>
+ </target>
+
+ <target name="SimpleClient" depends="compile">
+ <java classname="org.jboss.messaging.example.SimpleClient" fork="true">
+ <classpath refid="runtime.classpath"/>
+ </java>
+ </target>
+
+ <target name="SSLClient" depends="compile">
+ <java classname="org.jboss.messaging.example.SSLClient" fork="true">
+ <classpath refid="runtime.classpath"/>
+ </java>
+ </target>
+
+ <target name="SimpleExample" depends="compile">
+ <java classname="org.jboss.messaging.example.SimpleExample" fork="true">
+ <classpath refid="runtime.classpath"/>
+ </java>
+ </target>
+
+</project>
\ No newline at end of file
Copied: trunk/examples/messaging/src/org/jboss/messaging/example/SSLClient.java (from rev 4186, trunk/docs/examples/messaging/src/org/jboss/messaging/example/SSLClient.java)
===================================================================
--- trunk/examples/messaging/src/org/jboss/messaging/example/SSLClient.java (rev 0)
+++ trunk/examples/messaging/src/org/jboss/messaging/example/SSLClient.java 2008-05-14 12:08:30 UTC (rev 4189)
@@ -0,0 +1,102 @@
+/*
+ * 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.messaging.example;
+
+import org.jboss.messaging.core.client.ClientConnection;
+import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ConnectionParams;
+import org.jboss.messaging.core.client.Location;
+import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientMessageImpl;
+import org.jboss.messaging.core.client.impl.ConnectionParamsImpl;
+import org.jboss.messaging.core.client.impl.LocationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.remoting.TransportType;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ * A simple Client that uses SSL, to run this example enable ssl on the server in the jbm-configuration.xml file.
+ * (<remoting-enable-ssl>true</remoting-enable-ssl>)
+ *
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class SSLClient
+{
+ public static void main(String[] args)
+ {
+ ClientConnection clientConnection = null;
+ try
+ {
+ Location location = new LocationImpl(TransportType.TCP, "localhost", 5400);
+ ConnectionParams connectionParams = new ConnectionParamsImpl();
+ connectionParams.setSSLEnabled(true);
+ connectionParams.setKeyStorePath("messaging.keystore");
+ connectionParams.setTrustStorePath("messaging.truststore");
+ connectionParams.setKeyStorePassword("secureexample");
+ connectionParams.setTrustStorePassword("secureexample");
+ //it is also possible to set up ssl by using system properties.
+ /*System.setProperty(ConnectionParams.REMOTING_ENABLE_SSL, "true");
+ System.setProperty(ConnectionParams.REMOTING_SSL_KEYSTORE_PATH,"messaging.keystore");
+ System.setProperty(ConnectionParams.REMOTING_SSL_KEYSTORE_PASSWORD,"secureexample");
+ System.setProperty(ConnectionParams.REMOTING_SSL_TRUSTSTORE_PATH,"messaging.truststore");
+ System.setProperty(ConnectionParams.REMOTING_SSL_TRUSTSTORE_PASSWORD,"secureexample");*/
+ ClientConnectionFactory connectionFactory = new ClientConnectionFactoryImpl(location, connectionParams);
+ clientConnection = connectionFactory.createConnection(null, null);
+ ClientSession clientSession = clientConnection.createClientSession(false, true, true, 100, true, false);
+ SimpleString queue = new SimpleString("queuejms.testQueue");
+ ClientProducer clientProducer = clientSession.createProducer(queue);
+ ClientMessage message = new ClientMessageImpl(JBossTextMessage.TYPE, false, 0,
+ System.currentTimeMillis(), (byte) 1);
+ message.getBody().putString("Hello!");
+ clientProducer.send(message);
+ ClientConsumer clientConsumer = clientSession.createConsumer(queue);
+ clientConnection.start();
+ Message msg = clientConsumer.receive(5000);
+ System.out.println("msg.getPayload() = " + msg.getBody().getString());
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ if(clientConnection != null)
+ {
+ try
+ {
+ clientConnection.close();
+ }
+ catch (MessagingException e1)
+ {
+ //
+ }
+ }
+ }
+
+ }
+}
Copied: trunk/examples/messaging/src/org/jboss/messaging/example/SimpleClient.java (from rev 4186, trunk/docs/examples/messaging/src/org/jboss/messaging/example/SimpleClient.java)
===================================================================
--- trunk/examples/messaging/src/org/jboss/messaging/example/SimpleClient.java (rev 0)
+++ trunk/examples/messaging/src/org/jboss/messaging/example/SimpleClient.java 2008-05-14 12:08:30 UTC (rev 4189)
@@ -0,0 +1,90 @@
+/*
+ * 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.messaging.example;
+
+import org.jboss.messaging.core.client.ClientConnection;
+import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ConnectionParams;
+import org.jboss.messaging.core.client.Location;
+import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientMessageImpl;
+import org.jboss.messaging.core.client.impl.ConnectionParamsImpl;
+import org.jboss.messaging.core.client.impl.LocationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.remoting.TransportType;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ * Uses the core messaging API to send and receive a message to a queue.
+ *
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class SimpleClient
+{
+ public static void main(String[] args)
+ {
+ ClientConnection clientConnection = null;
+ try
+ {
+ Location location = new LocationImpl(TransportType.TCP, "localhost", 5400);
+ ConnectionParams connectionParams = new ConnectionParamsImpl();
+ ClientConnectionFactory connectionFactory = new ClientConnectionFactoryImpl(location, connectionParams);
+ clientConnection = connectionFactory.createConnection();
+ ClientSession clientSession = clientConnection.createClientSession(false, true, true, 100, true, false);
+ SimpleString queue = new SimpleString("queuejms.testQueue");
+ ClientProducer clientProducer = clientSession.createProducer(queue);
+ ClientMessage message = new ClientMessageImpl(JBossTextMessage.TYPE, false, 0,
+ System.currentTimeMillis(), (byte) 1);
+ message.getBody().putString("Hello!");
+ clientProducer.send(message);
+ ClientConsumer clientConsumer = clientSession.createConsumer(queue);
+ clientConnection.start();
+ Message msg = clientConsumer.receive(5000);
+ System.out.println("msg.getPayload() = " + msg.getBody().getString());
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ if (clientConnection != null)
+ {
+ try
+ {
+ clientConnection.close();
+ }
+ catch (MessagingException e1)
+ {
+ //
+ }
+ }
+ }
+
+ }
+}
Copied: trunk/examples/messaging/src/org/jboss/messaging/example/SimpleExample.java (from rev 4186, trunk/docs/examples/messaging/src/org/jboss/messaging/example/SimpleExample.java)
===================================================================
--- trunk/examples/messaging/src/org/jboss/messaging/example/SimpleExample.java (rev 0)
+++ trunk/examples/messaging/src/org/jboss/messaging/example/SimpleExample.java 2008-05-14 12:08:30 UTC (rev 4189)
@@ -0,0 +1,137 @@
+/*
+ * 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.messaging.example;
+
+import java.util.HashSet;
+
+import org.jboss.messaging.core.client.ClientConnection;
+import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ConnectionParams;
+import org.jboss.messaging.core.client.Location;
+import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.messaging.core.client.impl.ClientMessageImpl;
+import org.jboss.messaging.core.client.impl.ConnectionParamsImpl;
+import org.jboss.messaging.core.client.impl.LocationImpl;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.exception.MessagingException;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.remoting.TransportType;
+import org.jboss.messaging.core.security.CheckType;
+import org.jboss.messaging.core.security.JBMSecurityManager;
+import org.jboss.messaging.core.security.Role;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.core.server.impl.MessagingServerImpl;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ * A simple server is started with TCP transport, a message is sent and received.
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class SimpleExample
+{
+ public static void main(String[] args) throws Exception
+ {
+ MessagingServer messagingServer = null;
+ ClientConnection clientConnection = null;
+
+ try
+ {
+ //create a new server with an TCP transport
+ ConfigurationImpl configuration = new ConfigurationImpl();
+ configuration.setTransport(TransportType.TCP);
+ configuration.setHost("localhost");
+ messagingServer = new MessagingServerImpl(configuration);
+ //lets use our own security manager, we could use the default if needed but we would need to make sure that
+ // jbm-security.xml and queues.xml are in the classpath
+ messagingServer.setSecurityManager(new JBMSecurityManager()
+ {
+ public boolean validateUser(String user, String password)
+ {
+ return true;
+ }
+
+ public boolean validateUserAndRole(String user, String password, HashSet<Role> roles, CheckType checkType)
+ {
+ return true;
+ }
+ });
+ //start the server
+ messagingServer.start();
+ //add a new binding
+
+ SimpleString atestq = new SimpleString("atestq");
+
+ messagingServer.getPostOffice().addBinding(atestq, atestq, null, false, false);
+
+ //then we create a client as normal
+ Location location = new LocationImpl(TransportType.TCP, "localhost", 5400);
+ ConnectionParams connectionParams = new ConnectionParamsImpl();
+ ClientConnectionFactory connectionFactory = new ClientConnectionFactoryImpl(location, connectionParams);
+
+ clientConnection = connectionFactory.createConnection();
+ ClientSession clientSession = clientConnection.createClientSession(false, true, true, 100, true, false);
+ ClientProducer clientProducer = clientSession.createProducer(atestq);
+ ClientMessage message = new ClientMessageImpl(JBossTextMessage.TYPE, false, 0,
+ System.currentTimeMillis(), (byte) 1);
+ message.getBody().putString("Hello!");
+ clientProducer.send(message);
+ ClientConsumer clientConsumer = clientSession.createConsumer(atestq);
+ clientConnection.start();
+ Message msg = clientConsumer.receive(5000);
+ System.out.println("msg.getPayload() = " + msg.getBody().getString());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ if (clientConnection != null)
+ {
+ try
+ {
+ clientConnection.close();
+ }
+ catch (MessagingException e1)
+ {
+ //
+ }
+ }
+ if (messagingServer != null && messagingServer.isStarted())
+ {
+ try
+ {
+ messagingServer.stop();
+ }
+ catch (Exception e1)
+ {
+ //
+ }
+ }
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list