KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > benchmark > ProducerConsumer


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.benchmark;
19
20
21 /**
22  * @author James Strachan
23  * @version $Revision$
24  */

25 public class ProducerConsumer extends Producer {
26
27     private Consumer consumer = new Consumer();
28
29     public static void main(String JavaDoc[] 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 JavaDoc e) {
50             System.out.println("Caught: " + e);
51             e.printStackTrace();
52         }
53     }
54
55     public ProducerConsumer() {
56     }
57
58     public void run() throws Exception JavaDoc {
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 JavaDoc subject) {
71         super.setSubject(subject);
72         consumer.setSubject(subject);
73     }
74
75     public void setUrl(String JavaDoc url) {
76         super.setUrl(url);
77         consumer.setUrl(url);
78     }
79
80     protected boolean useTimerLoop() {
81         return false;
82     }
83 }
84
Popular Tags