001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.activemq.tool; 018 019 import javax.jms.JMSException; 020 021 import org.apache.activemq.tool.properties.JmsClientProperties; 022 import org.apache.activemq.tool.properties.JmsClientSystemProperties; 023 import org.apache.activemq.tool.properties.JmsConsumerProperties; 024 import org.apache.activemq.tool.properties.JmsConsumerSystemProperties; 025 import org.apache.activemq.tool.sampler.ThroughputSamplerTask; 026 027 public class JmsConsumerSystem extends AbstractJmsClientSystem { 028 protected JmsConsumerSystemProperties sysTest = new JmsConsumerSystemProperties(); 029 protected JmsConsumerProperties consumer = new JmsConsumerProperties(); 030 031 public JmsClientSystemProperties getSysTest() { 032 return sysTest; 033 } 034 035 public void setSysTest(JmsClientSystemProperties sysTestProps) { 036 sysTest = (JmsConsumerSystemProperties)sysTestProps; 037 } 038 039 public JmsClientProperties getJmsClientProperties() { 040 return getConsumer(); 041 } 042 043 public JmsConsumerProperties getConsumer() { 044 return consumer; 045 } 046 047 public void setConsumer(JmsConsumerProperties consumer) { 048 this.consumer = consumer; 049 } 050 051 protected void runJmsClient(String clientName, int clientDestIndex, int clientDestCount) { 052 ThroughputSamplerTask sampler = getTpSampler(); 053 054 JmsConsumerClient consumerClient = new JmsConsumerClient(consumer, jmsConnFactory); 055 consumerClient.setClientName(clientName); 056 057 if (sampler != null) { 058 sampler.registerClient(consumerClient); 059 } 060 061 try { 062 consumerClient.receiveMessages(clientDestIndex, clientDestCount); 063 } catch (JMSException e) { 064 e.printStackTrace(); 065 } 066 } 067 068 public static void main(String[] args) { 069 JmsConsumerSystem sys = new JmsConsumerSystem(); 070 sys.configureProperties(AbstractJmsClientSystem.parseStringArgs(args)); 071 072 try { 073 sys.runSystemTest(); 074 } catch (JMSException e) { 075 e.printStackTrace(); 076 } 077 } 078 }