The container provides the message-driven bean instance with a MessageDrivenContext. This gives the message-driven bean instance access to the instance's context maintained by the container. The MessageDrivenContext interface has the following methods:
The setRollbackOnly method allows the instance to mark the current transaction such that the only outcome of the transaction is a rollback. ONLY instances of a message-driven bean with container-managed transaction (CMT) demarcation can use this method.
The getRollbackOnly method allows the instance to test if the current transaction has been marked for rollback. ONLY instances of a message-driven bean with container-managed transaction (CMT) demarcation can use this method.
The getUserTransaction method returns the javax.transaction.UserTransaction interface that the instance can use to demarcate transactions, and to obtain transaction status. ONLY instances of a message-driven bean with bean-managed transaction (BMT) demarcation can use this method.
The getCallerPrincipal method is inherited from the EJBContext interface. Message-driven bean instances MUST NOT call this method (caller is unknown for MDB).
The isCallerInRole method is inherited from the EJBContext interface. Message-driven bean instances MUST NOT call this method (caller is unknown for MDB).
The getEJBHome and getEJBLocalHome methods are inherited from the EJBContext interface. Message-driven bean instances MUST NOT call these methods (MDB has no home/local-home interfaces, as well do not have component interfaces).
package javax.ejb; public interface MessageDrivenContext extends EJBContext { } public interface EJBContext { EJBHome getEJBHome(); EJBLocalHome getEJBLocalHome(); java.security.Principal getCallerPrincipal(); boolean isCallerInRole(String roleName); UserTransaction getUserTransaction() throws IllegalStateException; void setRollbackOnly() throws IllegalStateException; boolean getRollbackOnly() throws IllegalStateException; }