KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > messagedriven > mbeans > TestMessageDrivenManagement


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.messagedriven.mbeans;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Enumeration JavaDoc;
26 import java.util.Properties JavaDoc;
27
28 import javax.jms.Message JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30 import javax.transaction.Transaction JavaDoc;
31 import javax.transaction.TransactionManager JavaDoc;
32
33 import org.jboss.system.ServiceMBeanSupport;
34
35 /**
36  * Management of the test message driven bean
37  *
38  * @author <a HREF="mailto:adrian@jboss.com>Adrian Brock</a>
39  * @version <tt>$Revision: 1.4</tt>
40  */

41 public class TestMessageDrivenManagement extends ServiceMBeanSupport implements TestMessageDrivenManagementMBean
42 {
43    private static final Properties JavaDoc defaultProps = new Properties JavaDoc();
44    
45    private TransactionManager JavaDoc 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 JavaDoc messages = new ArrayList JavaDoc();
63    
64    public TestMessageDrivenManagement() throws Exception JavaDoc
65    {
66       tm = (TransactionManager JavaDoc) new InitialContext JavaDoc().lookup("java:/TransactionManager");
67    }
68    
69    public void initProperties(Properties JavaDoc props)
70    {
71       setProperties(defaultProps);
72       setProperties(props);
73    }
74    
75    public void addMessage(Message JavaDoc message)
76    {
77       synchronized (messages)
78       {
79          messages.add(message);
80       }
81    }
82    
83    public ArrayList JavaDoc getMessages()
84    {
85       synchronized (messages)
86       {
87          ArrayList JavaDoc result = new ArrayList JavaDoc(messages);
88          messages.clear();
89          return result;
90       }
91    }
92    
93    public Transaction JavaDoc getTransaction()
94    {
95       Transaction JavaDoc tx = null;
96       try
97       {
98          tx = tm.getTransaction();
99       }
100       catch (Throwable JavaDoc ignored)
101       {
102       }
103       return tx;
104    }
105    
106    protected void setProperties(Properties JavaDoc props)
107    {
108       for (Enumeration JavaDoc e = props.keys(); e.hasMoreElements();)
109       {
110          String JavaDoc key = (String JavaDoc) e.nextElement();
111          System.setProperty("test.messagedriven." + key, props.getProperty(key));
112       }
113    }
114 }
115
Popular Tags