KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > management > j2ee > JMSResource


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.management.j2ee;
23
24 import org.jboss.logging.Logger;
25 import org.jboss.management.j2ee.statistics.JMSStatsImpl;
26
27 import javax.management.MBeanServer JavaDoc;
28 import javax.management.MalformedObjectNameException JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30 import javax.management.j2ee.statistics.Stats JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.Map JavaDoc;
33
34 /**
35  * Root class of the JBoss JSR-77 implementation of the JMSResource model
36  *
37  * @author <a HREF="mailto:mclaugs@comcast.net">Scott McLaughlin</a>.
38  * @author <a HREF="mailto:thomas.diesler@jboss.org">Thomas Diesler</a>
39  * @version $Revision: 40550 $
40  */

41 public class JMSResource extends J2EEResource
42    implements JMSResourceMBean
43 {
44    // Constants -----------------------------------------------------
45
private static Logger log = Logger.getLogger(JMSResource.class);
46
47    // Attributes ----------------------------------------------------
48

49    private ObjectName JavaDoc jmsServiceName;
50    private JMSStatsImpl stats;
51
52    // Static --------------------------------------------------------
53

54    public static ObjectName JavaDoc create(MBeanServer JavaDoc mbeanServer, String JavaDoc resName,
55                                    ObjectName JavaDoc jmsServiceName)
56    {
57       ObjectName JavaDoc j2eeServerName = J2EEDomain.getDomainServerName(mbeanServer);
58       ObjectName JavaDoc jsr77Name = null;
59       try
60       {
61          JMSResource jmsRes = new JMSResource(resName, j2eeServerName, jmsServiceName);
62          jsr77Name = jmsRes.getObjectName();
63          mbeanServer.registerMBean(jmsRes, jsr77Name);
64          log.debug("Created JSR-77 JMSResource: " + resName);
65       }
66       catch (Exception JavaDoc e)
67       {
68          log.debug("Could not create JSR-77 JMSResource: " + resName, e);
69       }
70       return jsr77Name;
71    }
72
73    public static void destroy(MBeanServer JavaDoc pServer, String JavaDoc pName)
74    {
75       try
76       {
77          J2EEManagedObject.removeObject(pServer,
78                  J2EEDomain.getDomainName() + ":" +
79                  J2EEManagedObject.TYPE + "=" + J2EETypeConstants.JMSResource + "," +
80                  "name=" + pName + "," +
81                  "*");
82       }
83       catch (Exception JavaDoc e)
84       {
85          log.error("Could not destroy JSR-77 JMSResource Resource", e);
86       }
87    }
88
89    // -------------------------------------------------------------------------
90
// Constructors
91
// -------------------------------------------------------------------------
92

93    /**
94     * @param pName Name of the JMSResource
95     * @throws InvalidParameterException If list of nodes or ports was null or empty
96     */

97    public JMSResource(String JavaDoc resName, ObjectName JavaDoc j2eeServerName,
98                       ObjectName JavaDoc jmsServiceName)
99            throws MalformedObjectNameException JavaDoc,
100            InvalidParentException
101    {
102       super(J2EETypeConstants.JMSResource, resName, j2eeServerName);
103       this.jmsServiceName = jmsServiceName;
104       stats = new JMSStatsImpl(null);
105    }
106
107    // Begin StatisticsProvider interface methods
108

109    /**
110     * Obtain the Stats from the StatisticsProvider.
111     *
112     * @return An JMSStats subclass
113     * @jmx:managed-attribute
114     */

115    public Stats JavaDoc getstats()
116    {
117       try
118       {
119          // Obtain the current clients Map<ConnectionToken, ClientConsumer>
120
Map JavaDoc clients = (Map JavaDoc) server.getAttribute(jmsServiceName, "Clients");
121          Iterator JavaDoc iter = clients.keySet().iterator();
122       }
123       catch (Exception JavaDoc e)
124       {
125          log.debug("Failed to obtain stats", e);
126       }
127       return stats;
128    }
129
130    /**
131     * Reset all statistics in the StatisticsProvider
132     *
133     * @jmx:managed-operation
134     */

135    public void resetStats()
136    {
137       stats.reset();
138    }
139    // End StatisticsProvider interface methods
140

141
142    // java.lang.Object overrides ------------------------------------
143

144    public String JavaDoc toString()
145    {
146       return "JMSResource { " + super.toString() + " } []";
147    }
148 }
149
Popular Tags