From ca6eff1607964380e140c8b3e5fc0ffaede42f0c Mon Sep 17 00:00:00 2001 From: Arnaud Simon Date: Wed, 5 Dec 2007 16:14:54 +0000 Subject: moved base example into the common package git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@601388 13f79535-47bb-0310-9956-ffa450edef68 --- .../qpid/example/jmsexample/BaseExample.java | 184 --------------------- .../example/jmsexample/common/BaseExample.java | 184 +++++++++++++++++++++ .../qpid/example/jmsexample/direct/Consumer.java | 2 +- .../qpid/example/jmsexample/direct/Listener.java | 2 +- .../qpid/example/jmsexample/direct/Producer.java | 2 +- .../qpid/example/jmsexample/pubsub/Listener.java | 2 +- .../qpid/example/jmsexample/pubsub/Publisher.java | 2 +- .../jmsexample/requestResponse/MessageMirror.java | 2 +- .../jmsexample/requestResponse/P2PRequestor.java | 2 +- .../requestResponse/PubSubRequestor.java | 2 +- .../jmsexample/transacted/QueueToTopic.java | 2 +- 11 files changed, 193 insertions(+), 193 deletions(-) delete mode 100644 java/client/example/src/main/java/org/apache/qpid/example/jmsexample/BaseExample.java create mode 100644 java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java (limited to 'java') diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/BaseExample.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/BaseExample.java deleted file mode 100644 index ff67cbf303..0000000000 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/BaseExample.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.example.jmsexample; - -import javax.jms.*; -import javax.naming.Context; -import javax.naming.InitialContext; -import java.util.Hashtable; -import java.util.Properties; - -import org.apache.qpid.example.jmsexample.common.ArgProcessor; - -/** - * Abstract base class for providing common argument parsing features. - *

- *

Classes that extend BaseExample support the following command-line arguments:

- * - * - * - * - *
-factoryName ConnectionFactory name
-delMode Delivery mode [persistent | non-persistent]
-numMessages Number of messages to process
- */ - -abstract public class BaseExample -{ - /* The AMQP INITIAL_CONTEXT_FACTORY */ - private static final String INITIAL_CONTEXT_FACTORY_NAME = - "org.apache.qpid.jndi.PropertiesFileInitialContextFactory"; - - /* Default connection factory name. */ - private static final String DEFAULT_CONNECTION_FACTORY_NAME = "ConnectionFactory"; - - /* Default number of messages to process. */ - private static final int DEFAULT_NUMBER_MESSAGES = 1; - - /* JNDI provider URL. */ - private String _providerURL; - - /* Number of messages to process. */ - private int _numberMessages; - - /* The delivery Mode */ - private int _deliveryMode; - - /* The argument processor */ - protected ArgProcessor _argProcessor; - - /* The supported properties */ - protected static Properties _options = new Properties(); - - /* The properties default values */ - protected static Properties _defaults = new Properties(); - - /* The broker communication objects */ - private InitialContext _initialContext; - private ConnectionFactory _connectionFactory; - - /** - * Protected constructor to create a example client. - * - * @param Id Identity string used in log messages, for example, the name of the example program. - * @param args String array of arguments. - */ - protected BaseExample(String Id, String[] args) - { - _options.put("-factoryName", "ConnectionFactory name"); - _defaults.put("-factoryName", DEFAULT_CONNECTION_FACTORY_NAME); - _options.put("-providerURL", "JNDI Provider URL"); - _options.put("-deliveryMode", "Delivery mode [persistent | non-persistent]"); - _defaults.put("-deliveryMode", "non-persistent"); - _options.put("-numMessages", "Number of messages to process"); - _defaults.put("-numMessages", String.valueOf(DEFAULT_NUMBER_MESSAGES)); - - _argProcessor = new ArgProcessor(Id, args, _options, _defaults); - _argProcessor.display(); - //Set the initial context factory - _providerURL = _argProcessor.getStringArgument("-providerURL"); - // Set the number of messages - _numberMessages = _argProcessor.getIntegerArgument("-numMessages"); - // Set the delivery mode - _deliveryMode = _argProcessor.getStringArgument("-deliveryMode") - .equals("persistent") ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; - } - - /** - * Get the DeliveryMode to use when publishing messages. - * - * @return The delivery mode, either javax.jms.DeliveryMode.NON_PERSISTENT - * or javax.jms.DeliveryMode.PERSISTENT. - */ - protected int getDeliveryMode() - { - return _deliveryMode; - } - - /** - * Get the number of messages to be used. - * - * @return the number of messages to be used. - */ - protected int getNumberMessages() - { - return _numberMessages; - } - - - /** - * Get the JNDI provider URL. - * - * @return the JNDI provider URL. - */ - private String getProviderURL() - { - return _providerURL; - } - - /** - * we assume that the environment is correctly set - * i.e. -Djava.naming.provider.url="..//example.properties" - * - * @return An initial context - * @throws Exception if there is an error getting the context - */ - public InitialContext getInitialContext() throws Exception - { - if (_initialContext == null) - { - Hashtable jndiEnvironment = new Hashtable(); - jndiEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY_NAME); - jndiEnvironment.put("connectionfactory.ConnectionFactory", - "qpid:password=guest;username=guest;client_id=clientid;virtualhost=test@tcp:127.0.0.1:5672"); - if (getProviderURL() != null) - { - jndiEnvironment.put(Context.PROVIDER_URL, getProviderURL()); - } - _initialContext = new InitialContext(jndiEnvironment); - } - return _initialContext; - } - - /** - * Get a connection factory for the currently used broker - * - * @return A conection factory - * @throws Exception if there is an error getting the tactory - */ - public ConnectionFactory getConnectionFactory() throws Exception - { - if (_connectionFactory == null) - { - _connectionFactory = (ConnectionFactory) getInitialContext().lookup(DEFAULT_CONNECTION_FACTORY_NAME); - } - return _connectionFactory; - } - - /** - * Get a connection (remote or in-VM) - * - * @return a newly created connection - * @throws Exception if there is an error getting the connection - */ - public Connection getConnection() throws Exception - { - return getConnectionFactory().createConnection("guest", "guest"); - } -} diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java new file mode 100644 index 0000000000..1eb207ada5 --- /dev/null +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java @@ -0,0 +1,184 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.example.jmsexample.common; + +import javax.jms.*; +import javax.naming.Context; +import javax.naming.InitialContext; +import java.util.Hashtable; +import java.util.Properties; + +import org.apache.qpid.example.jmsexample.common.ArgProcessor; + +/** + * Abstract base class for providing common argument parsing features. + *

+ *

Classes that extend BaseExample support the following command-line arguments:

+ * + * + * + * + *
-factoryName ConnectionFactory name
-delMode Delivery mode [persistent | non-persistent]
-numMessages Number of messages to process
+ */ + +abstract public class BaseExample +{ + /* The AMQP INITIAL_CONTEXT_FACTORY */ + private static final String INITIAL_CONTEXT_FACTORY_NAME = + "org.apache.qpid.jndi.PropertiesFileInitialContextFactory"; + + /* Default connection factory name. */ + private static final String DEFAULT_CONNECTION_FACTORY_NAME = "ConnectionFactory"; + + /* Default number of messages to process. */ + private static final int DEFAULT_NUMBER_MESSAGES = 1; + + /* JNDI provider URL. */ + private String _providerURL; + + /* Number of messages to process. */ + private int _numberMessages; + + /* The delivery Mode */ + private int _deliveryMode; + + /* The argument processor */ + protected ArgProcessor _argProcessor; + + /* The supported properties */ + protected static Properties _options = new Properties(); + + /* The properties default values */ + protected static Properties _defaults = new Properties(); + + /* The broker communication objects */ + private InitialContext _initialContext; + private ConnectionFactory _connectionFactory; + + /** + * Protected constructor to create a example client. + * + * @param Id Identity string used in log messages, for example, the name of the example program. + * @param args String array of arguments. + */ + protected BaseExample(String Id, String[] args) + { + _options.put("-factoryName", "ConnectionFactory name"); + _defaults.put("-factoryName", DEFAULT_CONNECTION_FACTORY_NAME); + _options.put("-providerURL", "JNDI Provider URL"); + _options.put("-deliveryMode", "Delivery mode [persistent | non-persistent]"); + _defaults.put("-deliveryMode", "non-persistent"); + _options.put("-numMessages", "Number of messages to process"); + _defaults.put("-numMessages", String.valueOf(DEFAULT_NUMBER_MESSAGES)); + + _argProcessor = new ArgProcessor(Id, args, _options, _defaults); + _argProcessor.display(); + //Set the initial context factory + _providerURL = _argProcessor.getStringArgument("-providerURL"); + // Set the number of messages + _numberMessages = _argProcessor.getIntegerArgument("-numMessages"); + // Set the delivery mode + _deliveryMode = _argProcessor.getStringArgument("-deliveryMode") + .equals("persistent") ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; + } + + /** + * Get the DeliveryMode to use when publishing messages. + * + * @return The delivery mode, either javax.jms.DeliveryMode.NON_PERSISTENT + * or javax.jms.DeliveryMode.PERSISTENT. + */ + protected int getDeliveryMode() + { + return _deliveryMode; + } + + /** + * Get the number of messages to be used. + * + * @return the number of messages to be used. + */ + protected int getNumberMessages() + { + return _numberMessages; + } + + + /** + * Get the JNDI provider URL. + * + * @return the JNDI provider URL. + */ + private String getProviderURL() + { + return _providerURL; + } + + /** + * we assume that the environment is correctly set + * i.e. -Djava.naming.provider.url="..//example.properties" + * + * @return An initial context + * @throws Exception if there is an error getting the context + */ + public InitialContext getInitialContext() throws Exception + { + if (_initialContext == null) + { + Hashtable jndiEnvironment = new Hashtable(); + jndiEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY_NAME); + jndiEnvironment.put("connectionfactory.ConnectionFactory", + "qpid:password=guest;username=guest;client_id=clientid;virtualhost=test@tcp:127.0.0.1:5672"); + if (getProviderURL() != null) + { + jndiEnvironment.put(Context.PROVIDER_URL, getProviderURL()); + } + _initialContext = new InitialContext(jndiEnvironment); + } + return _initialContext; + } + + /** + * Get a connection factory for the currently used broker + * + * @return A conection factory + * @throws Exception if there is an error getting the tactory + */ + public ConnectionFactory getConnectionFactory() throws Exception + { + if (_connectionFactory == null) + { + _connectionFactory = (ConnectionFactory) getInitialContext().lookup(DEFAULT_CONNECTION_FACTORY_NAME); + } + return _connectionFactory; + } + + /** + * Get a connection (remote or in-VM) + * + * @return a newly created connection + * @throws Exception if there is an error getting the connection + */ + public Connection getConnection() throws Exception + { + return getConnectionFactory().createConnection("guest", "guest"); + } +} diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Consumer.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Consumer.java index be1ae972c4..9512ac07e1 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Consumer.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Consumer.java @@ -20,7 +20,7 @@ */ package org.apache.qpid.example.jmsexample.direct; -import org.apache.qpid.example.jmsexample.BaseExample; +import org.apache.qpid.example.jmsexample.common.BaseExample; import javax.jms.*; diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Listener.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Listener.java index 16a4174479..02694a477b 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Listener.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Listener.java @@ -20,7 +20,7 @@ */ package org.apache.qpid.example.jmsexample.direct; -import org.apache.qpid.example.jmsexample.BaseExample; +import org.apache.qpid.example.jmsexample.common.BaseExample; import javax.jms.*; diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java index 2304cd186c..5178051613 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java @@ -20,7 +20,7 @@ */ package org.apache.qpid.example.jmsexample.direct; -import org.apache.qpid.example.jmsexample.BaseExample; +import org.apache.qpid.example.jmsexample.common.BaseExample; import javax.jms.*; diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Listener.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Listener.java index 2cf04833cb..2e9835eadf 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Listener.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Listener.java @@ -17,7 +17,7 @@ */ package org.apache.qpid.example.jmsexample.pubsub; -import org.apache.qpid.example.jmsexample.BaseExample; +import org.apache.qpid.example.jmsexample.common.BaseExample; import javax.jms.*; diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Publisher.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Publisher.java index 27252983e5..ba81f5c41d 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Publisher.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/pubsub/Publisher.java @@ -20,7 +20,7 @@ */ package org.apache.qpid.example.jmsexample.pubsub; -import org.apache.qpid.example.jmsexample.BaseExample; +import org.apache.qpid.example.jmsexample.common.BaseExample; import javax.jms.*; diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java index be0fe95e90..749556c090 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java @@ -20,7 +20,7 @@ */ package org.apache.qpid.example.jmsexample.requestResponse; -import org.apache.qpid.example.jmsexample.BaseExample; +import org.apache.qpid.example.jmsexample.common.BaseExample; import javax.jms.*; diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java index 430b4e779e..aef21d2ea3 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java @@ -20,7 +20,7 @@ */ package org.apache.qpid.example.jmsexample.requestResponse; -import org.apache.qpid.example.jmsexample.BaseExample; +import org.apache.qpid.example.jmsexample.common.BaseExample; import javax.jms.*; diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/PubSubRequestor.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/PubSubRequestor.java index 0a82074f7a..0bc7ab61f5 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/PubSubRequestor.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/PubSubRequestor.java @@ -20,7 +20,7 @@ */ package org.apache.qpid.example.jmsexample.requestResponse; -import org.apache.qpid.example.jmsexample.BaseExample; +import org.apache.qpid.example.jmsexample.common.BaseExample; import javax.jms.*; diff --git a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/transacted/QueueToTopic.java b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/transacted/QueueToTopic.java index 20961e40ea..7b52127313 100644 --- a/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/transacted/QueueToTopic.java +++ b/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/transacted/QueueToTopic.java @@ -20,7 +20,7 @@ */ package org.apache.qpid.example.jmsexample.transacted; -import org.apache.qpid.example.jmsexample.BaseExample; +import org.apache.qpid.example.jmsexample.common.BaseExample; import javax.jms.*; -- cgit v1.2.1