1 22 package org.jboss.test.messagedriven.mbeans; 23 24 import java.util.ArrayList ; 25 import java.util.Enumeration ; 26 import java.util.Properties ; 27 28 import javax.jms.Message ; 29 import javax.naming.InitialContext ; 30 import javax.transaction.Transaction ; 31 import javax.transaction.TransactionManager ; 32 33 import org.jboss.system.ServiceMBeanSupport; 34 35 41 public class TestMessageDrivenManagement extends ServiceMBeanSupport implements TestMessageDrivenManagementMBean 42 { 43 private static final Properties defaultProps = new Properties (); 44 45 private TransactionManager tm; 46 47 static 48 { 49 defaultProps.put("destination", "NotSpecified"); 50 defaultProps.put("destinationType", "NotSpecified"); 51 defaultProps.put("transactionType", "Container"); 52 defaultProps.put("transactionAttribute", "Required"); 53 defaultProps.put("rollback", "None"); 54 defaultProps.put("DLQMaxResent", "5"); 55 defaultProps.put("DeliveryActive", "true"); 56 defaultProps.put("durability", "NonDurable"); 57 defaultProps.put("subscriptionName", ""); 58 defaultProps.put("user", "guest"); 59 defaultProps.put("password", "guest"); 60 } 61 62 protected ArrayList messages = new ArrayList (); 63 64 public TestMessageDrivenManagement() throws Exception 65 { 66 tm = (TransactionManager ) new InitialContext ().lookup("java:/TransactionManager"); 67 } 68 69 public void initProperties(Properties props) 70 { 71 setProperties(defaultProps); 72 setProperties(props); 73 } 74 75 public void addMessage(Message message) 76 { 77 synchronized (messages) 78 { 79 messages.add(message); 80 } 81 } 82 83 public ArrayList getMessages() 84 { 85 synchronized (messages) 86 { 87 ArrayList result = new ArrayList (messages); 88 messages.clear(); 89 return result; 90 } 91 } 92 93 public Transaction getTransaction() 94 { 95 Transaction tx = null; 96 try 97 { 98 tx = tm.getTransaction(); 99 } 100 catch (Throwable ignored) 101 { 102 } 103 return tx; 104 } 105 106 protected void setProperties(Properties props) 107 { 108 for (Enumeration e = props.keys(); e.hasMoreElements();) 109 { 110 String key = (String ) e.nextElement(); 111 System.setProperty("test.messagedriven." + key, props.getProperty(key)); 112 } 113 } 114 } 115 | Popular Tags |