KickJava   Java API By Example, From Geeks To Geeks.

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


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.Util;
35 import com.sun.appserv.management.base.AMX;
36 import com.sun.appserv.management.j2ee.J2EETypes;
37 import com.sun.appserv.management.util.misc.GSetUtil;
38
39 import com.sun.appserv.management.monitor.ServerRootMonitor;
40 import com.sun.appserv.management.monitor.CallFlowMonitor;
41
42 import com.sun.enterprise.management.support.ObjectNames;
43 import com.sun.enterprise.management.support.BootUtil;
44
45
46
47 /**
48 */

49 public final class ServerRootMonitorImpl
50     extends MonitoringImplBase
51     // implements ServerRootMonitor
52
{
53     public ServerRootMonitorImpl()
54     {
55         super( XTypes.SERVER_ROOT_MONITOR );
56     }
57
58     
59         public Map JavaDoc<String JavaDoc,ObjectName JavaDoc>
60     getORBConnectionManagerMonitorObjectNameMap()
61     {
62         return( getContaineeObjectNameMap( XTypes.CONNECTION_MANAGER_MONITOR ) );
63     }
64     
65     
66     private static final Set JavaDoc<String JavaDoc> NOT_SUPERFLUOUS =
67         GSetUtil.newUnmodifiableStringSet(
68             "getCallFlowMonitorObjectName",
69             "getORBConnectionManagerMonitorObjectNameMap"
70         );
71         protected final Set JavaDoc<String JavaDoc>
72     getNotSuperfluousMethods()
73     {
74         return GSetUtil.newSet( super.getNotSuperfluousMethods(), NOT_SUPERFLUOUS );
75     }
76     
77     
78         protected void
79     registerMisc()
80     {
81         super.registerMisc();
82         
83         if ( getLoader().isDAS() )
84         {
85             if ( ( BootUtil.getInstance().getServerName().equals( getName() ) ) )
86             {
87                 // this is the ServerRootMonitor for the DAS.
88
registerCallFlow();
89             }
90         }
91         else
92         {
93             // they should be cascaded from other instances
94
// and ServerRootMonitorImpl does not exist there.
95
throw new RuntimeException JavaDoc( "ServerRootMonitorImpl expected in DAS only" );
96         }
97
98     }
99     
100         public final ObjectName JavaDoc
101     getCallFlowMonitorObjectName()
102     {
103         return getContaineeObjectName( XTypes.CALL_FLOW_MONITOR );
104     }
105     
106         protected void
107     unregisterMisc()
108     {
109         if ( getLoader().isDAS() )
110         {
111             try
112             {
113                 getMBeanServer().unregisterMBean( getCallFlowMonitorObjectName() );
114             }
115             catch( JMException JavaDoc e )
116             {
117                 logWarning( "ServerRootMonitorImpl: exception unregistering CallFlowMonitor: " + e);
118             }
119         }
120     }
121     
122         protected final void
123     registerCallFlow()
124     {
125         final ObjectNames objectNames = ObjectNames.getInstance( getJMXDomain() );
126         final ObjectName JavaDoc childObjectName =
127             objectNames.buildContaineeObjectName( getObjectName(),
128                 getFullType(), XTypes.CALL_FLOW_MONITOR,
129                     getName() );
130         
131         final CallFlowMonitorImpl callFlow = new CallFlowMonitorImpl();
132         try
133         {
134             debug( "Loading CallFlowMonitor for DAS: " + childObjectName );
135             getMBeanServer().registerMBean( callFlow, childObjectName );
136         }
137         catch( JMException JavaDoc e )
138         {
139             logWarning( "ServerRootMonitor: Can't load CallFlow" );
140         }
141     }
142     
143     final Set JavaDoc<String JavaDoc> FAUX_CONTAINEE_TYPES =
144         GSetUtil.newUnmodifiableStringSet(
145             XTypes.EJB_MODULE_MONITOR,
146             XTypes.WEB_MODULE_VIRTUAL_SERVER_MONITOR
147             );
148         
149         protected Set JavaDoc<String JavaDoc>
150     getFauxChildTypes()
151     {
152         return( FAUX_CONTAINEE_TYPES );
153     }
154     
155     
156     
157     /*
158         Override default behavior to find modules that belong to ServerRootMonitor directly
159         because X-ApplicationMonitor=null.
160      */

161         public final Set JavaDoc<ObjectName JavaDoc>
162     getContaineeObjectNameSet( final String JavaDoc childJ2EEType )
163     {
164         final Set JavaDoc<ObjectName JavaDoc> result = super.getContaineeObjectNameSet( childJ2EEType );
165         
166         if ( getFauxChildTypes().contains( childJ2EEType ) )
167         {
168             final String JavaDoc nullAppMonitorProp = Util.makeProp( XTypes.APPLICATION_MONITOR, AMX.NULL_NAME );
169
170             final Set JavaDoc<ObjectName JavaDoc> fauxContainees = getFauxContaineeObjectNameSet( childJ2EEType, nullAppMonitorProp);
171             result.addAll( fauxContainees );
172         }
173         
174         return( result );
175     }
176 }
177
Popular Tags