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 */ 017package org.apache.activemq.tool; 018 019import javax.jms.JMSException; 020 021import org.apache.activemq.tool.properties.JmsClientProperties; 022import org.apache.activemq.tool.properties.JmsClientSystemProperties; 023import org.apache.activemq.tool.properties.JmsConsumerProperties; 024import org.apache.activemq.tool.properties.JmsConsumerSystemProperties; 025import org.apache.activemq.tool.sampler.ThroughputSamplerTask; 026 027public 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 @Override 052 protected ClientRunBasis getClientRunBasis() { 053 assert (consumer != null); 054 return ClientRunBasis.valueOf(consumer.getRecvType().toLowerCase()); 055 } 056 057 @Override 058 protected long getClientRunDuration() { 059 return consumer.getRecvDuration(); 060 } 061 062 protected void runJmsClient(String clientName, int clientDestIndex, int clientDestCount) { 063 ThroughputSamplerTask sampler = getTpSampler(); 064 065 JmsConsumerClient consumerClient = new JmsConsumerClient(consumer, jmsConnFactory); 066 consumerClient.setClientName(clientName); 067 068 if (sampler != null) { 069 sampler.registerClient(consumerClient); 070 } 071 072 try { 073 consumerClient.receiveMessages(clientDestIndex, clientDestCount); 074 } catch (JMSException e) { 075 e.printStackTrace(); 076 } 077 } 078 079 public static void main(String[] args) { 080 JmsConsumerSystem sys = new JmsConsumerSystem(); 081 sys.configureProperties(AbstractJmsClientSystem.parseStringArgs(args)); 082 083 try { 084 sys.runSystemTest(); 085 } catch (JMSException e) { 086 e.printStackTrace(); 087 } 088 } 089}