KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > strictpool > MDBInvoker


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * 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 JavaDoc;
25 import javax.jms.Queue JavaDoc;
26 import javax.jms.QueueSender JavaDoc;
27 import javax.jms.TextMessage JavaDoc;
28 import javax.jms.QueueReceiver JavaDoc;
29 import javax.jms.Message JavaDoc;
30 import javax.jms.ObjectMessage JavaDoc;
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: 58110 $
39  */

40 public class MDBInvoker extends Thread JavaDoc
41 {
42    QueueSession JavaDoc session;
43    Queue JavaDoc queueA;
44    Queue JavaDoc queueB;
45    int id;
46    CountDown done;
47    public Exception JavaDoc runEx;
48
49    public MDBInvoker(QueueSession JavaDoc session, Queue JavaDoc queueA, Queue JavaDoc queueB, int id, CountDown done)
50    {
51       super("MDBInvoker#"+id);
52       this.session = session;
53       this.queueA = queueA;
54       this.queueB = queueB;
55       this.id = id;
56       this.done = done;
57    }
58    public void run()
59    {
60       System.out.println("Begin run, this="+this);
61       try
62       {
63          QueueSender JavaDoc sender = session.createSender(queueA);
64          TextMessage JavaDoc message = session.createTextMessage();
65          message.setText(this.toString());
66          sender.send(message);
67          QueueReceiver JavaDoc receiver = session.createReceiver(queueB);
68          Message JavaDoc reply = receiver.receive(20000);
69          if( reply == null )
70          {
71             runEx = new IllegalStateException JavaDoc("Message receive timeout");
72          }
73          else
74          {
75             Message JavaDoc tm = (Message JavaDoc) reply;
76             System.out.println(tm);
77          }
78          sender.close();
79          receiver.close();
80       }
81       catch(Exception JavaDoc e)
82       {
83          runEx = e;
84       }
85       done.release();
86       System.out.println("End run, this="+this);
87    }
88
89 }
90
Popular Tags