1 23 24 28 29 31 32 package com.sun.enterprise.management.support; 33 34 import java.io.IOException ; 35 36 import javax.management.ObjectName ; 37 import javax.management.MBeanServer ; 38 import javax.management.MBeanServerConnection ; 39 import javax.management.MBeanInfo ; 40 import javax.management.AttributeList ; 41 import javax.management.Attribute ; 42 import javax.management.AttributeNotFoundException ; 43 import javax.management.InvalidAttributeValueException ; 44 import javax.management.InstanceNotFoundException ; 45 import javax.management.IntrospectionException ; 46 import javax.management.ReflectionException ; 47 48 import com.sun.appserv.management.util.jmx.stringifier.MBeanInfoStringifier; 49 50 53 public class DelegateToMBeanDelegate extends DelegateBase 54 { 55 private final ObjectName mTarget; 56 private final MBeanServerConnection mConn; 57 private final MBeanInfo mTargetMBeanInfo; 58 59 public 60 DelegateToMBeanDelegate( 61 final MBeanServerConnection conn, 62 final ObjectName target) 63 throws InstanceNotFoundException , IntrospectionException , ReflectionException , 64 IOException 65 { 66 super( "DelegateToMBeanDelegate." + target.toString(), null ); 67 68 mConn = conn; 69 mTarget = target; 70 71 mTargetMBeanInfo = mConn.getMBeanInfo( target ); 72 } 73 74 public 75 DelegateToMBeanDelegate( 76 final MBeanServer server, 77 final ObjectName target) 78 throws InstanceNotFoundException , IntrospectionException , ReflectionException 79 { 80 super( "DelegateToMBeanDelegate." + target.toString(), null); 81 82 mConn = server; 83 mTarget = target; 84 85 mTargetMBeanInfo = server.getMBeanInfo( target ); 86 87 } 90 91 public ObjectName 92 getTarget() 93 { 94 return( mTarget ); 95 } 96 97 public MBeanServerConnection 98 getMBeanServerConnection() 99 { 100 return( mConn ); 101 } 102 103 public Object 104 getAttribute( final String attrName ) 105 throws AttributeNotFoundException 106 { 107 try 108 { 109 final Object value = 110 getMBeanServerConnection().getAttribute( mTarget, attrName ); 111 return( value ); 112 } 113 catch( Exception e ) 114 { 115 e.printStackTrace(); 116 throw new RuntimeException ( e ); 117 } 118 } 119 120 public void 121 setAttribute( final Attribute attr ) 122 throws AttributeNotFoundException , InvalidAttributeValueException 123 { 124 try 125 { 126 getMBeanServerConnection().setAttribute( mTarget, attr ); 127 } 128 catch( Exception e ) 129 { 130 throw new RuntimeException ( e ); 131 } 132 } 133 134 public MBeanInfo 135 getMBeanInfo() 136 { 137 return( mTargetMBeanInfo ); 138 } 139 140 141 142 private void 143 delegateFailed( final Throwable t ) 144 { 145 if ( getOwner() != null ) 146 { 147 getOwner().delegateFailed( t ); 148 } 149 } 150 151 153 public final Object 154 invoke( 155 String operationName, 156 Object [] args, 157 String [] types ) 158 { 159 try 160 { 161 final Object result = getMBeanServerConnection().invoke( getTarget(), 162 operationName, args, types ); 163 164 return( result ); 165 } 166 catch ( InstanceNotFoundException e ) 167 { 168 delegateFailed( e ); 169 throw new RuntimeException ( e ); 170 } 171 catch ( IOException e ) 172 { 173 try 174 { 175 getMBeanServerConnection().isRegistered( getTarget() ); 176 } 177 catch( IOException ee ) 178 { 179 delegateFailed( e ); 180 } 181 throw new RuntimeException ( e ); 182 } 183 catch( Exception e ) 184 { 185 throw new RuntimeException ( e ); 186 } 187 } 188 } 189 190 191 192 193 194 195 196 197 | Popular Tags |