1 22 package org.jboss.ejb3.test.dd.mdb; 23 24 import javax.annotation.Resource; 25 import javax.ejb.MessageDrivenBean ; 26 import javax.ejb.MessageDrivenContext ; 27 import javax.ejb.EJBException ; 28 29 import javax.jms.JMSException ; 30 import javax.jms.MessageListener ; 31 import javax.jms.Message ; 32 import javax.naming.InitialContext ; 33 import javax.transaction.Status ; 34 import javax.transaction.Transaction ; 35 import javax.transaction.TransactionManager ; 36 import javax.transaction.xa.XAResource ; 37 38 public class BMPBean implements MessageDrivenBean , MessageListener { 39 org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass()); 40 41 private MessageDrivenContext ctx = null; 42 public BMPBean() { 43 44 } 45 46 @Resource 47 public void setMessageDrivenContext(MessageDrivenContext ctx) throws EJBException 48 { 49 this.ctx = ctx; 50 } 51 52 public void ejbCreate() {} 53 54 public void ejbRemove() {ctx=null;} 55 56 public void onMessage(Message message) 57 { 58 log.debug("DEBUG: BMPBean got message" + message.toString() ); 59 60 try 61 { 62 TestStatusBean.addDestination(message.getJMSDestination()); 63 TransactionManager tm = (TransactionManager )new InitialContext ().lookup("java:/TransactionManager"); 64 Transaction threadTx = tm.suspend(); 65 log.debug("DEBUG Tx="+threadTx); 66 67 log.debug("Sleeping for 10 seconds"); 68 try 69 { 70 Thread.currentThread().sleep(1000*10); 71 } 72 catch ( InterruptedException e ) 73 { 74 } 75 log.debug("Sleep done"); 76 77 if( threadTx != null ) tm.resume(threadTx); 78 } 79 catch (Exception e) 80 { 81 log.debug("BMPBean Error:"+e); 82 } 83 } 84 } 85 86 87 | Popular Tags |