001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  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    package org.apache.activemq.benchmark;
018    
019    /**
020     * @author James Strachan
021     * @version $Revision$
022     */
023    public class ProducerConsumer extends Producer {
024    
025        private Consumer consumer = new Consumer();
026        
027        public ProducerConsumer() {
028        }
029    
030        public static void main(String[] args) {
031            ProducerConsumer tool = new ProducerConsumer();
032            if (args.length > 0) {
033                tool.setUrl(args[0]);
034            }
035            if (args.length > 1) {
036                tool.setTopic(parseBoolean(args[1]));
037            }
038            if (args.length > 2) {
039                tool.setSubject(args[2]);
040            }
041            if (args.length > 3) {
042                tool.setDurable(Boolean.getBoolean(args[3]));
043            }
044            if (args.length > 4) {
045                tool.setConnectionCount(Integer.parseInt(args[4]));
046            }
047            try {
048                tool.run();
049            } catch (Exception e) {
050                System.out.println("Caught: " + e);
051                e.printStackTrace();
052            }
053        }
054    
055        public void run() throws Exception {
056            consumer.start();
057            consumer.subscribe();
058            start();
059            publish();
060        }
061    
062        public void setTopic(boolean topic) {
063            super.setTopic(topic);
064            consumer.setTopic(topic);
065        }
066    
067        public void setSubject(String subject) {
068            super.setSubject(subject);
069            consumer.setSubject(subject);
070        }
071    
072        public void setUrl(String url) {
073            super.setUrl(url);
074            consumer.setUrl(url);
075        }
076    
077        protected boolean useTimerLoop() {
078            return false;
079        }
080    
081        public Consumer getConsumer() {
082            return consumer;
083        }
084    }