KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ersatz > resourceadapter > MessageTakerMD


1
2 // MessageTakerMD.java
3

4 package ersatz.resourceadapter;
5
6 import javax.ejb.MessageDrivenBean;
7 import javax.ejb.MessageDrivenContext;
8
9 /**
10  *
11  */

12 public class MessageTakerMD implements MessageDrivenBean,
13                                        MsgListenerInterface
14 {
15     private transient MessageDrivenContext mdbContext;
16     String cName = "MessageTakerMD";
17     
18     // constructor for the container
19
public MessageTakerMD() {
20     }
21
22     // ------------------------------------------------------------------
23
// MessageDrivenBean implementation
24
// ------------------------------------------------------------------
25

26     /**
27      * Set the associated context. The container calls this method
28      * after the instance creation.
29      * The enterprise Bean instance should store the reference to the context
30      * object in an instance variable.
31      * This method is called with no transaction context.
32      *
33      * @param MessageDrivenContext A MessageDrivenContext interface for the instance.
34      * @throws EJBException Thrown by the method to indicate a failure caused by
35      * a system-level error.
36      */

37
38     public void setMessageDrivenContext(MessageDrivenContext ctxt) {
39         mdbContext = ctxt;
40 /*tmp*/ System.out.println(cName+".setMessageDrivenContext");
41         Utility.log(cName+".setMessageDrivenContext");
42     }
43
44     /**
45      * A container invokes this method before it ends the life of the message-driven object.
46      * This happens when a container decides to terminate the message-driven object.
47      *
48      * This method is called with no transaction context.
49      *
50      * @throws EJBException Thrown by the method to indicate a failure caused by
51      * a system-level error.
52      */

53     public void ejbRemove() {
54         Utility.log(cName+".ejbRemove");
55     }
56
57     /**
58      * The Message driven bean must define an ejbCreate methods with no args.
59      *
60      */

61     public void ejbCreate() {
62         Utility.log(cName+".ejbCreate");
63     }
64
65     /**
66      * onMessage method
67      */

68     public void onMessage(String message) {
69 /*tmp*/ System.out.println(cName+".onMessage Message="+message);
70         try {
71             Utility.log(cName+".onMessage Message="+message);
72         } catch (Exception ex) {
73             Utility.log(cName+".onMessage Exception caught="+ex.toString());
74         }
75     }
76     /**
77      * offMessage method
78      */

79     public void offMessage(String message) {
80         try{
81             Utility.log(cName+".offMessage Message="+message);
82         }catch(Exception ex){
83             Utility.log(cName+".offMessage Exception caught="+ex.toString());
84         }
85     }
86 }
Popular Tags