
// MessageTakerMD.java

package ersatz.resourceadapter;

import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;

/**
 *
 */
public class MessageTakerMD implements MessageDrivenBean, 
                                       MsgListenerInterface 
{
    private transient MessageDrivenContext mdbContext;
    String cName = "MessageTakerMD";
    
    // constructor for the container
    public MessageTakerMD() {
    }

    // ------------------------------------------------------------------
    // MessageDrivenBean implementation
    // ------------------------------------------------------------------

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

    public void setMessageDrivenContext(MessageDrivenContext ctxt) {
        mdbContext = ctxt;
/*tmp*/ System.out.println(cName+".setMessageDrivenContext");
        Utility.log(cName+".setMessageDrivenContext");
    } 

    /**
     * A container invokes this method before it ends the life of the message-driven object. 
     * This happens when a container decides to terminate the message-driven object. 
     *
     * This method is called with no transaction context. 
     *
     * @throws EJBException Thrown by the method to indicate a failure caused by
     * a system-level error.
     */
    public void ejbRemove() {
        Utility.log(cName+".ejbRemove");
    }

    /**
     * The Message driven  bean must define an ejbCreate methods with no args.
     *
     */
    public void ejbCreate() {
        Utility.log(cName+".ejbCreate");
    }

    /**
     *  onMessage method
     */
    public void onMessage(String message) {
/*tmp*/ System.out.println(cName+".onMessage Message="+message);
	    try {
            Utility.log(cName+".onMessage Message="+message);
	    } catch (Exception ex) {
            Utility.log(cName+".onMessage Exception caught="+ex.toString());
	    }
    }
    /**
     *  offMessage method
     */
    public void offMessage(String message) {
	    try{
            Utility.log(cName+".offMessage Message="+message);
	    }catch(Exception ex){
            Utility.log(cName+".offMessage Exception caught="+ex.toString());
	    }
    }
}