KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > statistics > beans > StatisticsMessageBean


1 /*
2  * Coefficient - facilitates project based collaboration
3  * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
4  * PO Box 395
5  * Pretoria 0001, RSA
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 (at your option) any later version.
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package za.org.coefficient.statistics.beans;
21
22 import net.sf.hibernate.HibernateException;
23
24 import za.org.coefficient.util.common.InvokerFactory;
25
26 import javax.ejb.EJBException JavaDoc;
27 import javax.ejb.MessageDrivenBean JavaDoc;
28 import javax.ejb.MessageDrivenContext JavaDoc;
29
30 import javax.jms.JMSException JavaDoc;
31 import javax.jms.MapMessage JavaDoc;
32 import javax.jms.Message JavaDoc;
33 import javax.jms.MessageListener JavaDoc;
34
35 /**
36  *
37  * @ejb:bean name="StatisticsMessage"
38  * transaction-type="Container"
39  * acknowledge-mode="Auto-acknowledge"
40  * destination-type="javax.jms.Queue"
41  * subscription-durability="Durable"
42  * @jboss:destination-jndi-name name="queue/statisticsQueue"
43  */

44 public class StatisticsMessageBean implements MessageDrivenBean JavaDoc,
45     MessageListener JavaDoc {
46     //~ Static fields/initializers =============================================
47

48     private static final String JavaDoc PROJECT = "project";
49     private static final String JavaDoc NAME = "name";
50     private static final String JavaDoc ACTION = "action";
51
52     //~ Instance fields ========================================================
53

54     private MessageDrivenContext JavaDoc ctx = null;
55
56     //~ Constructors ===========================================================
57

58     // Constructor
59
public StatisticsMessageBean() {
60     }
61
62     //~ Methods ================================================================
63

64     // Implementation of the MessageDrivenBean interface
65
public void setMessageDrivenContext(MessageDrivenContext JavaDoc ctx)
66         throws EJBException JavaDoc {
67         this.ctx = ctx;
68     }
69
70     public void ejbCreate() {
71     }
72
73     public void ejbRemove() {
74     }
75
76     //
77
// Implementation of the MessageListener interface
78
//
79
public void onMessage(Message JavaDoc message) {
80         if (message instanceof MapMessage JavaDoc) {
81             MapMessage JavaDoc mm = (MapMessage JavaDoc) message;
82             try {
83                 String JavaDoc name = mm.getString(NAME);
84                 Long JavaDoc prjId = new Long JavaDoc(mm.getLong(PROJECT));
85                 String JavaDoc action = mm.getString(ACTION);
86                 if(name == null) {
87                     name = "";
88                 }
89                 InvokerFactory.getInvoker().invokeMethodOnService("StatisticsService", "doStatistics", new Object JavaDoc[]{name, prjId, action});
90             } catch (JMSException JavaDoc jmsex) {
91                 jmsex.printStackTrace();
92                 System.err.println("<< exception getting values from messsage");
93             } catch (HibernateException he) {
94                 he.printStackTrace();
95                 System.err.println("<< hibernate exception, crap!!");
96             } catch (Exception JavaDoc e) {
97                 e.printStackTrace();
98                 System.err.println("<< exception, calling service!!");
99             }
100         } else {
101             System.out.println(
102                 "StatisticsMessageBean expected MapMessage but got message - "
103                 + message.getClass());
104         }
105     }
106 }
107
Popular Tags