KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > enventry > TestEnvEntryMDBean


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.enventry;
23
24 import javax.annotation.PostConstruct;
25 import javax.annotation.Resource;
26 import javax.ejb.ActivationConfigProperty JavaDoc;
27 import javax.ejb.MessageDriven JavaDoc;
28 import javax.jms.Connection JavaDoc;
29 import javax.jms.ConnectionFactory JavaDoc;
30 import javax.jms.Destination JavaDoc;
31 import javax.jms.Destination 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 import javax.jms.MessageProducer JavaDoc;
37 import javax.jms.Session JavaDoc;
38 import javax.naming.InitialContext JavaDoc;
39 import javax.naming.NamingException JavaDoc;
40
41 import org.jboss.logging.Logger;
42
43 /**
44  * @author <a HREF="mailto:carlo@nerdnet.nl">Carlo de Wolf</a>
45  * @version <tt>$Revision: 58110 $</tt>
46  */

47 @MessageDriven JavaDoc(name="TestEnvEntryMD",
48    activationConfig = {
49       @ActivationConfigProperty JavaDoc(
50          propertyName = "destinationType",
51          propertyValue = "javax.jms.Queue"),
52       @ActivationConfigProperty JavaDoc(
53          propertyName = "destination",
54          propertyValue = "queue/testEnvEntry") })
55 public class TestEnvEntryMDBean implements MessageListener JavaDoc
56 {
57    private static final Logger log = Logger.getLogger(TestEnvEntryMDBean.class);
58    
59    @Resource(mappedName="java:/JmsXA")
60    private ConnectionFactory JavaDoc connectionFactory;
61
62    @Resource(name="maxExceptions") private int maxExceptions = 4;
63    
64    @Resource private int numExceptions = 3;
65    
66    private int minExceptions = 1;
67    
68    public void onMessage(Message JavaDoc msg) {
69       try {
70          Destination JavaDoc destination = msg.getJMSReplyTo();
71          Connection JavaDoc conn = connectionFactory.createConnection();
72          try {
73             Session JavaDoc session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
74             MessageProducer JavaDoc replyProducer = session.createProducer(destination);
75             MapMessage JavaDoc replyMsg = session.createMapMessage();
76             replyMsg.setJMSCorrelationID(msg.getJMSMessageID());
77
78             replyMsg.setInt("maxExceptions", maxExceptions);
79             replyMsg.setInt("numExceptions", numExceptions);
80             replyMsg.setInt("minExceptions", minExceptions);
81
82 // System.err.println("reply to: " + destination);
83
// System.err.println("maxExceptions: " + maxExceptions);
84
// System.err.println("numExceptions: " + numExceptions);
85
// System.err.println("minExceptions: " + minExceptions);
86

87             replyProducer.send(replyMsg);
88          }
89          finally {
90             conn.close();
91          }
92       }
93       catch(JMSException JavaDoc e) {
94          throw new RuntimeException JavaDoc(e);
95       }
96    }
97 }
98
Popular Tags