KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ProducerAndConsumerTool


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
19 import java.util.Arrays JavaDoc;
20 import java.util.HashSet JavaDoc;
21
22 import javax.jms.MessageListener JavaDoc;
23
24 /**
25  * A simple tool for producing and consuming messages
26  *
27  * @version $Revision: 1.1.1.1 $
28  */

29 public class ProducerAndConsumerTool extends ConsumerTool implements MessageListener JavaDoc {
30
31     public static void main(String JavaDoc[] args) {
32         
33         ConsumerTool consumerTool = new ConsumerTool();
34         String JavaDoc[] unknonwn = CommnadLineSupport.setOptions(consumerTool, args);
35         HashSet JavaDoc set1 = new HashSet JavaDoc(Arrays.asList(unknonwn));
36         
37         ProducerTool producerTool = new ProducerTool();
38         unknonwn = CommnadLineSupport.setOptions(producerTool, args);
39         HashSet JavaDoc set2 = new HashSet JavaDoc(Arrays.asList(unknonwn));
40
41         set1.retainAll(set2);
42         if( set1.size() > 0 ) {
43             System.out.println("Unknown options: "+set1);
44             System.exit(-1);
45         }
46         
47         consumerTool.run();
48         producerTool.run();
49         
50     }
51
52 }
53
Popular Tags