KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > tool > JmsConsumerSystem


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.tool;
19
20 import org.apache.activemq.tool.properties.JmsClientSystemProperties;
21 import org.apache.activemq.tool.properties.JmsConsumerSystemProperties;
22 import org.apache.activemq.tool.properties.JmsConsumerProperties;
23 import org.apache.activemq.tool.properties.JmsClientProperties;
24 import org.apache.activemq.tool.sampler.ThroughputSamplerTask;
25
26 import javax.jms.JMSException JavaDoc;
27 import java.util.Properties JavaDoc;
28
29 public class JmsConsumerSystem extends AbstractJmsClientSystem {
30     protected JmsConsumerSystemProperties sysTest = new JmsConsumerSystemProperties();
31     protected JmsConsumerProperties consumer = new JmsConsumerProperties();
32
33     public JmsClientSystemProperties getSysTest() {
34         return sysTest;
35     }
36
37     public void setSysTest(JmsClientSystemProperties sysTestProps) {
38         sysTest = (JmsConsumerSystemProperties)sysTestProps;
39     }
40
41     public JmsClientProperties getJmsClientProperties() {
42         return getConsumer();
43     }
44
45     public JmsConsumerProperties getConsumer() {
46         return consumer;
47     }
48
49     public void setConsumer(JmsConsumerProperties consumer) {
50         this.consumer = consumer;
51     }
52
53     protected void runJmsClient(String JavaDoc clientName, int clientDestIndex, int clientDestCount) {
54         ThroughputSamplerTask sampler = getTpSampler();
55
56         JmsConsumerClient consumerClient = new JmsConsumerClient(consumer, jmsConnFactory);
57         consumerClient.setClientName(clientName);
58
59         if (sampler != null) {
60             sampler.registerClient(consumerClient);
61         }
62
63         try {
64             consumerClient.receiveMessages(clientDestIndex, clientDestCount);
65         } catch (JMSException JavaDoc e) {
66             e.printStackTrace();
67         }
68     }
69
70     public static void main(String JavaDoc[] args) {
71         JmsConsumerSystem sys = new JmsConsumerSystem();
72         sys.configureProperties(AbstractJmsClientSystem.parseStringArgs(args));
73
74         try {
75             sys.runSystemTest();
76         } catch (JMSException JavaDoc e) {
77             e.printStackTrace();
78         }
79     }
80 }
81
Popular Tags