    1   /***
    2    *
    3    * Copyright 2004 Protique Ltd
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   **/
    18  package org.codehaus.activemq.benchmark;
    19
    20
    21  /***
    22   * @author James Strachan
    23   * @version $Revision: 1.6 $
    24   */
    25  public class ProducerConsumer extends Producer {
    26
    27      private Consumer consumer = new Consumer();
    28
    29      public static void main(String[] args) {
    30          ProducerConsumer tool = new ProducerConsumer();
    31          if (args.length > 0) {
    32              tool.setUrl(args[0]);
    33          }
    34          if (args.length > 1) {
    35              tool.setTopic(parseBoolean(args[1]));
    36          }
    37          if (args.length > 2) {
    38              tool.setSubject(args[2]);
    39          }
    40          if (args.length > 3) {
    41              tool.setDurable(Boolean.getBoolean(args[3]));
    42          }
    43          if (args.length > 4) {
    44              tool.setConnectionCount(Integer.parseInt(args[4]));
    45          }
    46          try {
    47              tool.run();
    48          }
    49          catch (Exception e) {
    50              System.out.println("Caught: " + e);
    51              e.printStackTrace();
    52          }
    53      }
    54
    55      public ProducerConsumer() {
    56      }
    57
    58      public void run() throws Exception {
    59          consumer.start();
    60          consumer.subscribe();
    61          start();
    62          publish();
    63      }
    64
    65      public void setTopic(boolean topic) {
    66          super.setTopic(topic);
    67          consumer.setTopic(topic);
    68      }
    69
    70      public void setSubject(String subject) {
    71          super.setSubject(subject);
    72          consumer.setSubject(subject);
    73      }
    74
    75      public void setUrl(String url) {
    76          super.setUrl(url);
    77          consumer.setUrl(url);
    78      }
    79
    80      protected boolean useTimerLoop() {
    81          return false;
    82      }
    83  }