You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2006/09/20 00:07:25 UTC

svn commit: r447994 [26/46] - in /incubator/qpid/trunk/qpid: ./ cpp/ cpp/bin/ cpp/broker/ cpp/broker/inc/ cpp/broker/src/ cpp/broker/test/ cpp/client/ cpp/client/inc/ cpp/client/src/ cpp/client/test/ cpp/common/ cpp/common/concurrent/ cpp/common/concur...

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/config/jmscts.policy
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/config/jmscts.policy?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/config/jmscts.policy (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/config/jmscts.policy Tue Sep 19 15:06:50 2006
@@ -0,0 +1,5 @@
+// grant all users all permissions. This is only for test cases
+// and should be modified for deployment
+grant {
+	permission java.security.AllPermission;
+};

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/config/jmscts.properties
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/config/jmscts.properties?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/config/jmscts.properties (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/config/jmscts.properties Tue Sep 19 15:06:50 2006
@@ -0,0 +1,52 @@
+# =============================================================================
+# General properties         
+# -----------------------------------------------------------------------------
+
+#
+# Username & password
+#   A user name and password for creating Connection instances via
+#   TopicConnectionFactory.createTopicConnection(...) etc
+#
+valid.username=guest
+valid.password=guest
+
+#
+# Invalid user name and password
+#   As above, but guaranteed to fail.
+#
+invalid.username=guest
+invalid.password=guest
+
+#
+# Message receipt timeout
+#   The default time to wait for messages, in milliseconds
+#
+org.exolab.jmscts.core.MessagingBehaviour.timeout=2000
+
+
+# =============================================================================
+# Compliance test properties
+# -----------------------------------------------------------------------------
+
+#
+# Expiration interval
+#   Time in milliseconds to wait for the JMS provider to collect expired
+#   messages. 
+#   This can be set for providers which collect expired messages periodically,
+#   rather than at the moment they expire.
+#   NOTE: for OpenJMS 0.7.6, this should be set to 5000
+org.exolab.jmscts.test.producer.ttl.ExpirationTest.expirationInterval=0
+
+
+# =============================================================================
+# Stress test properties
+# -----------------------------------------------------------------------------
+
+#
+# Each of the following properties determines the no. of messages that
+# will be sent by stress tests
+#
+org.exolab.jmscts.stress.Send0KTest.count=1000
+org.exolab.jmscts.stress.ReceiveSize0KTest.count=1000
+org.exolab.jmscts.stress.SendReceive0KTest.count=1000
+org.exolab.jmscts.stress.SendReceive2Size0KTest.count=1000

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/config/jmscts.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/config/providers.xml
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/config/providers.xml?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/config/providers.xml (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/config/providers.xml Tue Sep 19 15:06:50 2006
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<!--
+ -
+ - Copyright (c) 2006 The Apache Software Foundation
+ -
+ - Licensed under the Apache License, Version 2.0 (the "License");
+ - you may not use this file except in compliance with the License.
+ - You may obtain a copy of the License at
+ -
+ -    http://www.apache.org/licenses/LICENSE-2.0
+ -
+ - Unless required by applicable law or agreed to in writing, software
+ - distributed under the License is distributed on an "AS IS" BASIS,
+ - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ - See the License for the specific language governing permissions and
+ - limitations under the License.
+ -
+ -->
+
+<!-- ====================================================================== -->
+<!-- Sample provider configuration file                                     -->
+<!--                                                                        -->
+<!-- This configures JMS CTS to test OpenJMS                                -->
+<!-- ====================================================================== -->
+
+<configuration>
+
+  <provider>
+    <name>AMQP</name>
+    <class>org.exolab.jmscts.amqp.AMQPProvider</class>
+    <paths>
+      <path>/home/guso/harness/jmscts-0.5-b2/lib/amqp-provider-0.0a1.jar</path>
+    </paths>
+    <config>
+    </config>
+  </provider>
+
+</configuration>

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/config/providers.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/readme.txt
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/readme.txt?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/readme.txt (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/readme.txt Tue Sep 19 15:06:50 2006
@@ -0,0 +1,5 @@
+The files present in the bin, config and src directories should be copied over a complete copy of jms-cts-0.5-b2.
+
+The path entries on the config/providers.xml and src/compile.sh files should be changed before attempting to run.
+
+The scripts expect a properly configured IBASE environment. Before attempting to run, the amqp provider classes must be packaged and installed. The src/compile.sh script will help to achieve that.
\ No newline at end of file

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/readme.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/compile.sh
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/compile.sh?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/compile.sh (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/compile.sh Tue Sep 19 15:06:50 2006
@@ -0,0 +1,31 @@
+#!/bin/sh
+#
+# Copyright (c) 2006 The Apache Software Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+JMSCTS_PATH=/home/guso/harness/jmscts-0.5-b2
+
+distjms="$IBASE/amqp/dist"
+lib="$IBASE/amqp/lib"
+lib2="$JMSCTS_PATH/lib/"
+libs="$lib/jakarta-commons/commons-collections-3.1.jar:$lib/util-concurrent/backport-util-concurrent.jar:$lib/mina/mina-0.7.3.jar:$lib/jms/jms.jar:$lib/logging-log4j/log4j-1.2.9.jar:$distjms/amqp-common.jar:$distjms/amqp-jms.jar"
+libs2="$lib2/ant-1.5.3-1.jar:$lib2/junit-3.8.1.jar:$lib2/ant-optional-1.5.3-1.jar:$lib2/log4j-1.2.7.jar:$lib2/castor-0.9.5.jar:$lib2/openjms-provider-0.5-b2.jar:$lib2/commons-cli-1.0.jar:$lib2/oro-2.0.7.jar:$lib2/commons-collections-2.1.jar:$lib2/xalan-2.5.1.jar:$lib2/commons-logging-1.0.2.jar:$lib2/xdoclet-1.2b2.jar:$lib2/concurrent-1.3.2.jar:$lib2/xdoclet-xdoclet-module-1.2b2.jar:$lib2/exolabcore-0.3.7.jar:$lib2/xdoclet-xjavadoc-uc-1.2b2.jar:$lib2/jms-1.0.2a.jar:$lib2/xerces-2.3.0.jar:$lib2/jmscts-0.5-b2.jar:$lib2/xml-apis-1.0.b2.jar"
+
+javac -classpath $libs:$libs2 $JMSCTS_PATH/src/providers/amqp/org/exolab/jmscts/amqp/*.java
+cd $JMSCTS_PATH/src/providers/amqp
+jar cvf amqp-provider-0.0a1.jar org/exolab/jmscts/amqp/*.class
+mv amqp-provider-0.0a1.jar $lib2
+

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/compile.sh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/compile.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/providers/amqp/org/exolab/jmscts/amqp/AMQPAdministrator.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/providers/amqp/org/exolab/jmscts/amqp/AMQPAdministrator.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/providers/amqp/org/exolab/jmscts/amqp/AMQPAdministrator.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/providers/amqp/org/exolab/jmscts/amqp/AMQPAdministrator.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,242 @@
+/**
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "Exolab" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Exoffice Technologies.  For written permission,
+ *    please contact jima@intalio.com.
+ *
+ * 4. Products derived from this Software may not be called "Exolab"
+ *    nor may "Exolab" appear in their names without prior written
+ *    permission of Exoffice Technologies. Exolab is a registered
+ *    trademark of Exoffice Technologies.
+ *
+ * 5. Due credit should be given to the Exolab Project
+ *    (http://www.exolab.org/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001, 2003 (C) Exoffice Technologies Inc. All Rights Reserved.
+ *
+ */
+package org.exolab.jmscts.amqp;
+
+import org.apache.qpid.client.*;
+import org.exolab.jmscts.provider.Administrator;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import java.net.InetAddress;
+import java.util.HashMap;
+
+/**
+ * This class provides methods for obtaining and manipulating administered
+ * objects managed by the Sonicmq implementation of JMS
+ *
+ */
+class AMQPAdministrator implements Administrator {
+    // AMQ Connection configuration
+    private int port = 5672;
+    private String host = "localhost";
+    private String user = "guest";
+    private String pass = "guest";
+    private String vhost = "/test";
+
+    // The cached broker connection & session
+    private AMQConnection _connection = null;
+    private Session _session = null;
+
+    // Factory request names
+    private static final String QUEUE_CONNECTION_FACTORY = "QueueConnectionFactory";
+    private static final String TOPIC_CONNECTION_FACTORY = "TopicConnectionFactory";
+
+    /**
+     * The cache of known administered objects
+     */
+    private HashMap<String, Object> _directory = new HashMap<String, Object>();
+
+    /**
+     * Returns the name of the QueueConnectionFactory bound in JNDI
+     *
+     * @return the default QueueConnectionFactory name
+     */
+    public String getQueueConnectionFactory() {
+        return QUEUE_CONNECTION_FACTORY;
+    }
+
+    /**
+     * Returns the name of the TopicConnectionFactory bound in JNDI
+     *
+     * @return the default TopicConnectionFactory name
+     */
+    public String getTopicConnectionFactory() {
+        return TOPIC_CONNECTION_FACTORY;
+    }
+
+    /**
+     * Returns the name of the XAQueueConnectionFactory bound in JNDI
+     *
+     * @return the default XAQueueConnectionFactory name
+     */
+    public String getXAQueueConnectionFactory() {
+        return null;
+    }
+
+    /**
+     * Returns the name of the XATopicConnectionFactory bound in JNDI
+     *
+     * @return the default XATopicConnectionFactory name
+     */
+    public String getXATopicConnectionFactory() {
+        return null;
+    }
+
+    /**
+     * Look up the named administered object
+     *
+     * @param name the name that the administered object is bound to
+     * @return the administered object bound to name
+     * @throws NamingException if the object is not bound, or the lookup fails
+     */
+    public Object lookup(String name) throws NamingException {
+        Object result = _directory.get(name);
+        if (result == null) {
+            if (name.equals(QUEUE_CONNECTION_FACTORY)) {
+                _directory.put(QUEUE_CONNECTION_FACTORY, new AMQConnectionFactory(host, port, user, pass, vhost));
+            } else if (name.equals(TOPIC_CONNECTION_FACTORY)) {
+                _directory.put(TOPIC_CONNECTION_FACTORY, new AMQConnectionFactory(host, port, user, pass, vhost));
+            } else {
+                throw new NameNotFoundException("Name not found: " + name);
+            }
+        }
+        return result;
+    }
+
+    /**
+     * Create an administered destination
+     *
+     * @param name the destination name
+     * @param queue if true, create a queue, else create a topic
+     * @throws JMSException if the destination cannot be created
+     */
+    public void createDestination(String name, boolean queue)
+        throws JMSException {
+        AMQDestination destination = null;
+
+        try {
+            if (queue) {
+                destination = new AMQQueue(name);
+                createConsumer(destination);
+            } else {
+                destination = new AMQTopic(name);
+                createConsumer(destination);
+            }
+
+            _directory.put(name, destination);
+        } catch (Exception exception) {
+            JMSException error = new JMSException(exception.getMessage());
+            error.setLinkedException(exception);
+            throw error;
+        }
+    }
+
+    /**
+     * Destroy an administered destination
+     *
+     * @param name the destination name
+     * @throws JMSException if the destination cannot be destroyed
+     */
+    public void destroyDestination(String name)
+        throws JMSException {
+
+        try {
+            Destination destination = (Destination) lookup(name);
+            _directory.remove(name);
+        } catch (NamingException exception) {
+            JMSException error = new JMSException(exception.getMessage());
+            error.setLinkedException(exception);
+            throw error;
+        } catch (Exception exception) {
+            JMSException error = new JMSException(exception.getMessage());
+            error.setLinkedException(exception);
+            throw error;
+        }
+    }
+
+    /**
+     * Returns true if an administered destination exists
+     *
+     * @param name the destination name
+     * @throws JMSException for any internal JMS provider error
+     */
+    public boolean destinationExists(String name)
+        throws JMSException {
+
+        boolean exists = false;
+        try {
+            lookup(name);
+            exists = true;
+        } catch (NameNotFoundException ignore) {
+        } catch (Exception exception) {
+            JMSException error = new JMSException(exception.getMessage());
+            error.setLinkedException(exception);
+            throw error;
+        }
+        return exists;
+    }
+
+    public void initialise() throws JMSException {
+        try {
+            InetAddress address = InetAddress.getLocalHost();
+            _connection = new AMQConnection(host, port, user, pass,
+                                                  address.getHostName(), vhost);
+            _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        } catch (Exception exception) {
+            JMSException error = new JMSException(exception.getMessage());
+            error.setLinkedException(exception);
+            throw error;
+        }
+    }
+
+    public synchronized void cleanup() {
+        try {
+            _connection.close();
+        } catch (JMSException e) {
+            e.printStackTrace();
+        }
+        _connection = null;
+        _session = null;
+        _directory.clear();
+    }
+
+    MessageConsumer createConsumer(AMQDestination destination) throws JMSException
+    {
+        return ((AMQSession)_session).createConsumer(destination, /*pre-fetch*/0, false, /*exclusive*/false, null);
+    }
+} //-- AMQPAdministrator

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/providers/amqp/org/exolab/jmscts/amqp/AMQPAdministrator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/providers/amqp/org/exolab/jmscts/amqp/AMQPProvider.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/providers/amqp/org/exolab/jmscts/amqp/AMQPProvider.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/providers/amqp/org/exolab/jmscts/amqp/AMQPProvider.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/providers/amqp/org/exolab/jmscts/amqp/AMQPProvider.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,95 @@
+/**
+ * Redistribution and use of this software and associated documentation
+ * ("Software"), with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain copyright
+ *    statements and notices.  Redistributions must also contain a
+ *    copy of this document.
+ *
+ * 2. Redistributions in binary form must reproduce the
+ *    above copyright notice, this list of conditions and the
+ *    following disclaimer in the documentation and/or other
+ *    materials provided with the distribution.
+ *
+ * 3. The name "Exolab" must not be used to endorse or promote
+ *    products derived from this Software without prior written
+ *    permission of Exoffice Technologies.  For written permission,
+ *    please contact jima@intalio.com.
+ *
+ * 4. Products derived from this Software may not be called "Exolab"
+ *    nor may "Exolab" appear in their names without prior written
+ *    permission of Exoffice Technologies. Exolab is a registered
+ *    trademark of Exoffice Technologies.
+ *
+ * 5. Due credit should be given to the Exolab Project
+ *    (http://www.exolab.org/).
+ *
+ * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
+ * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Copyright 2001, 2003 (C) Exoffice Technologies Inc. All Rights Reserved.
+ *
+ */
+package org.exolab.jmscts.amqp;
+
+import javax.jms.JMSException;
+
+import org.exolab.jmscts.provider.Administrator;
+import org.exolab.jmscts.provider.Provider;
+
+
+/**
+ * This class enables test cases to be run against the SonicMQ provider
+ *
+ * @see         AMQPAdministrator
+ */
+public class AMQPProvider implements Provider {
+
+    /**
+     * The administration interface
+     */
+    private AMQPAdministrator _admin = new AMQPAdministrator();
+
+    /**
+     * Construct an instance of the interface to the AMQP provider
+     */
+    public AMQPProvider() {
+    }
+
+    /**
+     * Initialises the administation interface
+     *
+     * @throws JMSException if the administration interface can't be 
+     * initialised 
+     */
+    public void initialise(boolean start) throws JMSException {
+        _admin.initialise();
+    }
+
+    /**
+     * Returns the administration interface 
+     */
+    public Administrator getAdministrator() {
+        return _admin;
+    }
+
+    /**
+     * This method cleans up the administrator
+     */
+    public void cleanup(boolean stop) {
+        _admin.cleanup();
+        _admin = null;
+    }
+
+} //-- AMQPProvider

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/src/providers/amqp/org/exolab/jmscts/amqp/AMQPProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/destinationurl/DestinationURLTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/destinationurl/DestinationURLTest.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/destinationurl/DestinationURLTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/destinationurl/DestinationURLTest.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,150 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.destinationurl;
+
+import org.junit.Test;
+import org.junit.Assert;
+import org.apache.qpid.url.AMQBindingURL;
+import org.apache.qpid.url.URLSyntaxException;
+import org.apache.qpid.exchange.ExchangeDefaults;
+import junit.framework.JUnit4TestAdapter;
+
+public class DestinationURLTest
+{
+    @Test
+    public void fullURL() throws URLSyntaxException
+    {
+
+        String url = "exchange.Class://exchangeName/Destination/Queue";
+
+        AMQBindingURL dest = new AMQBindingURL(url);
+
+        Assert.assertTrue(url.equals(dest.toString()));
+
+        Assert.assertTrue(dest.getExchangeClass().equals("exchange.Class"));
+        Assert.assertTrue(dest.getExchangeName().equals("exchangeName"));
+        Assert.assertTrue(dest.getDestinationName().equals("Destination"));
+        Assert.assertTrue(dest.getQueueName().equals("Queue"));
+    }
+
+    @Test
+    public void queue() throws URLSyntaxException
+    {
+
+        String url = "exchangeClass://exchangeName//Queue";
+
+        AMQBindingURL dest = new AMQBindingURL(url);
+
+        Assert.assertTrue(url.equals(dest.toString()));
+
+        Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass"));
+        Assert.assertTrue(dest.getExchangeName().equals("exchangeName"));
+        Assert.assertTrue(dest.getDestinationName().equals(""));
+        Assert.assertTrue(dest.getQueueName().equals("Queue"));
+    }
+
+    @Test
+    public void queueWithOption() throws URLSyntaxException
+    {
+
+        String url = "exchangeClass://exchangeName//Queue?option='value'";
+
+        AMQBindingURL dest = new AMQBindingURL(url);
+
+        Assert.assertTrue(url.equals(dest.toString()));
+
+        Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass"));
+        Assert.assertTrue(dest.getExchangeName().equals("exchangeName"));
+        Assert.assertTrue(dest.getDestinationName().equals(""));
+        Assert.assertTrue(dest.getQueueName().equals("Queue"));
+        Assert.assertTrue(dest.getOption("option").equals("value"));
+    }
+
+
+    @Test
+    public void destination() throws URLSyntaxException
+    {
+
+        String url = "exchangeClass://exchangeName/Destination/";
+
+        AMQBindingURL dest = new AMQBindingURL(url);
+
+        Assert.assertTrue(url.equals(dest.toString()));
+
+        Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass"));
+        Assert.assertTrue(dest.getExchangeName().equals("exchangeName"));
+        Assert.assertTrue(dest.getDestinationName().equals("Destination"));
+        Assert.assertTrue(dest.getQueueName().equals(""));
+    }
+
+    @Test
+    public void destinationWithOption() throws URLSyntaxException
+    {
+
+        String url = "exchangeClass://exchangeName/Destination/?option='value'";
+
+        AMQBindingURL dest = new AMQBindingURL(url);
+
+        Assert.assertTrue(url.equals(dest.toString()));
+
+        Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass"));
+        Assert.assertTrue(dest.getExchangeName().equals("exchangeName"));
+        Assert.assertTrue(dest.getDestinationName().equals("Destination"));
+        Assert.assertTrue(dest.getQueueName().equals(""));
+
+        Assert.assertTrue(dest.getOption("option").equals("value"));
+    }
+
+    @Test
+    public void destinationWithMultiOption() throws URLSyntaxException
+    {
+
+        String url = "exchangeClass://exchangeName/Destination/?option='value',option2='value2'";
+
+        AMQBindingURL dest = new AMQBindingURL(url);
+
+        Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass"));
+        Assert.assertTrue(dest.getExchangeName().equals("exchangeName"));
+        Assert.assertTrue(dest.getDestinationName().equals("Destination"));
+        Assert.assertTrue(dest.getQueueName().equals(""));
+
+        Assert.assertTrue(dest.getOption("option").equals("value"));
+        Assert.assertTrue(dest.getOption("option2").equals("value2"));
+    }
+
+    @Test
+    public void destinationWithNoExchangeDefaultsToDirect() throws URLSyntaxException
+    {
+
+        String url = "IBMPerfQueue1?durable='true'";
+
+        AMQBindingURL dest = new AMQBindingURL(url);
+
+        Assert.assertTrue(dest.getExchangeClass().equals(ExchangeDefaults.DIRECT_EXCHANGE_CLASS));
+        Assert.assertTrue(dest.getExchangeName().equals(ExchangeDefaults.DIRECT_EXCHANGE_NAME));
+        Assert.assertTrue(dest.getDestinationName().equals(""));
+        Assert.assertTrue(dest.getQueueName().equals("IBMPerfQueue1"));
+
+        Assert.assertTrue(dest.getOption("durable").equals("true"));
+    }
+
+    public static junit.framework.Test suite()
+    {
+        return new JUnit4TestAdapter(DestinationURLTest.class);
+    }
+}

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/destinationurl/DestinationURLTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/destinationurl/UnitTests.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/destinationurl/UnitTests.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/destinationurl/UnitTests.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/destinationurl/UnitTests.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,33 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.destinationurl;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.apache.qpid.ack.*;
+import junit.framework.JUnit4TestAdapter;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({DestinationURLTest.class})
+public class UnitTests
+{
+    public static junit.framework.Test suite()
+    {
+        return new JUnit4TestAdapter(org.apache.qpid.destinationurl.UnitTests.class);
+    }
+}

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/destinationurl/UnitTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/log4j.xml
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/log4j.xml?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/log4j.xml (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/log4j.xml Tue Sep 19 15:06:50 2006
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+<!--
+ -
+ - Copyright (c) 2006 The Apache Software Foundation
+ -
+ - Licensed under the Apache License, Version 2.0 (the "License");
+ - you may not use this file except in compliance with the License.
+ - You may obtain a copy of the License at
+ -
+ -    http://www.apache.org/licenses/LICENSE-2.0
+ -
+ - Unless required by applicable law or agreed to in writing, software
+ - distributed under the License is distributed on an "AS IS" BASIS,
+ - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ - See the License for the specific language governing permissions and
+ - limitations under the License.
+ -
+ -->
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+    <appender name="FileAppender" class="org.apache.log4j.FileAppender">
+        <param name="File" value="ams_messaging.log"/>
+        <param name="Append" value="false"/>
+
+        <layout class="org.apache.log4j.PatternLayout">
+            <param name="ConversionPattern" value="%t %-5p %c{2} - %m%n"/>
+        </layout>
+    </appender>
+
+    <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
+
+        <layout class="org.apache.log4j.PatternLayout">
+            <param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
+        </layout>
+    </appender>
+
+    <root>
+        <priority value="debug"/>
+        <appender-ref ref="STDOUT"/>
+        <appender-ref ref="FileAppender"/>
+    </root>
+</log4j:configuration>
\ No newline at end of file

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/log4j.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/FileMessageDispatcher.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/FileMessageDispatcher.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/FileMessageDispatcher.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/FileMessageDispatcher.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,142 @@
+package org.apache.qpid.example.publisher;
+
+import org.apache.log4j.Logger;
+import java.util.Properties;
+import java.io.File;
+
+import org.apache.qpid.example.shared.FileUtils;
+import org.apache.qpid.example.shared.Statics;
+
+import javax.jms.JMSException;
+
+/**
+ * Class that sends message files to the Publisher to distribute
+ * using files as input
+ * Must set system properties for host etc or amend and use config props
+ * Author: Marnie McCormack
+ * Date: 20-Jul-2006
+ * Time: 09:56:56
+ * Copyright JPMorgan Chase 2006
+ */
+public class FileMessageDispatcher {
+
+    private static final Logger _logger = Logger.getLogger(FileMessageDispatcher.class);
+
+    private static Publisher _publisher = null;
+
+    private static final String DEFAULT_PUB_NAME = "Publisher";
+
+    public static void main(String[] args)
+    {
+
+        //Check command line args ok - must provide a path or file for us to run
+        if (args.length == 0)
+        {
+            System.err.println("Usage: FileMessageDispatcher <filesToDispatch>" + "");
+        }
+        else
+        {
+            try
+            {
+                //publish message(s) from file(s) and send message to monitor queue
+                publish(args[0]);
+
+                //Move payload file(s) to archive location as no error
+                FileUtils.moveFileToNewDir(args[0], System.getProperties().getProperty(Statics.ARCHIVE_PATH));
+            }
+            catch(Exception e)
+            {
+                System.err.println("Error trying to dispatch message: " + e);
+                System.exit(1);
+            }
+            finally
+            {
+                //clean up before exiting
+                if (getPublisher() != null)
+                {
+                    getPublisher().cleanup();
+                }
+            }
+        }
+
+        if (_logger.isDebugEnabled())
+        {
+            _logger.debug("Finished dispatching message");
+        }
+
+        System.exit(0);
+    }
+
+
+    //Publish files or file as message
+    public static void publish(String path) throws JMSException, MessageFactoryException
+    {
+        File tempFile = new File(path);
+        if (tempFile.isDirectory())
+        {
+            //while more files in dir publish them
+            File[] files = tempFile.listFiles();
+
+            if (files == null || files.length == 0)
+            {
+                _logger.info("FileMessageDispatcher - No files to publish in input directory: " + tempFile);
+            }
+            else
+            {
+                for (File file : files)
+                {
+                    //Create message factory passing in payload path
+                    MessageFactory factory = new MessageFactory(getPublisher().getSession(), file.toString());
+
+                    //Send the message generated from the payload using the _publisher
+                    getPublisher().sendMessage(factory.createEventMessage());
+
+                }
+            }
+        }
+        else
+        {
+            //handle as single file
+            //Create message factory passing in payload path
+            MessageFactory factory = new MessageFactory(getPublisher().getSession(),tempFile.toString());
+
+            //Send the message generated from the payload using the _publisher
+            getPublisher().sendMessage(factory.createEventMessage());
+        }
+    }
+
+    //cleanup publishers
+    public static void cleanup()
+    {
+        if (getPublisher() != null)
+        {
+            getPublisher().cleanup();
+        }
+    }
+
+    /*
+     * Returns a _publisher for a queue
+     * Using system properties to get connection info for now
+     * Must set using -D the host, client, queue, user, pwd, virtual path, archive path
+     */
+    private static Publisher getPublisher()
+    {
+       if (_publisher != null)
+       {
+           return _publisher;
+       }
+
+       //Create _publisher using system properties
+       Properties props = System.getProperties();
+
+       //Create a _publisher using failover details
+       _publisher = new Publisher(props.getProperty(Statics.HOST_PROPERTY),
+                               props.getProperty(Statics.CLIENT_PROPERTY), props.getProperty(Statics.QUEUE_PROPERTY),
+                               props.getProperty(Statics.USER_PROPERTY), props.getProperty(Statics.PWD_PROPERTY),
+                               props.getProperty(Statics.VIRTUAL_PATH_PROPERTY), props.getProperty(Statics.ARCHIVE_PATH));
+
+       _publisher.setName(DEFAULT_PUB_NAME);
+       return _publisher;
+    }
+
+}

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/FileMessageDispatcher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MessageFactory.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MessageFactory.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MessageFactory.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MessageFactory.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,109 @@
+/**
+ * Class that creates messages from file payload
+ * Author: Marnie McCormack
+ * Date: 18-Jul-2006
+ * Time: 10:48:38
+ * Copyright JPMorgan Chase 2006
+ */
+
+package org.apache.qpid.example.publisher;
+
+import org.apache.qpid.example.shared.FileUtils;
+import org.apache.qpid.example.shared.Statics;
+
+import java.io.*;
+import javax.jms.*;
+
+public class MessageFactory
+{
+    private final Session _session;
+    private final String _payload;
+    private final String _filename;
+
+    public MessageFactory(Session session, String filename) throws MessageFactoryException
+    {
+        try
+        {
+            _filename = filename;
+            _payload = FileUtils.getFileContent(filename);
+            _session = session;
+        }
+        catch (IOException e)
+        {
+            throw new MessageFactoryException(e.toString());
+        }
+    }
+
+    /*
+    * Creates message and sets filename property on it
+    */
+    public Message createEventMessage() throws JMSException
+    {
+        TextMessage msg = _session.createTextMessage();
+        msg.setText(_payload);
+        msg.setStringProperty(Statics.FILENAME_PROPERTY,new File(_filename).getName());
+        return msg;
+    }
+
+    /*
+    * Creates message from a string for use by the monitor
+    */
+    public static Message createSimpleEventMessage(Session session, String textMsg) throws JMSException
+    {
+        TextMessage msg = session.createTextMessage();
+        msg.setText(textMsg);
+        return msg;
+    }
+
+    public Message createShutdownMessage() throws JMSException
+    {
+        return _session.createTextMessage("SHUTDOWN");
+    }
+
+    public Message createReportRequestMessage() throws JMSException
+    {
+        return _session.createTextMessage("REPORT");
+    }
+
+    public Message createReportResponseMessage(String msg) throws JMSException
+    {
+        return _session.createTextMessage(msg);
+    }
+
+    public boolean isShutdown(Message m)
+    {
+        return checkText(m, "SHUTDOWN");
+    }
+
+    public boolean isReport(Message m)
+    {
+        return checkText(m, "REPORT");
+    }
+
+    public Object getReport(Message m)
+    {
+        try
+        {
+            return ((TextMessage) m).getText();
+        }
+        catch (JMSException e)
+        {
+            e.printStackTrace(System.out);
+            return e.toString();
+        }
+    }
+
+    private static boolean checkText(Message m, String s)
+    {
+        try
+        {
+            return m instanceof TextMessage && ((TextMessage) m).getText().equals(s);
+        }
+        catch (JMSException e)
+        {
+            e.printStackTrace(System.out);
+            return false;
+        }
+    }
+}
+

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MessageFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MessageFactoryException.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MessageFactoryException.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MessageFactoryException.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MessageFactoryException.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,60 @@
+package org.apache.qpid.example.publisher;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Author: Marnie McCormack
+ * Date: 18-Jul-2006
+ * Time: 11:13:23
+ * Copyright JPMorgan Chase 2006
+ */
+public class MessageFactoryException extends Exception {
+
+    private int _errorCode;
+
+    public MessageFactoryException(String message)
+    {
+        super(message);
+    }
+
+    public MessageFactoryException(String msg, Throwable t)
+    {
+        super(msg, t);
+    }
+
+    public MessageFactoryException(int errorCode, String msg, Throwable t)
+    {
+        super(msg + " [error code " + errorCode + ']', t);
+        _errorCode = errorCode;
+    }
+
+    public MessageFactoryException(int errorCode, String msg)
+    {
+        super(msg + " [error code " + errorCode + ']');
+        _errorCode = errorCode;
+    }
+
+    public MessageFactoryException(Logger logger, String msg, Throwable t)
+    {
+        this(msg, t);
+        logger.error(getMessage(), this);
+    }
+
+    public MessageFactoryException(Logger logger, String msg)
+    {
+        this(msg);
+        logger.error(getMessage(), this);
+    }
+
+    public MessageFactoryException(Logger logger, int errorCode, String msg)
+    {
+        this(errorCode, msg);
+        logger.error(getMessage(), this);
+    }
+
+    public int getErrorCode()
+    {
+        return _errorCode;
+    }
+}
+

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MessageFactoryException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MonitorMessageDispatcher.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MonitorMessageDispatcher.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MonitorMessageDispatcher.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MonitorMessageDispatcher.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,116 @@
+package org.apache.qpid.example.publisher;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.BasicConfigurator;
+import org.apache.qpid.example.shared.Statics;
+import javax.jms.*;
+import java.util.Properties;
+
+/**
+ * Class that sends heartbeat messages to allow monitoring of message consumption
+ * Sends regular (currently 20 seconds apart) heartbeat message
+ * Author: Marnie McCormack
+ * Date: 20-Jul-2006
+ * Time: 09:56:56
+ * Copyright JPMorgan Chase 2006
+ */
+public class MonitorMessageDispatcher {
+
+    private static final Logger _logger = Logger.getLogger(MonitorMessageDispatcher.class);
+
+    private static MonitorPublisher _monitorPublisher = null;
+
+    private static final String DEFAULT_MONITOR_PUB_NAME = "MonitorPublisher";
+
+    public static void main(String[] args)
+    {
+
+        //@TODO switch on logging appropriately at your app level
+        BasicConfigurator.configure();
+
+        try
+        {
+            while(true)
+            {
+                try
+                {
+                    //endlessly publish messages to monitor queue
+                    publish();
+
+                    if (_logger.isDebugEnabled())
+                    {
+                        _logger.debug("Dispatched monitor message");
+                    }
+
+                    //sleep for twenty seconds and then publish again - change if appropriate
+                    Thread.sleep(20000);
+                }
+                catch(UndeliveredMessageException a)
+                {
+                    //@TODO trigger application specific failure handling here
+                    _logger.error("Problem delivering monitor message");
+                    break;
+                }
+            }
+        }
+        catch(Exception e)
+        {
+
+            System.err.println("Error trying to dispatch AMS monitor message: " + e);
+            System.exit(1);
+        }
+        finally
+        {
+            if (getMonitorPublisher() != null)
+            {
+               getMonitorPublisher().cleanup();
+            }
+        }
+
+        System.exit(1);
+    }
+
+    //Publish heartbeat message
+    public static void publish() throws JMSException, UndeliveredMessageException
+    {
+        //Send the message generated from the payload using the _publisher
+        getMonitorPublisher().sendImmediateMessage
+          (MessageFactory.createSimpleEventMessage(getMonitorPublisher().getSession(),"monitor:" +System.currentTimeMillis()));
+    }
+
+    //cleanup publishers
+    public static void cleanup()
+    {
+        if (getMonitorPublisher() != null)
+        {
+            getMonitorPublisher().cleanup();
+        }
+
+        if (getMonitorPublisher() != null)
+        {
+            getMonitorPublisher().cleanup();
+        }
+    }
+
+    //Returns a _publisher for the monitor queue
+    private static MonitorPublisher getMonitorPublisher()
+    {
+       if (_monitorPublisher != null)
+       {
+           return _monitorPublisher;
+       }
+
+       //Create _publisher using system properties
+       Properties props = System.getProperties();
+
+       //Create a _publisher using failover details and constant for monitor queue
+       _monitorPublisher = new MonitorPublisher(props.getProperty(Statics.HOST_PROPERTY),
+                               props.getProperty(Statics.CLIENT_PROPERTY), Statics.MONITOR_QUEUE,
+                               props.getProperty(Statics.USER_PROPERTY), props.getProperty(Statics.PWD_PROPERTY),
+                               props.getProperty(Statics.VIRTUAL_PATH_PROPERTY), props.getProperty(Statics.ARCHIVE_PATH));
+
+       _monitorPublisher.setName(MonitorMessageDispatcher.DEFAULT_MONITOR_PUB_NAME);
+       return _monitorPublisher;
+    }
+
+}

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MonitorMessageDispatcher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MonitorPublisher.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MonitorPublisher.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MonitorPublisher.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MonitorPublisher.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,64 @@
+package org.apache.qpid.example.publisher;
+
+import javax.jms.Message;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import org.apache.qpid.client.BasicMessageProducer;
+import org.apache.log4j.Logger;
+
+/**
+ * Subclass of Publisher which uses QPID functionality to send a heartbeat message
+ * Note immediate flag not available via JMS MessageProducer
+ * Author: Marnie McCormack
+ * Date: 12-Sep-2006
+ * Time: 09:41:07
+ * Copyright JPMorgan Chase 2006
+ */
+public class MonitorPublisher extends Publisher
+{
+
+    private static final Logger _log = Logger.getLogger(Publisher.class);
+
+    BasicMessageProducer _producer;
+
+    public MonitorPublisher(String host, int port, String clientID, String queueName,
+                            String user, String password, String virtualPath, String destinationDir)
+    {
+        super(host,port,clientID,queueName,user,password,virtualPath,destinationDir);
+    }
+
+    public MonitorPublisher(String hostdetails, String clientID, String queueName,
+                            String user, String password, String virtualPath, String destinationDir)
+    {
+        super(hostdetails,clientID,queueName,user,password,virtualPath,destinationDir);
+    }
+
+     /*
+     * Publishes a non-persistent message using transacted session
+     */
+    public boolean sendImmediateMessage(Message message) throws UndeliveredMessageException
+    {
+        try
+        {
+             _producer = (BasicMessageProducer)_session.createProducer(_destination);
+
+            //Send message via our producer which is not persistent and is immediate
+            //NB: not available via jms interface MessageProducer
+            _producer.send(message, DeliveryMode.NON_PERSISTENT, true);
+
+            //commit the message send and close the transaction
+            _session.commit();
+
+        }
+        catch (JMSException e)
+        {
+            //Have to assume our commit failed but do not rollback here as channel closed
+            _log.error(e);
+            e.printStackTrace();
+            throw new UndeliveredMessageException("Cannot deliver immediate message",e);
+        }
+
+        _log.info(_name + " finished sending message: " + message);
+        return true;
+    }
+}

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/MonitorPublisher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/Publisher.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/Publisher.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/Publisher.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/Publisher.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,213 @@
+/*
+ *   Class that publishes to an AMQ message queue
+ *   Author: Marnie McCormack
+ *
+ */
+package org.apache.qpid.example.publisher;
+
+import org.apache.log4j.Logger;
+
+import org.apache.qpid.client.AMQConnection;
+
+import org.apache.qpid.jms.Session;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.DeliveryMode;
+import javax.jms.Queue;
+import javax.jms.MessageProducer;
+import javax.jms.Connection;
+
+
+import org.apache.qpid.example.shared.ConnectionException;
+import org.apache.qpid.example.shared.Statics;
+
+public class Publisher
+{
+    private static final Logger _log = Logger.getLogger(Publisher.class);
+
+    protected Connection _connection;
+
+    protected Session _session;
+
+    private MessageProducer _producer;
+
+    protected String _destinationDir;
+
+    protected String _name = "Publisher";
+
+    protected Queue _destination;
+
+    //constructor for use with a single host
+    public Publisher(String host, int port, String clientID, String queueName,
+                     String user, String password, String virtualPath, String destinationDir)
+    {
+        try
+        {
+            createConnection(host, port, clientID, user, password, virtualPath);
+
+            //create a transactional session
+            _session = (Session) _connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+
+            //now using a queue rather than a topic
+            //AMQTopic destination = new AMQTopic(topicName);
+            //Queue is non-exclusive and not deleted when last consumer detaches
+            _destination = _session.createQueue(queueName);
+
+            //create a message producer
+            _producer = _session.createProducer(_destination);
+
+            //set destination dir for files that have been processed
+            _destinationDir = destinationDir;
+
+            _connection.start();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            _log.error(e);
+        }
+    }
+
+    //constructor that allows for multiple host details to be provided for failover
+    public Publisher(String hostdetails, String clientID, String queueName,
+                     String user, String password, String virtualPath, String destinationDir)
+    {
+        try
+        {
+            if (queueName==null||queueName.length()==0)
+            {
+                queueName = Statics.QUEUE_NAME;
+            }
+            createConnectionWithFailover(hostdetails, clientID, user, password, virtualPath);
+
+            //create a transactional session
+            _session = (Session) _connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
+
+            //now using a queue rather than a topic
+            //AMQTopic destination = new AMQTopic(topicName);
+            //Queue is non-exclusive and not deleted when last consumer detaches
+            _destination = _session.createQueue(queueName);
+
+            //create a message producer
+            _producer = _session.createProducer(_destination);
+
+            //set destination dir for files that have been processed
+            _destinationDir = destinationDir;
+
+            _connection.start();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            _log.error(e);
+        }
+    }
+
+    /*
+    * Publishes a non-persistent message using transacted session
+    */
+    public boolean sendMessage(Message message)
+    {
+        try
+        {
+            //Send message via our producer which is not persistent
+            _producer.send(message, DeliveryMode.NON_PERSISTENT, _producer.getPriority(), _producer.getTimeToLive());
+
+            //commit the message send and close the transaction
+            _session.commit();
+
+        }
+        catch (JMSException e)
+        {
+            //Have to assume our commit failed and rollback here
+            try
+            {
+                _session.rollback();
+                _log.error(e);
+                e.printStackTrace();
+                return false;
+            }
+            catch (JMSException j)
+            {
+                _log.error("Unable to rollback publish transaction ",e);
+                return false;
+            }
+        }
+
+        _log.info(_name + " finished sending message: " + message);
+        return true;
+    }
+
+    public void cleanup()
+    {
+        try
+        {
+            if (_connection != null)
+            {
+                _connection.stop();
+                _connection.close();
+            }
+            _connection = null;
+            _producer = null;
+        }
+        catch(Exception e)
+        {
+            System.err.println("Error trying to cleanup publisher " + e);
+            System.exit(1);
+        }
+    }
+
+    public Session getSession()
+    {
+        return _session;
+    }
+
+    public String getDestinationDir()
+    {
+        return _destinationDir;
+    }
+
+    public void setDestinationDir(String destinationDir)
+    {
+        _destinationDir = destinationDir;
+    }
+
+    //ONly using one set of host details
+    private void createConnection(String host, int port, String clientID, String user, String password, String virtualPath)
+                                   throws ConnectionException
+    {
+        try
+        {
+            _connection = new AMQConnection(host, port, user, password, clientID, virtualPath);
+        }
+        catch (Exception e)
+        {
+            throw new ConnectionException(e.toString());
+        }
+    }
+
+    //Create connection with more than one set of host details for failover
+    private void createConnectionWithFailover(String hostdetails, String clientID, String user, String password, String virtualPath)
+                                   throws ConnectionException
+    {
+        try
+        {
+            _connection = new AMQConnection(hostdetails, user, password, clientID, virtualPath);
+        }
+        catch (Exception e)
+        {
+            throw new ConnectionException(e.toString());
+        }
+    }
+
+    public String getName()
+    {
+        return _name;
+    }
+
+    public void setName(String _name) {
+        this._name = _name;
+    }
+}
+

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/Publisher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/UndeliveredMessageException.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/UndeliveredMessageException.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/UndeliveredMessageException.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/UndeliveredMessageException.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,60 @@
+package org.apache.qpid.example.publisher;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Exception thrown by monitor when cannot send a message marked for immediate delivery
+ * Author: Marnie McCormack
+ * Date: 18-Jul-2006
+ * Time: 11:13:23
+ * Copyright JPMorgan Chase 2006
+ */
+public class UndeliveredMessageException extends Exception {
+
+    private int _errorCode;
+
+    public UndeliveredMessageException(String message)
+    {
+        super(message);
+    }
+
+    public UndeliveredMessageException(String msg, Throwable t)
+    {
+        super(msg, t);
+    }
+
+    public UndeliveredMessageException(int errorCode, String msg, Throwable t)
+    {
+        super(msg + " [error code " + errorCode + ']', t);
+        _errorCode = errorCode;
+    }
+
+    public UndeliveredMessageException(int errorCode, String msg)
+    {
+        super(msg + " [error code " + errorCode + ']');
+        _errorCode = errorCode;
+    }
+
+    public UndeliveredMessageException(Logger logger, String msg, Throwable t)
+    {
+        this(msg, t);
+        logger.error(getMessage(), this);
+    }
+
+    public UndeliveredMessageException(Logger logger, String msg)
+    {
+        this(msg);
+        logger.error(getMessage(), this);
+    }
+
+    public UndeliveredMessageException(Logger logger, int errorCode, String msg)
+    {
+        this(errorCode, msg);
+        logger.error(getMessage(), this);
+    }
+
+    public int getErrorCode()
+    {
+        return _errorCode;
+    }
+}

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/publisher/UndeliveredMessageException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/shared/ConnectionException.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/shared/ConnectionException.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/shared/ConnectionException.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/shared/ConnectionException.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,59 @@
+package org.apache.qpid.example.shared;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Author: Marnie McCormack
+ * Date: 18-Jul-2006
+ * Time: 11:13:23
+ * Copyright JPMorgan Chase 2006
+ */
+public class ConnectionException extends Exception {
+
+    private int _errorCode;
+
+    public ConnectionException(String message)
+    {
+        super(message);
+    }
+
+    public ConnectionException(String msg, Throwable t)
+    {
+        super(msg, t);
+    }
+
+    public ConnectionException(int errorCode, String msg, Throwable t)
+    {
+        super(msg + " [error code " + errorCode + ']', t);
+        _errorCode = errorCode;
+    }
+
+    public ConnectionException(int errorCode, String msg)
+    {
+        super(msg + " [error code " + errorCode + ']');
+        _errorCode = errorCode;
+    }
+
+    public ConnectionException(Logger logger, String msg, Throwable t)
+    {
+        this(msg, t);
+        logger.error(getMessage(), this);
+    }
+
+    public ConnectionException(Logger logger, String msg)
+    {
+        this(msg);
+        logger.error(getMessage(), this);
+    }
+
+    public ConnectionException(Logger logger, int errorCode, String msg)
+    {
+        this(errorCode, msg);
+        logger.error(getMessage(), this);
+    }
+
+    public int getErrorCode()
+    {
+        return _errorCode;
+    }
+}

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/shared/ConnectionException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/shared/FileUtils.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/shared/FileUtils.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/shared/FileUtils.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/shared/FileUtils.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,154 @@
+package org.apache.qpid.example.shared;
+
+import java.io.*;
+
+/**
+ * Class that provides file related utility methods for utility use
+ * Author: Marnie McCormack
+ * Date: 20-Jul-2006
+ * Time: 08:17:16
+ * Copyright JPMorgan Chase 2006
+ */
+public class FileUtils {
+
+
+    //Reads file content into String
+    public static String getFileContent(String filePath) throws IOException
+    {
+
+        BufferedReader reader = null;
+        String tempData = "";
+        String eol = "\n\r";
+
+        try
+        {
+            String line;
+            reader = new BufferedReader(new FileReader(filePath));
+            while ((line = reader.readLine()) != null)
+            {
+                if (!tempData.equals(""))
+                {
+                    tempData = tempData + eol + line;
+                }
+                else
+                {
+                    tempData = line;
+                }
+            }
+        }
+        finally
+        {
+            if (reader != null)
+            {
+                reader.close();
+            }
+        }
+        return tempData;
+    }
+
+     /*
+     * Reads xml from a file and returns it as an array of chars
+     */
+    public static char[] getFileAsCharArray(String filePath) throws IOException
+    {
+        BufferedReader reader = null;
+        char[] tempChars = null;
+        String tempData = "";
+
+        try
+        {
+            String line;
+            reader = new BufferedReader(new FileReader(filePath));
+            while ((line = reader.readLine()) != null)
+            {
+                tempData = tempData + line;
+            }
+            tempChars = tempData.toCharArray();
+        }
+        finally
+        {
+            if (reader != null)
+            {
+                reader.close();
+            }
+        }
+        return tempChars;
+    }
+
+    /*
+    * Write String content to filename provided
+    */
+    public static void writeStringToFile(String content, String path) throws IOException
+    {
+
+        BufferedWriter writer = new BufferedWriter(new FileWriter(new File(path)));
+        writer.write(content);
+        writer.flush();
+        writer.close();
+    }
+
+    /*
+    * Allows moving of files to a new dir and preserves the last bit of the name only
+    */
+    public static void moveFileToNewDir(String path, String newDir) throws IOException
+    {
+        //get file name from current path
+        //while more files in dir publish them
+        File pathFile = new File(path);
+        if (pathFile.isDirectory())
+        {
+            File[] files = pathFile.listFiles();
+            for (File file : files)
+            {
+                moveFileToNewDir(file,newDir);
+            }
+        }
+    }
+
+    /*
+    * Allows moving of a file to a new dir and preserves the last bit of the name only
+    */
+    public static void moveFileToNewDir(File fileToMove, String newDir) throws IOException
+    {
+        moveFile(fileToMove,getArchiveFileName(fileToMove,newDir));
+    }
+
+    /*
+    * Moves file from a given path to a new path with String params
+    */
+    public static void moveFile(String fromPath, String dest) throws IOException
+    {
+        moveFile(new File(fromPath),new File(dest));
+    }
+
+    /*
+    * Moves file from a given path to a new path with mixed params
+    */
+    public static void moveFile(File fileToMove, String dest) throws IOException
+    {
+        moveFile(fileToMove,new File(dest));
+    }
+
+    /*
+    * Moves file from a given path to a new path with File params
+    */
+    public static void moveFile(File fileToMove, File dest) throws IOException
+    {
+        fileToMove.renameTo(dest);
+    }
+
+    /*
+    * Deletes a given file
+    */
+    public static void deleteFile(String filePath) throws IOException
+    {
+        new File(filePath).delete();
+    }
+
+    private static String getArchiveFileName(File fileToMove, String archiveDir)
+    {
+         //get file name from current path
+        String fileName = fileToMove.getName();
+        return archiveDir + File.separator + fileName;
+    }
+}

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/shared/FileUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/shared/Statics.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/shared/Statics.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/shared/Statics.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/shared/Statics.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,42 @@
+package org.apache.qpid.example.shared;
+
+/**
+ * Constants used by AMS Publisher/Subscriber classes
+ * Author: Marnie McCormack
+ * Date: 18-Jul-2006
+ * Time: 09:19:33
+ */
+public class Statics {
+
+    public static final String TOPIC_NAME = "EXAMPLE_TOPIC";
+
+    public static final String QUEUE_NAME = "EXAMPLE_QUEUE";
+
+    public static final String MONITOR_QUEUE = "MONITOR_QUEUE";
+
+    public static final String HOST_PROPERTY = "host";
+
+    public static final String PORT_PROPERTY = "port";
+
+    public static final String USER_PROPERTY = "user";
+
+    public static final String PWD_PROPERTY = "pwd";
+
+    public static final String TOPIC_PROPERTY = "topic";
+
+    public static final String QUEUE_PROPERTY = "queue";
+
+    public static final String VIRTUAL_PATH_PROPERTY = "virtualpath";
+
+    public static final String ARCHIVE_PATH = "archivepath";
+
+    public static final String CLIENT_PROPERTY = "client";
+
+    public static final String FILENAME_PROPERTY = "filename";
+
+    public static final String DEFAULT_USER = "guest";
+
+    public static final String DEFAULT_PWD = "guest";
+
+
+}

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/shared/Statics.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/MonitoredSubscriber.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/MonitoredSubscriber.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/MonitoredSubscriber.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/MonitoredSubscriber.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,120 @@
+package org.apache.qpid.example.subscriber;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.example.shared.Statics;
+
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.JMSException;
+import javax.jms.Queue;
+
+/**
+ * Subclass of Subscriber which consumes a heartbeat message
+ * Author: Marnie McCormack
+ * Date: 12-Sep-2006
+ * Time: 09:41:07
+ * Copyright JPMorgan Chase 2006
+ */
+
+public class MonitoredSubscriber extends Subscriber
+{
+    private static final Logger _logger = Logger.getLogger(MonitoredSubscriber.class);
+
+    private static MessageConsumer _monitorConsumer;
+
+    public static class MonitorMessageListener implements MessageListener
+    {
+        private String _name;
+
+        public MonitorMessageListener(String name)
+        {
+            _name = name;
+
+        }
+
+        /*
+        * Listens for heartbeat messages and acknowledges them
+        */
+        public void onMessage(javax.jms.Message message)
+        {
+            _logger.info(_name + " monitor got message '" + message + "'");
+
+            try
+            {
+               _logger.debug("Monitor acknowledging recieved message");
+
+                //Now acknowledge the message to clear it from our queue
+                message.acknowledge();
+            }
+            catch(JMSException j)
+            {
+                _logger.error("Monitor caught JMSException trying to acknowledge message receipt");
+                j.printStackTrace();
+            }
+            catch(Exception e)
+            {
+                _logger.error("Monitor caught unexpected exception trying to handle message");
+                e.printStackTrace();
+            }
+        }
+    }
+
+    /*
+    * Subscribes to Queue and attaches additional monitor listener
+    * @param hostdetails - for broker connection in host1:port1;host2:port2 format
+    * @param username - for connection to the broker
+    * @password - for connection to the broker
+    * @virtualpath
+    */
+    public void subscribeAndMonitor(String hostdetails, String username, String password,
+                                      String virtualPath, String queueName)
+    {
+        Queue queue;
+
+        try
+        {
+            //Create monitor comsumer for failover purposes
+            if (queueName==null||queueName.length()==0)
+            {
+                queue = getSession(_connection).createQueue(Statics.QUEUE_NAME);
+            }
+            else
+            {
+                queue = getSession(_connection).createQueue(queueName);
+            }
+
+            _monitorConsumer = getSession(_connection).createConsumer(queue);
+
+            //give the monitor message listener a name of it's own
+            _monitorConsumer.setMessageListener(new MonitoredSubscriber.MonitorMessageListener("MonitorListener " + System.currentTimeMillis()));
+
+            MonitoredSubscriber._logger.info("Starting monitored subscription ...");
+
+            MonitoredSubscriber._connection.start();
+
+            //and now start ordinary consumption too
+            subscribe(hostdetails,username,password,virtualPath,queueName);
+        }
+        catch (Throwable t)
+        {
+            _logger.error("Fatal error: " + t);
+            t.printStackTrace();
+        }
+    }
+
+    //stop consuming
+    public void stopMonitor()
+    {
+        try
+        {
+            _monitorConsumer.close();
+            _monitorConsumer = null;
+            stop();
+        }
+        catch(JMSException j)
+        {
+            _logger.error("JMSException trying to Subscriber.stop: " + j.getStackTrace());
+        }
+    }
+
+}

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/MonitoredSubscriber.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/MonitoredSubscriptionWrapper.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/MonitoredSubscriptionWrapper.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/MonitoredSubscriptionWrapper.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/MonitoredSubscriptionWrapper.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,41 @@
+package org.apache.qpid.example.subscriber;
+
+import org.apache.log4j.BasicConfigurator;
+import org.apache.qpid.example.shared.Statics;
+
+import java.util.Properties;
+
+/**
+ * Allows you to simply start a monitored subscriber
+ * Author: Marnie McCormack
+ * Date: 08-Aug-2006
+ * Time: 12:05:52
+ * Copyright JPMorgan Chase 2006
+ */
+public class MonitoredSubscriptionWrapper {
+
+    private static MonitoredSubscriber _subscriber;
+
+    public static void main(String args[])
+    {
+        //switch on logging
+        BasicConfigurator.configure();
+
+        _subscriber = new MonitoredSubscriber();
+
+        //using system props but can replace with app appropriate config here
+        Properties props = System.getProperties();
+
+        //note that for failover should set -Dhost=host1:port1;host2:port2
+        //Client will then failover in order i.e. connect to first host and failover to second and so on
+        _subscriber.subscribe(props.getProperty(Statics.HOST_PROPERTY),
+                                props.getProperty(Statics.USER_PROPERTY), props.getProperty(Statics.PWD_PROPERTY),
+                                props.getProperty(Statics.VIRTUAL_PATH_PROPERTY), props.getProperty(Statics.QUEUE_NAME));
+    }
+
+    //Stop subscribing now ...
+    public static void stop()
+    {
+        _subscriber.stop();
+    }
+}

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/MonitoredSubscriptionWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/Subscriber.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/Subscriber.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/Subscriber.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/Subscriber.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,210 @@
+package org.apache.qpid.example.subscriber;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.client.AMQConnection;
+
+import javax.jms.*;
+
+import org.apache.qpid.example.shared.Statics;
+import org.apache.qpid.example.shared.ConnectionException;
+
+import java.net.InetAddress;
+
+/**
+ * Subscriber which consumes messages from a queue
+ * Author: Marnie McCormack
+ * Date: 12-Sep-2006
+ * Time: 09:41:07
+ * Copyright JPMorgan Chase 2006
+ */
+
+public class Subscriber
+{
+    private static final Logger _logger = Logger.getLogger(Subscriber.class);
+
+    protected static Connection _connection;
+
+    protected static MessageConsumer _consumer;
+
+    protected static Session _session;
+
+
+
+    /*
+    * Listener class that handles messages
+    */
+    public static class AMSMessageListener implements MessageListener
+    {
+        private String _name;
+
+        public AMSMessageListener(String name)
+        {
+            _name = name;
+
+        }
+
+        /*
+        * Listens for message callbacks, handles and then acknowledges them
+        * @param message - the message received
+        */
+        public void onMessage(javax.jms.Message message)
+        {
+            _logger.info(_name + " got message '" + message + "'");
+
+            try
+            {
+                //@TODO handle your message appropriately for your application here ?
+
+                _logger.debug("Acknowledging recieved message");
+
+                //Now acknowledge the message to clear it from our queue
+                message.acknowledge();
+            }
+            catch(JMSException j)
+            {
+                _logger.error("JMSException trying to acknowledge message receipt");
+                j.printStackTrace();
+            }
+            catch(Exception e)
+            {
+                _logger.error("Unexpected exception trying to handle message");
+                e.printStackTrace();
+            }
+        }
+    }
+
+    /*
+    * Subscribes to AMS Queue and attaches listener
+    * @param hostdetails - for broker connection in host1:port1;host2:port2 format
+    * @param username - for connection to the broker
+    * @password - for connection to the broker
+    * @virtualpath
+    */
+    public void subscribe(String hostdetails, String username, String password,
+                          String virtualPath, String queue)
+    {
+        Queue q;
+
+        _logger.info("Starting subscription ...");
+
+
+        try
+        {
+            //To enable failover simply specify more than one host:port combination for hostdetails
+            //Format is host1:port1;host2:port2
+            _connection = getConnectionWithFailover(hostdetails,username,password,virtualPath);
+
+            //Default to a queue with a default name if queue is null - replace with your own name from config etc
+            if (queue==null || queue.length()==0)
+            {
+                q = getSession(_connection).createQueue(Statics.QUEUE_NAME);
+            }
+            else
+            {
+                q = getSession(_connection).createQueue(queue);
+            }
+
+            //Create a consumer with a destination of our queue which will use defaults for prefetch etc
+            _consumer = getSession(_connection).createConsumer(q);
+
+            //give the message listener a name of it's own
+            _consumer.setMessageListener(new AMSMessageListener("MessageListener " + System.currentTimeMillis()));
+
+            _connection.start();
+        }
+        catch (Throwable t)
+        {
+            _logger.error("Fatal error: " + t);
+            t.printStackTrace();
+        }
+
+        _logger.info("Waiting for messages ...");
+
+        //wait for messages and sleep to survive failover
+        try
+        {
+            while(true)
+            {
+                Thread.sleep(Long.MAX_VALUE);
+            }
+        }
+        catch (Exception e)
+        {
+            _logger.warn("Exception while Subscriber sleeping",e);
+        }
+    }
+
+    /*
+    * stop consuming and close connection
+    */
+    public void stop()
+    {
+        try
+        {
+            _consumer.close();
+            _consumer = null;
+            _connection.stop();
+            _connection.close();
+        }
+        catch(JMSException j)
+        {
+            _logger.error("JMSException trying to Subscriber.stop: " + j.getStackTrace());
+        }
+    }
+
+    /*
+    * Get a connection for our broker with failover by providing an array of hostdetails
+    * @param hostdetails - a delimited string of host1:port1;host2:port2 style connection details
+    * @param username - for connection to the broker
+    * @password - for connection to the broker
+    * @virtualpath
+    */
+    protected Connection getConnectionWithFailover(String hostdetails, String username, String password,
+                                                   String virtualPath) throws ConnectionException
+    {
+        if (_connection == null)
+        {
+            try
+            {
+                _connection = new AMQConnection(hostdetails,username,password,InetAddress.getLocalHost().getHostName(),virtualPath);
+
+                //To use a url to get your connection create a string in this format and then get a connection with it
+                //String myurl = "amqp://guest:guest@/temp?brokerlist='tcp://localhost:5672',failover='roundrobin'";
+                //_connection =  new AMQConnectionFactory(url).createConnection();
+
+                return _connection;
+            }
+            catch (Exception e)
+            {
+                throw new ConnectionException(e.toString());
+            }
+        }
+        else
+        {
+            return _connection;
+        }
+    }
+
+    /*
+    * Creates a non-transacted session for consuming messages
+    * Using client acknowledge mode means messages removed from queue only once ack'd
+    * @param connection - to the broker
+    */
+    protected Session getSession(Connection connection) throws JMSException
+    {
+        if (_session == null)
+        {
+            _session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+            return _session;
+        }
+        else
+        {
+            return _session;
+        }
+    }
+
+}
+
+
+
+

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/Subscriber.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/SubscriptionWrapper.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/SubscriptionWrapper.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/SubscriptionWrapper.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/SubscriptionWrapper.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,42 @@
+package org.apache.qpid.example.subscriber;
+
+import org.apache.qpid.example.shared.Statics;
+
+import java.util.Properties;
+
+import org.apache.log4j.BasicConfigurator;
+
+/**
+ * Allows you to simply start a subscriber
+ * Author: Marnie McCormack
+ * Date: 08-Aug-2006
+ * Time: 12:05:52
+ * Copyright JPMorgan Chase 2006
+ */
+public class SubscriptionWrapper {
+
+    private static Subscriber _subscriber;
+
+    public static void main(String args[])
+    {
+        //switch on logging
+        BasicConfigurator.configure();
+        
+         _subscriber = new Subscriber();
+
+        //using system props but can replace with app appropriate config here
+        Properties props = System.getProperties();
+
+        //note that for failover should set -Dhost=host1:port1;host2:port2
+        //Client will then failover in order i.e. connect to first host and failover to second and so on
+        _subscriber.subscribe(props.getProperty(Statics.HOST_PROPERTY),
+                                props.getProperty(Statics.USER_PROPERTY), props.getProperty(Statics.PWD_PROPERTY),
+                                props.getProperty(Statics.VIRTUAL_PATH_PROPERTY), props.getProperty(Statics.QUEUE_PROPERTY));
+    }
+
+    //Stop subscribing now ...
+    public static void stop()
+    {
+        _subscriber.stop();
+    }
+}

Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/example/subscriber/SubscriptionWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native