KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dotcom > TopicListener


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - Dyade
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): Frederic Maistre (INRIA)
22  * Contributor(s):
23  */

24 package dotcom;
25
26 import javax.jms.*;
27
28 /**
29  * Listener getting messages from a topic.
30  *
31  * @author Maistre Frederic
32  *
33  * @see CustomerServer
34  * @see InventoryServer
35  * @see BillingServer
36  */

37 class TopicListener implements javax.jms.MessageListener JavaDoc {
38   /** TopicSession getting messages from a topic. */
39   TopicSession session ;
40   /** FifoQueue used to hold incoming messages. */
41   fr.dyade.aaa.util.Queue queue ;
42   
43   /**
44    * Creates a TopicListener.
45    *
46    * @param session current TopicSession
47    * @param queue FifoQueue used to hold incoming messages
48    */

49   TopicListener(TopicSession session, fr.dyade.aaa.util.Queue queue) {
50     this.session = session ;
51     this.queue = queue ;
52   }
53
54   /**
55    * Method called when receiving a message.
56    *
57    * @param msg message received from the topic
58    */

59   public void onMessage(javax.jms.Message JavaDoc msg) {
60     try {
61       // push incoming message into the queue
62
queue.push((ObjectMessage) msg);
63       // commiting the reception
64
session.commit() ;
65       
66     } catch (Exception JavaDoc exc) {
67       System.out.println(" Exception caught in TopicListener: " + exc);
68       exc.printStackTrace();
69     }
70   }
71 }
72
Popular Tags