KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > support > SystemInfoImpl


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 /*
25  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28  
29 /*
30  */

31
32 package com.sun.enterprise.management.support;
33
34 import java.util.Map JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import java.util.Set JavaDoc;
37
38 import javax.management.ObjectName JavaDoc;
39 import javax.management.MBeanServer JavaDoc;
40 import javax.management.JMException JavaDoc;
41 import javax.management.MBeanInfo JavaDoc;
42 import javax.management.MBeanOperationInfo JavaDoc;
43
44 import com.sun.appserv.management.base.AMX;
45 import com.sun.appserv.management.base.XTypes;
46 import com.sun.appserv.management.base.SystemInfo;
47 import com.sun.appserv.management.base.Util;
48 import com.sun.appserv.management.util.misc.GSetUtil;
49 import com.sun.appserv.management.util.jmx.JMXUtil;
50
51 /**
52  */

53 public final class SystemInfoImpl extends AMXImplBase
54     implements SystemInfo
55 {
56     private final MBeanServer JavaDoc mServer;
57     
58     private BootUtil mBootUtil;
59     
60     public static final String JavaDoc NAME_PROP_VALUE = "system-info";
61     
62     private final Map JavaDoc<String JavaDoc,Boolean JavaDoc> mFeatures;
63     
64         private final boolean
65     supportsClusters( )
66     {
67         final ObjectName JavaDoc serversObjectName = getOldServersMBeanObjectName();
68         
69         boolean supportsClusters = false;
70         if ( serversObjectName != null )
71         {
72             // see if the 'servers' MBean supports listing unclustered instances
73
try
74             {
75                 final MBeanInfo JavaDoc info = mServer.getMBeanInfo( serversObjectName );
76                 
77                 final String JavaDoc operationName = "listUnclusteredServerInstancesAsString";
78                 final Set JavaDoc operations = JMXUtil.findInfoByName( info.getOperations(), operationName );
79                 supportsClusters = operations.size() != 0;
80                 
81             }
82             catch( JMException JavaDoc e )
83             {
84                 // should never happen...
85
throw new RuntimeException JavaDoc( "problem with 'servers' MBean: " + serversObjectName, e );
86             }
87         }
88         else
89         {
90             // presumably, we're in another instance, which implies multiple instances.
91
// assume this also means clustering is possible
92
supportsClusters = true;
93         }
94         
95         return( supportsClusters );
96     }
97     
98     /**
99         Get the ObjectName of the "type=servers" MBean, which only exists in the DAS.
100      */

101         private ObjectName JavaDoc
102     getOldServersMBeanObjectName()
103     {
104         // if we find the old "servers" MBean, it should only be running in the DAS.
105
final ObjectName JavaDoc pattern =
106                 Util.newObjectName( "com.sun.appserv", "category=config,type=servers" );
107         final Set JavaDoc<ObjectName JavaDoc> serversSet = JMXUtil.queryNames( mServer, pattern, null );
108         
109         final ObjectName JavaDoc objectName = serversSet.size() == 0 ?
110                     null : (ObjectName JavaDoc)GSetUtil.getSingleton( serversSet );
111                     
112         return( objectName );
113     }
114     
115         private boolean
116     isRunningInDomainAdminServer()
117     {
118         return( getOldServersMBeanObjectName() != null );
119     }
120     
121         public
122     SystemInfoImpl(
123         final MBeanServer JavaDoc server,
124         final BootUtil bootUtil )
125     {
126         super( );
127         
128         mServer = server;
129         mBootUtil = bootUtil;
130         
131         mFeatures = new HashMap JavaDoc<String JavaDoc,Boolean JavaDoc>();
132         
133         final boolean supportsClusters = supportsClusters( );
134         
135         mFeatures.put( CLUSTERS_FEATURE, Boolean.valueOf( supportsClusters ));
136         mFeatures.put( MULTIPLE_SERVERS_FEATURE, Boolean.valueOf( supportsClusters ));
137         mFeatures.put( RUNNING_IN_DAS_FEATURE, Boolean.valueOf( isRunningInDomainAdminServer() ) );
138     }
139     
140         public final String JavaDoc
141     getGroup()
142     {
143         return( AMX.GROUP_UTILITY );
144     }
145     
146     private static final String JavaDoc[] FEATURE_NAMES =
147         new String JavaDoc[]
148         {
149             CLUSTERS_FEATURE,
150             MULTIPLE_SERVERS_FEATURE,
151             RUNNING_IN_DAS_FEATURE,
152         };
153     
154         public String JavaDoc[]
155     getFeatureNames()
156     {
157         return( (String JavaDoc[])FEATURE_NAMES.clone() );
158     }
159     
160         public boolean
161     supportsFeature( final String JavaDoc key )
162     {
163         boolean supports = false;
164         
165         Boolean JavaDoc result = mFeatures.get( key );
166         if ( result == null )
167         {
168             result = Boolean.FALSE;
169         }
170         
171         return( result.booleanValue() );
172     }
173     
174 }
175
176
177
178
179
180
181
182
183
Popular Tags