KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > example > MyListener


1 package example;
2
3 import java.util.logging.Logger JavaDoc;
4 import java.util.logging.Level JavaDoc;
5
6 import javax.jms.Message JavaDoc;
7 import javax.jms.TextMessage JavaDoc;
8 import javax.jms.MessageListener JavaDoc;
9
10 public class MyListener implements MessageListener JavaDoc {
11   private static final Logger JavaDoc log = Logger.getLogger(MyListener.class.getName());
12   private static String JavaDoc _lastMessage;
13
14   /**
15    * Returns the last received message.
16    */

17   public static String JavaDoc getLastMessage()
18   {
19     return _lastMessage;
20   }
21   
22   /**
23    * Receives the message.
24    */

25   public void onMessage(Message JavaDoc message)
26   {
27     try {
28       TextMessage JavaDoc textMessage = (TextMessage JavaDoc) message;
29
30       log.info("received: " + textMessage.getText());
31
32       _lastMessage = textMessage.getText();
33     } catch (Throwable JavaDoc e) {
34       log.log(Level.WARNING, e.toString(), e);
35     }
36   }
37 }
38
Popular Tags