01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.ejb3.test.strictpool;
23:
24: import javax.jms.QueueSession;
25: import javax.jms.Queue;
26: import javax.jms.QueueSender;
27: import javax.jms.TextMessage;
28: import javax.jms.QueueReceiver;
29: import javax.jms.Message;
30: import javax.jms.ObjectMessage;
31:
32: import EDU.oswego.cs.dl.util.concurrent.CountDown;
33: import org.jboss.logging.Logger;
34:
35: /**
36: * Adapted from the EJB 2.1 tests (org.jboss.test.cts.test.SessionInvoker)
37: * @author <a href="mailto:kabir.khan@jboss.org">Kabir Khan</a>
38: * @version $Revision: 60233 $
39: */
40: public class MDBInvoker extends Thread {
41: QueueSession session;
42: Queue queueA;
43: Queue queueB;
44: int id;
45: CountDown done;
46: public Exception runEx;
47:
48: public MDBInvoker(QueueSession session, Queue queueA, Queue queueB,
49: int id, CountDown done) {
50: super ("MDBInvoker#" + id);
51: this .session = session;
52: this .queueA = queueA;
53: this .queueB = queueB;
54: this .id = id;
55: this .done = done;
56: }
57:
58: public void run() {
59: System.out.println("Begin run, this=" + this );
60: try {
61: QueueSender sender = session.createSender(queueA);
62: TextMessage message = session.createTextMessage();
63: message.setText(this .toString());
64: sender.send(message);
65: QueueReceiver receiver = session.createReceiver(queueB);
66: Message reply = receiver.receive(20000);
67: if (reply == null) {
68: runEx = new IllegalStateException(
69: "Message receive timeout");
70: } else {
71: Message tm = (Message) reply;
72: System.out.println(tm);
73: }
74: sender.close();
75: receiver.close();
76: } catch (Exception e) {
77: runEx = e;
78: }
79: done.release();
80: System.out.println("End run, this=" + this);
81: }
82:
83: }
|