KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > monitor > JMXMonitorMgrImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.management.monitor;
25
26 import java.util.Map JavaDoc;
27 import java.util.Set JavaDoc;
28 import java.util.Collections JavaDoc;
29
30 import javax.management.ObjectName JavaDoc;
31 import javax.management.JMException JavaDoc;
32
33 import com.sun.appserv.management.base.XTypes;
34 import com.sun.appserv.management.base.AMX;
35 import com.sun.appserv.management.base.Util;
36 import com.sun.appserv.management.monitor.JMXMonitorMgr;
37 import com.sun.appserv.management.util.misc.GSetUtil;
38
39 import com.sun.enterprise.management.support.AMXImplBase;
40 import com.sun.enterprise.management.support.Delegate;
41
42
43 /**
44 */

45 public final class JMXMonitorMgrImpl extends AMXImplBase
46     // implements JMXMonitorMgr
47
{
48         public
49     JMXMonitorMgrImpl()
50     {
51     }
52     
53     
54     private static final Set JavaDoc<String JavaDoc> NOT_SUPERFLUOUS =
55         GSetUtil.newUnmodifiableStringSet(
56             "getCounterMonitorObjectNameMap",
57             "getGaugeMonitorObjectNameMap",
58             "getStringMonitorObjectNameMap"
59         );
60             
61             
62         protected final Set JavaDoc<String JavaDoc>
63     getNotSuperfluousMethods()
64     {
65         return GSetUtil.newSet( super.getNotSuperfluousMethods(), NOT_SUPERFLUOUS );
66     }
67     
68         public String JavaDoc
69     getGroup()
70     {
71         return( AMX.GROUP_UTILITY );
72     }
73     
74         private ObjectName JavaDoc
75     registerMonitor(
76         final Object JavaDoc impl,
77         final String JavaDoc j2eeType,
78         final String JavaDoc name )
79     {
80         final ObjectName JavaDoc self = getObjectName();
81         
82         final String JavaDoc domain = self.getDomain();
83         final String JavaDoc requiredProps = Util.makeRequiredProps( j2eeType, name );
84         
85         ObjectName JavaDoc objectName = Util.newObjectName( domain, requiredProps );
86         try
87         {
88             objectName = registerMBean( impl, objectName );
89         }
90         catch( Exception JavaDoc e )
91         {
92             throw new RuntimeException JavaDoc( e );
93         }
94         
95         return( objectName );
96     }
97     
98         public ObjectName JavaDoc
99     createStringMonitor( final String JavaDoc name )
100     {
101         final AMXStringMonitorImpl monitor = new AMXStringMonitorImpl();
102         return( registerMonitor( monitor, XTypes.JMX_STRING_MONITOR, name ) );
103     }
104     
105         public ObjectName JavaDoc
106     createCounterMonitor( final String JavaDoc name )
107     {
108         final AMXCounterMonitorImpl monitor = new AMXCounterMonitorImpl();
109         return( registerMonitor( monitor, XTypes.JMX_COUNTER_MONITOR, name ) );
110     }
111     
112         public ObjectName JavaDoc
113     createGaugeMonitor( final String JavaDoc name )
114     {
115         final AMXGaugeMonitorImpl monitor = new AMXGaugeMonitorImpl();
116         return( registerMonitor( monitor, XTypes.JMX_GAUGE_MONITOR, name ) );
117     }
118     
119     
120         private Map JavaDoc<String JavaDoc,ObjectName JavaDoc>
121     getMap( final String JavaDoc j2eeType )
122     {
123         final Map JavaDoc<String JavaDoc,AMX> m = getDomainRoot().getContaineeMap( j2eeType );
124         
125         return( Util.toObjectNames( m ) );
126     }
127     
128         public Map JavaDoc<String JavaDoc,ObjectName JavaDoc>
129     getStringMonitorObjectNameMap()
130     {
131         return( getMap( XTypes.JMX_STRING_MONITOR ) );
132     }
133     
134         public Map JavaDoc<String JavaDoc,ObjectName JavaDoc>
135     getCounterMonitorObjectNameMap()
136     {
137         return( getMap( XTypes.JMX_COUNTER_MONITOR ) );
138     }
139     
140         public Map JavaDoc<String JavaDoc,ObjectName JavaDoc>
141     getGaugeMonitorObjectNameMap()
142     {
143         return( getMap( XTypes.JMX_GAUGE_MONITOR ) );
144     }
145     
146     static private final Set JavaDoc<String JavaDoc> TYPES =
147         GSetUtil.newUnmodifiableStringSet(
148             //XTypes.JMX_GAUGE_MONITOR,
149
//XTypes.JMX_COUNTER_MONITOR,
150
XTypes.JMX_STRING_MONITOR
151         );
152             
153     
154         private ObjectName JavaDoc
155     getMonitor( final String JavaDoc name )
156     {
157         final Set JavaDoc<AMX> s = getDomainRoot().getByNameContaineeSet( TYPES, name );
158         
159         final AMX mon = Util.asAMX( GSetUtil.getSingleton( s ));
160         
161         return( Util.getObjectName( mon ) );
162     }
163     
164         public void
165     remove( final String JavaDoc name )
166     {
167         final ObjectName JavaDoc objectName = getMonitor( name );
168         if ( objectName == null )
169         {
170             throw new IllegalArgumentException JavaDoc( name );
171         }
172         
173         try
174         {
175             getMBeanServer().unregisterMBean( objectName );
176         }
177         catch( JMException JavaDoc e )
178         {
179             throw new RuntimeException JavaDoc( e );
180         }
181     }
182 }
183
184
185
186
187
188
189
190
191
192
193
194
195
Popular Tags