01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.jmeter.protocol.jms.sampler;
20:
21: import javax.jms.JMSException;
22: import javax.jms.Message;
23: import javax.jms.QueueSender;
24:
25: import org.apache.jorphan.logging.LoggingManager;
26: import org.apache.log.Logger;
27:
28: /**
29: * Request/reply executor with a fixed reply queue. <br>
30: * Created on: October 28, 2004
31: *
32: * @author Martijn Blankestijn
33: * @version $Id: FixedQueueExecutor.java,v 1.3 2005/05/19 15:36:53 mblankestijn
34: * Exp $
35: */
36: public class FixedQueueExecutor implements QueueExecutor {
37: /** Sender. */
38: private QueueSender producer;
39:
40: /** Timeout used for waiting on message. */
41: private int timeout;
42:
43: static Logger log = LoggingManager.getLoggerForClass();
44:
45: /**
46: * Constructor.
47: *
48: * @param producer
49: * the queue to send the message on
50: * @param timeout
51: * timeout to use for the return message
52: */
53: public FixedQueueExecutor(QueueSender producer, int timeout) {
54: this .producer = producer;
55: this .timeout = timeout;
56: }
57:
58: /*
59: * (non-Javadoc)
60: *
61: * @see org.apache.jmeter.protocol.jms.sampler.QueueExecutor#sendAndReceive(javax.jms.Message)
62: */
63: public Message sendAndReceive(Message request) throws JMSException {
64: producer.send(request);
65: String id = request.getJMSMessageID();
66: MessageAdmin.getAdmin().putRequest(id, request);
67: try {
68: if (log.isDebugEnabled()) {
69: log.debug("wait for reply " + id + " started on "
70: + System.currentTimeMillis());
71: }
72: synchronized (request) {
73: request.wait(timeout);
74: }
75: if (log.isDebugEnabled()) {
76: log.debug("done waiting for " + id + " ended on "
77: + System.currentTimeMillis());
78: }
79:
80: } catch (InterruptedException e) {
81: log.warn("Interrupt exception caught", e);
82: }
83: return MessageAdmin.getAdmin().get(request.getJMSMessageID());
84: }
85: }
|