001 /**
002 *
003 * Copyright 2004 Protique Ltd
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 **/
018 package org.activemq.benchmark;
019
020
021 /**
022 * @author James Strachan
023 * @version $Revision$
024 */
025 public class ProducerConsumer extends Producer {
026
027 private Consumer consumer = new Consumer();
028
029 public static void main(String[] args) {
030 ProducerConsumer tool = new ProducerConsumer();
031 if (args.length > 0) {
032 tool.setUrl(args[0]);
033 }
034 if (args.length > 1) {
035 tool.setTopic(parseBoolean(args[1]));
036 }
037 if (args.length > 2) {
038 tool.setSubject(args[2]);
039 }
040 if (args.length > 3) {
041 tool.setDurable(Boolean.getBoolean(args[3]));
042 }
043 if (args.length > 4) {
044 tool.setConnectionCount(Integer.parseInt(args[4]));
045 }
046 try {
047 tool.run();
048 }
049 catch (Exception e) {
050 System.out.println("Caught: " + e);
051 e.printStackTrace();
052 }
053 }
054
055 public ProducerConsumer() {
056 }
057
058 public void run() throws Exception {
059 consumer.start();
060 consumer.subscribe();
061 start();
062 publish();
063 }
064
065 public void setTopic(boolean topic) {
066 super.setTopic(topic);
067 consumer.setTopic(topic);
068 }
069
070 public void setSubject(String subject) {
071 super.setSubject(subject);
072 consumer.setSubject(subject);
073 }
074
075 public void setUrl(String url) {
076 super.setUrl(url);
077 consumer.setUrl(url);
078 }
079
080 protected boolean useTimerLoop() {
081 return false;
082 }
083 }