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.4 $
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.setConnectionCount(Integer.parseInt(args[3]));
42          }
43          try {
44              tool.run();
45          }
46          catch (Exception e) {
47              System.out.println("Caught: " + e);
48              e.printStackTrace();
49          }
50      }
51  
52      public ProducerConsumer() {
53      }
54  
55      public void run() throws Exception {
56          consumer.start();
57          consumer.subscribe();
58          start();
59          publish();
60          consumer.waitLoop();
61      }
62  
63      public void setTopic(boolean topic) {
64          super.setTopic(topic);
65          consumer.setTopic(topic);
66      }
67  
68      public void setSubject(String subject) {
69          super.setSubject(subject);
70          consumer.setSubject(subject);
71      }
72  
73      public void setUrl(String url) {
74          super.setUrl(url);
75          consumer.setUrl(url);
76      }
77  
78      protected boolean useTimerLoop() {
79          return false;
80      }
81  }