Config.java
001 /*
002  *
003  * Licensed to the Apache Software Foundation (ASF) under one
004  * or more contributor license agreements.  See the NOTICE file
005  * distributed with this work for additional information
006  * regarding copyright ownership.  The ASF licenses this file
007  * to you under the Apache License, Version 2.0 (the
008  * "License"); you may not use this file except in compliance
009  * with the License.  You may obtain a copy of the License at
010  
011  *   http://www.apache.org/licenses/LICENSE-2.0
012  
013  * Unless required by applicable law or agreed to in writing,
014  * software distributed under the License is distributed on an
015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016  * KIND, either express or implied.  See the License for the
017  * specific language governing permissions and limitations
018  * under the License.
019  *
020  */
021 package org.apache.qpid.oldtopic;
022 
023 import org.apache.qpid.client.AMQSession;
024 import org.apache.qpid.config.ConnectorConfig;
025 import org.apache.qpid.config.ConnectionFactoryInitialiser;
026 import org.apache.qpid.config.Connector;
027 import org.apache.qpid.config.AbstractConfig;
028 
029 import javax.jms.Connection;
030 import javax.jms.ConnectionFactory;
031 
032 class Config extends AbstractConfig implements ConnectorConfig
033 {
034 
035     private String host = "localhost";
036     private int port = 5672;
037     private String factory = null;
038 
039     private int payload = 256;
040     private int messages = 1000;
041     private int clients = 1;
042     private int batch = 1;
043     private long delay = 1;
044     private int warmup;
045     private int ackMode= AMQSession.NO_ACKNOWLEDGE;
046     private String clientId;
047     private String subscriptionId;
048     private boolean persistent;
049 
050     public Config()
051     {
052     }
053 
054     int getAckMode()
055     {
056         return ackMode;
057     }
058 
059     void setPayload(int payload)
060     {
061         this.payload = payload;
062     }
063 
064     int getPayload()
065     {
066         return payload;
067     }
068 
069     void setClients(int clients)
070     {
071         this.clients = clients;
072     }
073 
074     int getClients()
075     {
076         return clients;
077     }
078 
079     void setMessages(int messages)
080     {
081         this.messages = messages;
082     }
083 
084     int getMessages()
085     {
086         return messages;
087     }
088 
089     public String getHost()
090     {
091         return host;
092     }
093 
094     public void setHost(String host)
095     {
096         this.host = host;
097     }
098 
099     public int getPort()
100     {
101         return port;
102     }
103 
104     public String getFactory()
105     {
106         return factory;
107     }
108 
109     public void setPort(int port)
110     {
111         this.port = port;
112     }
113 
114     int getBatch()
115     {
116         return batch;
117     }
118 
119     void setBatch(int batch)
120     {
121         this.batch = batch;
122     }
123 
124     int getWarmup()
125     {
126         return warmup;
127     }
128 
129     void setWarmup(int warmup)
130     {
131         this.warmup = warmup;
132     }
133 
134     public long getDelay()
135     {
136         return delay;
137     }
138 
139     public void setDelay(long delay)
140     {
141         this.delay = delay;
142     }
143 
144     String getClientId()
145     {
146         return clientId;
147     }
148 
149     String getSubscriptionId()
150     {
151         return subscriptionId;
152     }
153 
154     boolean usePersistentMessages()
155     {
156         return persistent;
157     }
158 
159     public void setOption(String key, String value)
160     {
161         if("-host".equalsIgnoreCase(key))
162         {
163             setHost(value);
164         }
165         else if("-port".equalsIgnoreCase(key))
166         {
167             try
168             {
169                 setPort(Integer.parseInt(value));
170             }
171             catch(NumberFormatException e)
172             {
173                 throw new RuntimeException("Bad port number: " + value);
174             }
175         }
176         else if("-payload".equalsIgnoreCase(key))
177         {
178             setPayload(parseInt("Bad payload size", value));
179         }
180         else if("-messages".equalsIgnoreCase(key))
181         {
182             setMessages(parseInt("Bad message count", value));
183         }
184         else if("-clients".equalsIgnoreCase(key))
185         {
186             setClients(parseInt("Bad client count", value));
187         }
188         else if("-batch".equalsIgnoreCase(key))
189         {
190             setBatch(parseInt("Bad batch count", value));
191         }
192         else if("-delay".equalsIgnoreCase(key))
193         {
194             setDelay(parseLong("Bad batch delay", value));
195         }
196         else if("-warmup".equalsIgnoreCase(key))
197         {
198             setWarmup(parseInt("Bad warmup count", value));
199         }
200         else if("-ack".equalsIgnoreCase(key))
201         {
202             ackMode = parseInt("Bad ack mode", value);
203         }
204         else if("-factory".equalsIgnoreCase(key))
205         {
206             factory = value;
207         }
208         else if("-clientId".equalsIgnoreCase(key))
209         {
210             clientId = value;
211         }
212         else if("-subscriptionId".equalsIgnoreCase(key))
213         {
214             subscriptionId = value;
215         }
216         else if("-persistent".equalsIgnoreCase(key))
217         {
218             persistent = "true".equalsIgnoreCase(value);
219         }
220         else
221         {
222             System.out.println("Ignoring unrecognised option: " + key);
223         }
224     }
225 
226     static String getAckModeDescription(int ackMode)
227     {
228         switch(ackMode)
229         {
230             case AMQSession.NO_ACKNOWLEDGE: return "NO_ACKNOWLEDGE";
231             case AMQSession.AUTO_ACKNOWLEDGE: return "AUTO_ACKNOWLEDGE";
232             case AMQSession.CLIENT_ACKNOWLEDGE: return "CLIENT_ACKNOWLEDGE";
233             case AMQSession.DUPS_OK_ACKNOWLEDGE: return "DUPS_OK_ACKNOWELDGE";
234             case AMQSession.PRE_ACKNOWLEDGE: return "PRE_ACKNOWLEDGE";
235         }
236         return "AckMode=" + ackMode;
237     }
238 
239     public Connection createConnection() throws Exception
240     {
241         return new Connector().createConnection(this);
242     }
243 }