01 /*
02 *
03 * Licensed to the Apache Software Foundation (ASF) under one
04 * or more contributor license agreements. See the NOTICE file
05 * distributed with this work for additional information
06 * regarding copyright ownership. The ASF licenses this file
07 * to you under the Apache License, Version 2.0 (the
08 * "License"); you may not use this file except in compliance
09 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21
22 package org.apache.qpid.ping;
23
24 import java.util.Properties;
25
26 import javax.jms.Destination;
27 import javax.jms.JMSException;
28 import javax.jms.Message;
29 import javax.jms.ObjectMessage;
30
31 import org.apache.log4j.Logger;
32
33 import org.apache.qpid.client.message.TestMessageFactory;
34 import org.apache.qpid.util.CommandLineParser;
35
36 /**
37 * <p><table id="crc"><caption>CRC Card</caption>
38 * <tr><th> Responsibilities <th> Collaborations
39 * </table>
40 */
41 public class PingSendOnlyClient extends PingDurableClient
42 {
43 private static final Logger log = Logger.getLogger(PingSendOnlyClient.class);
44
45 public PingSendOnlyClient(Properties overrides) throws Exception
46 {
47 super(overrides);
48 }
49
50 /**
51 * Starts the ping/wait/receive process.
52 *
53 * @param args The command line arguments.
54 */
55 public static void main(String[] args)
56 {
57 try
58 {
59 // Create a ping producer overriding its defaults with all options passed on the command line.
60 Properties options = CommandLineParser.processCommandLine(args, new CommandLineParser(new String[][] {}), System.getProperties());
61 PingSendOnlyClient pingProducer = new PingSendOnlyClient(options);
62
63 // Create a shutdown hook to terminate the ping-pong producer.
64 Runtime.getRuntime().addShutdownHook(pingProducer.getShutdownHook());
65
66 // Ensure that the ping pong producer is registered to listen for exceptions on the connection too.
67 // pingProducer.getConnection().setExceptionListener(pingProducer);
68
69 // Run the test procedure.
70 int sent = pingProducer.send();
71 pingProducer.waitForUser("Press return to close connection and quit.");
72 pingProducer.closeConnection();
73
74 System.exit(0);
75 }
76 catch (Exception e)
77 {
78 System.err.println(e.getMessage());
79 log.error("Top level handler caught execption.", e);
80 System.exit(1);
81 }
82 }
83
84 public Message getTestMessage(Destination replyQueue, int messageSize, boolean persistent) throws JMSException
85 {
86 Message msg = TestMessageFactory.newTextMessage(_producerSession, messageSize);
87
88 // Timestamp the message in nanoseconds.
89 msg.setLongProperty(MESSAGE_TIMESTAMP_PROPNAME, System.nanoTime());
90
91 return msg;
92 }
93 }
|