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