org.objectweb.jonas_ejb.container
Class JMessageDrivenBean

java.lang.Object
  extended by org.objectweb.jonas_ejb.container.JMessageDrivenBean
All Implemented Interfaces:
java.lang.Runnable, javax.ejb.EJBContext, javax.ejb.MessageDrivenContext, javax.jms.MessageListener, javax.jms.ServerSession, javax.resource.spi.work.Work

public class JMessageDrivenBean
extends java.lang.Object
implements javax.jms.MessageListener, javax.jms.ServerSession, javax.resource.spi.work.Work, javax.ejb.MessageDrivenContext

Generic interposed class for Message Driven Beans This class presents these interfaces, depending on object reached: ServerSession interface to the ServerSessionPool MessageDrivenContext interface to the bean instance MessageListener interface to the JMS Session Runnable interface to the ThreadPool

Author:
Philippe Coq, Philippe Durieux, Christophe Ney (Easier Enhydra integration)

Field Summary
protected  JMdbFactory bf
           
protected  javax.ejb.MessageDrivenBean mdb
           
protected  javax.jms.Session sess
           
protected  int timerTxAttr
          Transactional attribute for ejbTimeout method.
protected  org.objectweb.transaction.jta.TransactionManager tm
           
protected  int txattr
          Transactional attribute for onMessage method.
protected  javax.resource.spi.work.WorkManager wm
           
 
Constructor Summary
JMessageDrivenBean(JMdbFactory bf, javax.jms.Session sess, javax.ejb.MessageDrivenBean mdb, javax.resource.spi.work.WorkManager wm)
          constructor
 
Method Summary
 void deliverTimeout(javax.ejb.Timer timer)
          Deliver a timeout to the bean
 java.security.Identity getCallerIdentity()
          Deprecated. @exception java.lang.IllegalStateException always
 java.security.Principal getCallerPrincipal()
          Obtain the java.security.Principal that identifies the caller.
 javax.ejb.EJBHome getEJBHome()
          Is disallowed.
 javax.ejb.EJBLocalHome getEJBLocalHome()
          Is disallowed.
 java.util.Properties getEnvironment()
          Deprecated. Use the JNDI naming context java:comp/env instead.
 boolean getRollbackOnly()
          Tests if the transaction has been marked for rollback only.
 javax.jms.Session getSession()
          Return the ServerSession's Session.
 javax.ejb.TimerService getTimerService()
          Get access to the EJB Timer Service.
 javax.transaction.UserTransaction getUserTransaction()
          Obtains the transaction demarcation interface.
 boolean isCallerInRole(java.security.Identity role)
          Deprecated. @throws java.lang.IllegalStateException for message driven bean because there is no security context available
 boolean isCallerInRole(java.lang.String roleLink)
          Test if the caller has a given role.
 void onMessage(javax.jms.Message message)
          A message has been received by the Session.
 void release()
           
 void run()
          Process messages by calling run method on Session.
 void setRollbackOnly()
          Marks the current transaction for rollback.
 void start()
          Cause the session's run method to be called to process messages that were just assigned to it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sess

protected javax.jms.Session sess

bf

protected JMdbFactory bf

mdb

protected javax.ejb.MessageDrivenBean mdb

txattr

protected int txattr
Transactional attribute for onMessage method. TX_NOT_SUPPORTED, TX_REQUIRED or TX_NOT_SET (= bean managed)


timerTxAttr

protected int timerTxAttr
Transactional attribute for ejbTimeout method. default is TX_REQUIRES_NEW


tm

protected org.objectweb.transaction.jta.TransactionManager tm

wm

protected javax.resource.spi.work.WorkManager wm
Constructor Detail

JMessageDrivenBean

public JMessageDrivenBean(JMdbFactory bf,
                          javax.jms.Session sess,
                          javax.ejb.MessageDrivenBean mdb,
                          javax.resource.spi.work.WorkManager wm)
constructor

Parameters:
bf - The MDB Factory
sess - The JMS Session
mdb - The Message Driven Bean
wm - The Work Manager
Method Detail

getTimerService

public javax.ejb.TimerService getTimerService()
                                       throws java.lang.IllegalStateException
Get access to the EJB Timer Service.

Specified by:
getTimerService in interface javax.ejb.EJBContext
Returns:
the EJB Timer Service
Throws:
java.lang.IllegalStateException - Thrown if the instance is not allowed to use this method

onMessage

public void onMessage(javax.jms.Message message)
A message has been received by the Session. Basically, we have to do: preInvoke + onMessage + postInvoke. No exception should be returned to the caller.

Specified by:
onMessage in interface javax.jms.MessageListener
Parameters:
message - The received message to handle.

getSession

public javax.jms.Session getSession()
                             throws javax.jms.JMSException
Return the ServerSession's Session. This must be a Session created by the same Connection which will be dispatching messages to it. The provider will assign one or more messages to the Session and then call start on the ServerSession.

Specified by:
getSession in interface javax.jms.ServerSession
Returns:
the server session's session.
Throws:
javax.jms.JMSException - - if a JMS fails to get associated session for this serverSession due to some internal error.

start

public void start()
           throws javax.jms.JMSException
Cause the session's run method to be called to process messages that were just assigned to it.

Specified by:
start in interface javax.jms.ServerSession
Throws:
javax.jms.JMSException - - if a JMS fails to start the server session to process messages.

run

public void run()
Process messages by calling run method on Session. When finished, return the object in the pool.

Specified by:
run in interface java.lang.Runnable

release

public void release()
Specified by:
release in interface javax.resource.spi.work.Work

getCallerIdentity

public java.security.Identity getCallerIdentity()
Deprecated. @exception java.lang.IllegalStateException always

Obtains the java.security.Identity of the caller. disallowed in messagedriven bean method because there is no security context

Specified by:
getCallerIdentity in interface javax.ejb.EJBContext

getCallerPrincipal

public java.security.Principal getCallerPrincipal()
Obtain the java.security.Principal that identifies the caller. throws a java.lang.IllegalStateException for message driven bean because there is no security context available (EJB v2.0, chapter 14.5.1)

Specified by:
getCallerPrincipal in interface javax.ejb.EJBContext
Throws:
java.lang.IllegalStateException - always

isCallerInRole

public boolean isCallerInRole(java.security.Identity role)
Deprecated. @throws java.lang.IllegalStateException for message driven bean because there is no security context available

Test if the caller has a given role.

Specified by:
isCallerInRole in interface javax.ejb.EJBContext

isCallerInRole

public boolean isCallerInRole(java.lang.String roleLink)
Test if the caller has a given role.

Specified by:
isCallerInRole in interface javax.ejb.EJBContext
Throws:
java.lang.IllegalStateException - for message driven bean because there is no security context available

setRollbackOnly

public void setRollbackOnly()
Marks the current transaction for rollback. Should be used only if the instance is associated with a transaction

Specified by:
setRollbackOnly in interface javax.ejb.EJBContext
Throws:
java.lang.IllegalStateException - if the instance is not associated with a transaction

getRollbackOnly

public boolean getRollbackOnly()
Tests if the transaction has been marked for rollback only.

Specified by:
getRollbackOnly in interface javax.ejb.EJBContext
Returns:
True if transaction has been marked for rollback.

getEJBHome

public javax.ejb.EJBHome getEJBHome()
Is disallowed. There is no home for message driven bean.

Specified by:
getEJBHome in interface javax.ejb.EJBContext
Throws:
java.lang.IllegalStateException - Always.

getEJBLocalHome

public javax.ejb.EJBLocalHome getEJBLocalHome()
Is disallowed. There is no local home for message driven bean.

Specified by:
getEJBLocalHome in interface javax.ejb.EJBContext
Throws:
java.lang.IllegalStateException - Always.

getEnvironment

public java.util.Properties getEnvironment()
Deprecated. Use the JNDI naming context java:comp/env instead.

Specified by:
getEnvironment in interface javax.ejb.EJBContext
Returns:
properties for the bean.

getUserTransaction

public javax.transaction.UserTransaction getUserTransaction()
                                                     throws java.lang.IllegalStateException
Obtains the transaction demarcation interface.

Specified by:
getUserTransaction in interface javax.ejb.EJBContext
Returns:
The UserTransaction interface that the enterprise bean instance can use for transaction demarcation.
Throws:
IllegalStateException: - Thrown if the instance container does not make the UserTransaction interface available to the instance.
java.lang.IllegalStateException

deliverTimeout

public void deliverTimeout(javax.ejb.Timer timer)
Deliver a timeout to the bean

Parameters:
timer - timer whose expiration caused this notification.