DeleteViaQMDBean.ejb Sample
This topic inludes the source code for the DeleteViaQMDBean.ejb Sample.
Sample Location
This sample is located in the following directory in your WebLogic Workshop installation:
BEA_HOME/weblogic81/samples/workshop/SamplesApp/EJBs/messageDriven/
Sample Source Code
01 package messageDriven;
02
03 import java.util.Collection;
04 import java.util.Iterator;
05 import javax.ejb.*;
06 import javax.jms.*;
07 import javax.naming.InitialContext;
08 import javax.naming.NamingException;
09 import weblogic.ejb.*;
10
11 /**
12 * This Message-Driven Bean listens to the queue jms/SamplesAppMDBQ
13 * for messages with the message selector "Command = 'Delete'", and creates
14 * all tokens, using the entity bean SimpleTokenBean.
15 *
16 * @ejbgen:message-driven default-transaction="NotSupported"
17 * message-selector="Command = 'Delete'"
18 * ejb-name = DeleteViaQMD
19 * destination-jndi-name = jms/SamplesAppMDBQ
20 * destination-type = javax.jms.Queue
21 *
22 * @ejbgen:ejb-local-ref link="SimpleToken_M"
23 */
24 public class DeleteViaQMDBean
25 extends GenericMessageDrivenBean
26 implements MessageDrivenBean, MessageListener
27 {
28 private SimpleTokenHome_M tokenHome;
29
30 public void ejbCreate() {
31 try {
32 javax.naming.Context ic = new InitialContext();
33 tokenHome = (SimpleTokenHome_M)ic.lookup("java:/comp/env/ejb/SimpleToken_M");
34 }
35 catch(NamingException ne) {
36 System.out.println("Encountered the following naming exception: " + ne.getMessage());
37 }
38 }
39
40 public void onMessage(Message msg) {
41 try {
42 Iterator allIter = tokenHome.findAll().iterator();
43 while(allIter.hasNext()) {
44 ((SimpleToken_M) allIter.next()).remove();
45 }
46 }
47 catch(Exception e) {
48 System.out.println("Encountered the following exception: " + e.getMessage());
49 }
50 }
51 }
52
|