KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > alarm > beans > AlarmListenerBean


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
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: JOnAS Team
22  * --------------------------------------------------------------------------
23  * $Id: AlarmListenerBean.java,v 1.6 2004/04/09 12:56:41 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.alarm.beans;
28
29 import javax.ejb.EJBException JavaDoc;
30 import javax.ejb.MessageDrivenBean JavaDoc;
31 import javax.ejb.MessageDrivenContext JavaDoc;
32 import javax.jms.JMSException JavaDoc;
33 import javax.jms.MapMessage JavaDoc;
34 import javax.jms.Message JavaDoc;
35 import javax.jms.MessageListener JavaDoc;
36
37 /**
38  *
39  */

40 public class AlarmListenerBean implements MessageDrivenBean JavaDoc, MessageListener JavaDoc {
41
42     /**
43      * Reference to the alarm manager
44      */

45     private static transient AlarmManager alarmManager = null;
46
47     /**
48      * Default constructor
49      */

50     public AlarmListenerBean() {
51     }
52
53     /**
54      * Set the associated context. The container call this method after the
55      * instance creation. The enterprise Bean instance should store the
56      * reference to the context object in an instance variable. This method is
57      * called with no transaction context.
58      * @param ctx A MessageDrivenContext interface for the
59      * instance.
60      */

61
62     public void setMessageDrivenContext(MessageDrivenContext JavaDoc ctx) {
63     }
64
65     /**
66      * A container invokes this method before it ends the life of the
67      * message-driven object. This happens when a container decides to terminate
68      * the message-driven object. This method is called with no transaction
69      * context.
70      * @throws EJBException Thrown by the method to indicate a failure caused by
71      * a system-level error.
72      */

73     public void ejbRemove() throws EJBException JavaDoc {
74     }
75
76     /**
77      * The Message driven bean must define an ejbCreate methods with no args. We
78      * can do here all operations that will be common to all messages, i.e.
79      * asking JNDI for bean homes, ...
80      */

81     public void ejbCreate() {
82         // Get a reference on the AlarmManager.
83
alarmManager = AlarmManager.getInstance();
84
85     }
86
87     /**
88      * Called when there is a messgae
89      * @param message the message
90      * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
91      */

92     public void onMessage(Message JavaDoc message) {
93
94         int sev = 0;
95         String JavaDoc from = null;
96         String JavaDoc reason = null;
97
98         // Decode the message (MapMessage)
99
MapMessage JavaDoc msg = (MapMessage JavaDoc) message;
100         try {
101             sev = msg.getInt("Severity");
102             from = msg.getString("From");
103             reason = msg.getString("Reason");
104         } catch (JMSException JavaDoc e) {
105             Debug.logError("AlarmListenerBean exception:" + e);
106         }
107         // Give all messages to the AlarmServiceHelper.
108
alarmManager.alarm(sev, from, reason);
109
110     }
111 }
Popular Tags