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