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