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.topic;
022
023 import org.apache.qpid.client.AMQSession;
024 import org.apache.qpid.config.ConnectorConfig;
025 import org.apache.qpid.config.Connector;
026 import org.apache.qpid.config.AbstractConfig;
027
028 import javax.jms.Connection;
029
030 public class Config extends AbstractConfig implements ConnectorConfig
031 {
032
033 private String host = "localhost";
034 private int port = 5672;
035 private String factory = null;
036
037 private int payload = 256;
038 private int messages = 1000;
039 private int clients = 1;
040 private int batch = 1;
041 private long delay = 1;
042 private int warmup;
043 private int ackMode= AMQSession.NO_ACKNOWLEDGE;
044 private String clientId;
045 private String subscriptionId;
046 private String selector;
047 private String destinationName;
048 private boolean persistent;
049 private boolean transacted;
050 private int destinationsCount;
051 private int batchSize;
052 private int rate;
053 private boolean ispubsub;
054 private long timeout;
055
056 public Config()
057 {
058 }
059
060 public int getAckMode()
061 {
062 return ackMode;
063 }
064
065 public void setPayload(int payload)
066 {
067 this.payload = payload;
068 }
069
070 public int getPayload()
071 {
072 return payload;
073 }
074
075 void setClients(int clients)
076 {
077 this.clients = clients;
078 }
079
080 int getClients()
081 {
082 return clients;
083 }
084
085 void setMessages(int messages)
086 {
087 this.messages = messages;
088 }
089
090 public int getMessages()
091 {
092 return messages;
093 }
094
095 public int getBatchSize()
096 {
097 return batchSize;
098 }
099
100 public int getRate()
101 {
102 return rate;
103 }
104
105 public int getDestinationsCount()
106 {
107 return destinationsCount;
108 }
109
110 public String getHost()
111 {
112 return host;
113 }
114
115 public void setHost(String host)
116 {
117 this.host = host;
118 }
119
120 public int getPort()
121 {
122 return port;
123 }
124
125 public String getFactory()
126 {
127 return factory;
128 }
129
130 public void setPort(int port)
131 {
132 this.port = port;
133 }
134
135 int getBatch()
136 {
137 return batch;
138 }
139
140 void setBatch(int batch)
141 {
142 this.batch = batch;
143 }
144
145 int getWarmup()
146 {
147 return warmup;
148 }
149
150 void setWarmup(int warmup)
151 {
152 this.warmup = warmup;
153 }
154
155 public long getDelay()
156 {
157 return delay;
158 }
159
160 public void setDelay(long delay)
161 {
162 this.delay = delay;
163 }
164
165 public long getTimeout()
166 {
167 return timeout;
168 }
169
170 public void setTimeout(long time)
171 {
172 this.timeout = time;
173 }
174
175 public String getClientId()
176 {
177 return clientId;
178 }
179
180 public String getSubscriptionId()
181 {
182 return subscriptionId;
183 }
184
185 public String getSelector()
186 {
187 return selector;
188 }
189
190 public String getDestination()
191 {
192 return destinationName;
193 }
194
195 public boolean usePersistentMessages()
196 {
197 return persistent;
198 }
199
200 public boolean isTransacted()
201 {
202 return transacted;
203 }
204
205 public boolean isPubSub()
206 {
207 return ispubsub;
208 }
209
210 public void setOption(String key, String value)
211 {
212 if("-host".equalsIgnoreCase(key))
213 {
214 setHost(value);
215 }
216 else if("-port".equalsIgnoreCase(key))
217 {
218 try
219 {
220 setPort(Integer.parseInt(value));
221 }
222 catch(NumberFormatException e)
223 {
224 throw new RuntimeException("Bad port number: " + value, e);
225 }
226 }
227 else if("-payload".equalsIgnoreCase(key))
228 {
229 setPayload(parseInt("Bad payload size", value));
230 }
231 else if("-messages".equalsIgnoreCase(key))
232 {
233 setMessages(parseInt("Bad message count", value));
234 }
235 else if("-clients".equalsIgnoreCase(key))
236 {
237 setClients(parseInt("Bad client count", value));
238 }
239 else if("-batch".equalsIgnoreCase(key))
240 {
241 setBatch(parseInt("Bad batch count", value));
242 }
243 else if("-delay".equalsIgnoreCase(key))
244 {
245 setDelay(parseLong("Bad batch delay", value));
246 }
247 else if("-warmup".equalsIgnoreCase(key))
248 {
249 setWarmup(parseInt("Bad warmup count", value));
250 }
251 else if("-ack".equalsIgnoreCase(key))
252 {
253 ackMode = parseInt("Bad ack mode", value);
254 }
255 else if("-factory".equalsIgnoreCase(key))
256 {
257 factory = value;
258 }
259 else if("-clientId".equalsIgnoreCase(key))
260 {
261 clientId = value;
262 }
263 else if("-subscriptionId".equalsIgnoreCase(key))
264 {
265 subscriptionId = value;
266 }
267 else if("-persistent".equalsIgnoreCase(key))
268 {
269 persistent = "true".equalsIgnoreCase(value);
270 }
271 else if("-transacted".equalsIgnoreCase(key))
272 {
273 transacted = "true".equalsIgnoreCase(value);
274 }
275 else if ("-destinationscount".equalsIgnoreCase(key))
276 {
277 destinationsCount = parseInt("Bad destinations count", value);
278 }
279 else if ("-batchsize".equalsIgnoreCase(key))
280 {
281 batchSize = parseInt("Bad batch size", value);
282 }
283 else if ("-rate".equalsIgnoreCase(key))
284 {
285 rate = parseInt("MEssage rate", value);
286 }
287 else if("-pubsub".equalsIgnoreCase(key))
288 {
289 ispubsub = "true".equalsIgnoreCase(value);
290 }
291 else if("-selector".equalsIgnoreCase(key))
292 {
293 selector = value;
294 }
295 else if("-destinationname".equalsIgnoreCase(key))
296 {
297 destinationName = value;
298 }
299 else if("-timeout".equalsIgnoreCase(key))
300 {
301 setTimeout(parseLong("Bad timeout data", value));
302 }
303 else
304 {
305 System.out.println("Ignoring unrecognised option: " + key);
306 }
307 }
308
309 static String getAckModeDescription(int ackMode)
310 {
311 switch(ackMode)
312 {
313 case AMQSession.NO_ACKNOWLEDGE: return "NO_ACKNOWLEDGE";
314 case AMQSession.AUTO_ACKNOWLEDGE: return "AUTO_ACKNOWLEDGE";
315 case AMQSession.CLIENT_ACKNOWLEDGE: return "CLIENT_ACKNOWLEDGE";
316 case AMQSession.DUPS_OK_ACKNOWLEDGE: return "DUPS_OK_ACKNOWELDGE";
317 case AMQSession.PRE_ACKNOWLEDGE: return "PRE_ACKNOWLEDGE";
318 }
319 return "AckMode=" + ackMode;
320 }
321
322 public Connection createConnection() throws Exception
323 {
324 return new Connector().createConnection(this);
325 }
326 }
|