1 23 24 28 29 31 32 package com.sun.enterprise.management.support; 33 34 import java.util.Map ; 35 import java.util.HashMap ; 36 import java.util.Set ; 37 38 import javax.management.ObjectName ; 39 import javax.management.MBeanServer ; 40 import javax.management.JMException ; 41 import javax.management.MBeanInfo ; 42 import javax.management.MBeanOperationInfo ; 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 53 public final class SystemInfoImpl extends AMXImplBase 54 implements SystemInfo 55 { 56 private final MBeanServer mServer; 57 58 private BootUtil mBootUtil; 59 60 public static final String NAME_PROP_VALUE = "system-info"; 61 62 private final Map <String ,Boolean > mFeatures; 63 64 private final boolean 65 supportsClusters( ) 66 { 67 final ObjectName serversObjectName = getOldServersMBeanObjectName(); 68 69 boolean supportsClusters = false; 70 if ( serversObjectName != null ) 71 { 72 try 74 { 75 final MBeanInfo info = mServer.getMBeanInfo( serversObjectName ); 76 77 final String operationName = "listUnclusteredServerInstancesAsString"; 78 final Set operations = JMXUtil.findInfoByName( info.getOperations(), operationName ); 79 supportsClusters = operations.size() != 0; 80 81 } 82 catch( JMException e ) 83 { 84 throw new RuntimeException ( "problem with 'servers' MBean: " + serversObjectName, e ); 86 } 87 } 88 else 89 { 90 supportsClusters = true; 93 } 94 95 return( supportsClusters ); 96 } 97 98 101 private ObjectName 102 getOldServersMBeanObjectName() 103 { 104 final ObjectName pattern = 106 Util.newObjectName( "com.sun.appserv", "category=config,type=servers" ); 107 final Set <ObjectName > serversSet = JMXUtil.queryNames( mServer, pattern, null ); 108 109 final ObjectName objectName = serversSet.size() == 0 ? 110 null : (ObjectName )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 server, 124 final BootUtil bootUtil ) 125 { 126 super( ); 127 128 mServer = server; 129 mBootUtil = bootUtil; 130 131 mFeatures = new HashMap <String ,Boolean >(); 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 141 getGroup() 142 { 143 return( AMX.GROUP_UTILITY ); 144 } 145 146 private static final String [] FEATURE_NAMES = 147 new String [] 148 { 149 CLUSTERS_FEATURE, 150 MULTIPLE_SERVERS_FEATURE, 151 RUNNING_IN_DAS_FEATURE, 152 }; 153 154 public String [] 155 getFeatureNames() 156 { 157 return( (String [])FEATURE_NAMES.clone() ); 158 } 159 160 public boolean 161 supportsFeature( final String key ) 162 { 163 boolean supports = false; 164 165 Boolean 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 |