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.test.cts.test;
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.apache.log4j.Category;
34:
35: /**
36: * @author Scott.Stark@jboss.org
37: * @version $Revision: 57211 $
38: */
39: public class MDBInvoker extends Thread {
40: Category log;
41: QueueSession session;
42: Queue queueA;
43: Queue queueB;
44: int id;
45: CountDown done;
46: Exception runEx;
47:
48: public MDBInvoker(QueueSession session, Queue queueA, Queue queueB,
49: int id, CountDown done, Category log) {
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: this .log = log;
57: }
58:
59: public void run() {
60: log.info("Begin run, this=" + this );
61: try {
62: QueueSender sender = session.createSender(queueA);
63: TextMessage message = session.createTextMessage();
64: message.setText(this .toString());
65: sender.send(message);
66: QueueReceiver receiver = session.createReceiver(queueB);
67: log.info("Begin receive");
68: Message reply = receiver.receive(10000);
69: log.info("reply=" + reply);
70: if (reply == null)
71: runEx = new IllegalStateException(
72: "Message receive timeout");
73: else if (reply instanceof ObjectMessage) {
74: ObjectMessage om = (ObjectMessage) reply;
75: runEx = (Exception) om.getObject();
76: }
77: sender.close();
78: receiver.close();
79: } catch (Exception e) {
80: runEx = e;
81: }
82: done.release();
83: System.out.println("End run, this=" + this);
84: }
85:
86: }
|