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.JmsProducerProperties; 024import org.apache.activemq.tool.properties.JmsProducerSystemProperties; 025import org.apache.activemq.tool.sampler.ThroughputSamplerTask; 026 027public class JmsProducerSystem extends AbstractJmsClientSystem { 028 protected JmsProducerSystemProperties sysTest = new JmsProducerSystemProperties(); 029 protected JmsProducerProperties producer = new JmsProducerProperties(); 030 031 @Override 032 public JmsClientSystemProperties getSysTest() { 033 return sysTest; 034 } 035 036 @Override 037 public void setSysTest(JmsClientSystemProperties sysTestProps) { 038 sysTest = (JmsProducerSystemProperties)sysTestProps; 039 } 040 041 @Override 042 public JmsClientProperties getJmsClientProperties() { 043 return getProducer(); 044 } 045 046 public JmsProducerProperties getProducer() { 047 return producer; 048 } 049 050 public void setProducer(JmsProducerProperties producer) { 051 this.producer = producer; 052 } 053 054 @Override 055 protected ClientRunBasis getClientRunBasis() { 056 assert (producer != null); 057 return ClientRunBasis.valueOf(producer.getSendType().toLowerCase()); 058 } 059 060 @Override 061 protected long getClientRunDuration() { 062 return producer.getSendDuration(); 063 } 064 065 066 @Override 067 protected void runJmsClient(String clientName, int clientDestIndex, int clientDestCount) { 068 ThroughputSamplerTask sampler = getTpSampler(); 069 070 JmsProducerClient producerClient = new JmsProducerClient(producer, jmsConnFactory); 071 producerClient.setClientName(clientName); 072 073 if (sampler != null) { 074 sampler.registerClient(producerClient); 075 } 076 077 try { 078 producerClient.sendMessages(clientDestIndex, clientDestCount); 079 } catch (JMSException e) { 080 e.printStackTrace(); 081 } 082 } 083 084 public static void main(String[] args) { 085 JmsProducerSystem sys = new JmsProducerSystem(); 086 sys.configureProperties(AbstractJmsClientSystem.parseStringArgs(args)); 087 088 try { 089 sys.runSystemTest(); 090 } catch (JMSException e) { 091 e.printStackTrace(); 092 } 093 } 094}