KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > ejb > QueueBean


1 package test.ejb;
2
3 import javax.ejb.EJBException JavaDoc;
4 import javax.ejb.MessageDrivenBean JavaDoc;
5 import javax.ejb.MessageDrivenContext JavaDoc;
6 import javax.jms.Message JavaDoc;
7 import javax.jms.MessageListener JavaDoc;
8
9 /**
10  * A message-driven bean based on a Queue.
11  *
12  * <p>A message-driven bean is an EJB that acts as a message consumer in the WebLogic JMS messaging
13  * system. As with standard JMS message consumers, message-driven beans receive messages from a JMS
14  * Queue or Topic, and perform business logic based on the message contents.</p>
15  *
16  * <p>More info on message-driven beans can be found here:
17  * <a HREF="http://www.onjava.com/pub/a/onjava/excerpt/ejb3_ch13/index.html?page=5#17">
18  * http://www.onjava.com/pub/a/onjava/excerpt/ejb3_ch13/index.html?page=5#17</a></p>
19  *
20  * @ejb.bean
21  * name="QueueBean"
22  * acknowledge-mode="Auto-acknowledge"
23  * destination-type="javax.jms.Queue"
24  * subscription-durability="NonDurable"
25  * transaction-type="Bean"
26  *
27  * @jboss.destination-jndi-name
28  * name="queue/testQueue"
29  *
30  * @weblogic.pool
31  * initial-beans-in-free-pool="1"
32  * max-beans-in-free-pool="3"
33  *
34  * @weblogic.message-driven
35  * connection-factory-jndi-name="moe"
36  * destination-jndi-name="queue/testQueue"
37  * initial-context-factory="meenie"
38  * jms-client-id="a"
39  * jms-polling-interval-seconds="4"
40  * provider-url="minie"
41  *
42  * @weblogic.transaction-descriptor
43  * trans-timeout-seconds="10"
44  *
45  * @weblogic.resource-description
46  * jndi-name="cream"
47  * res-ref-name="ice"
48  *
49  * @weblogic.resource-env-description
50  * jndi-name="pie"
51  * res-env-ref-name="blueberry"
52  *
53  * @weblogic.ejb-reference-description
54  * ejb-ref-name="hot"
55  * jndi-name="iron"
56  *
57  * @weblogic.ejb-local-reference-description
58  * ejb-ref-name="mashed"
59  * jndi-name="potatoes"
60  *
61  * @weblogic.enable-call-by-reference True
62  *
63  * @weblogic.run-as-identity-principal True
64  *
65  * @jonas.bean ejb-name="QueueBean"
66  * @jonas.message-driven-destination jndi-name="queue/testQueue"
67  *
68  * @author <a HREF="mailto:youremail@yourdomain.com">youremail@yourdomain.com</a>
69  */

70 public class QueueBean implements MessageDrivenBean JavaDoc, MessageListener JavaDoc {
71     /** The context for the message-driven bean, set by the EJB container. */
72     private MessageDrivenContext JavaDoc messageContext = null;
73
74     /** Required method for container to set context. */
75     public void setMessageDrivenContext(MessageDrivenContext JavaDoc messageContext) throws EJBException JavaDoc {
76         this.messageContext = messageContext;
77     }
78
79     /**
80      * Required creation method for message-driven beans.
81      *
82      * @ejb.create-method
83      */

84     public void ejbCreate() {
85         // no specific action required for message-driven beans
86
}
87
88     /** Required removal method for message-driven beans. */
89     public void ejbRemove() {
90         messageContext = null;
91     }
92
93     /**
94      * This method implements the business logic for the EJB.
95      *
96      * <p>Make sure that the business logic accounts for asynchronous message processing.
97      * For example, it cannot be assumed that the EJB receives messages in the order they were
98      * sent by the client. Instance pooling within the container means that messages are not
99      * received or processed in a sequential order, although individual onMessage() calls to
100      * a given message-driven bean instance are serialized.
101      *
102      * <p>The <code>onMessage()</code> method is required, and must take a single parameter
103      * of type javax.jms.Message. The throws clause (if used) must not include an application
104      * exception. Must not be declared as final or static.
105      */

106     public void onMessage(Message JavaDoc message) {
107         System.out.println("QueueBean got message " + message);
108         // do business logic here
109
}
110
111 }
112
Popular Tags