1 23 24 29 30 31 package com.sun.enterprise.admin.dottedname; 32 33 import java.util.HashSet ; 34 import java.util.Set ; 35 import java.util.Collections ; 36 37 import javax.management.ObjectName ; 38 import javax.management.MalformedObjectNameException ; 39 import javax.management.AttributeNotFoundException ; 40 import javax.management.Attribute ; 41 import javax.management.MBeanServerConnection ; 42 import javax.management.ReflectionException ; 43 import javax.management.InstanceNotFoundException ; 44 import javax.management.MBeanException ; 45 46 import com.sun.enterprise.admin.util.ArrayConversion; 47 48 import com.sun.enterprise.admin.common.ObjectNames; 49 50 51 import javax.management.MBeanServerInvocationHandler ; 52 53 54 59 public class DottedNameServerInfoImpl implements DottedNameServerInfo 60 { 61 final MBeanServerConnection mConn; 62 63 64 public 65 DottedNameServerInfoImpl( MBeanServerConnection conn ) 66 { 67 mConn = conn; 68 } 69 70 ObjectName 71 getControllerObjectName() 72 { 73 return( ObjectNames.getControllerObjectName() ); 74 } 75 76 ObjectName 77 getConfigsObjectName() 78 throws MalformedObjectNameException 79 { 80 return( new ObjectName ( "com.sun.appserv:type=configs,category=config" ) ); 81 } 82 83 ObjectName 84 getServerObjectName( final String serverName ) 85 { 86 return( ObjectNames.getServerObjectName( serverName ) ); 87 } 88 89 90 Set 91 _getConfigNames() 92 throws ReflectionException , InstanceNotFoundException , MBeanException , java.io.IOException , 93 MalformedObjectNameException , AttributeNotFoundException 94 { 95 final ObjectName [] configObjectNames = 98 (ObjectName [])mConn.invoke( getConfigsObjectName(), "getConfig", null, null ); 99 100 final HashSet configNames = new HashSet (); 101 for( int i = 0; i < configObjectNames.length; ++i ) 102 { 103 final String name = (String )mConn.getAttribute( configObjectNames[ i ], "name" ); 104 105 configNames.add( name ); 106 } 107 108 return( configNames ); 109 } 110 111 public Set 112 getConfigNames() 113 throws DottedNameServerInfo.UnavailableException 114 { 115 Set namesSet = null; 116 117 try 118 { 119 namesSet = _getConfigNames(); 120 } 121 catch( Exception e ) 122 { 123 throw new DottedNameServerInfo.UnavailableException( e ); 124 } 125 126 return( namesSet ); 127 } 128 129 private interface MyController 131 { 132 String [] listServerInstances(); 133 }; 134 135 protected Set 136 _getServerNames() 137 throws ReflectionException , InstanceNotFoundException , MBeanException , java.io.IOException 138 { 139 final MyController controller = (MyController) 140 MBeanServerInvocationHandler.newProxyInstance( mConn, getControllerObjectName(), MyController.class, false ); 141 142 final String [] names = controller.listServerInstances(); 143 144 return( ArrayConversion.toSet( names ) ); 145 } 146 147 public Set 148 getServerNames() 149 throws DottedNameServerInfo.UnavailableException 150 { 151 Set namesSet = null; 152 153 try 154 { 155 namesSet = _getServerNames(); 156 } 157 catch( Exception e ) 158 { 159 throw new DottedNameServerInfo.UnavailableException( e ); 160 } 161 162 return( namesSet ); 163 } 164 165 public String 166 getConfigNameForServer( String serverName ) 167 throws DottedNameServerInfo.UnavailableException 168 { 169 final ObjectName serverObjectName = getServerObjectName( serverName ); 170 171 if ( serverObjectName == null ) 172 { 173 throw new DottedNameServerInfo.UnavailableException( serverObjectName.toString() ); 174 } 175 176 String configName = null; 177 try 178 { 179 configName = (String )mConn.getAttribute( serverObjectName, "config_ref" ); 180 } 181 catch( Exception e ) 182 { 183 throw new DottedNameServerInfo.UnavailableException( e ); 184 } 185 186 return( configName ); 187 } 188 189 public String [] 190 getServerNamesForConfig( String configName ) 191 throws DottedNameServerInfo.UnavailableException 192 { 193 final java.util.Iterator iter = getServerNames().iterator(); 194 final java.util.ArrayList namesOut = new java.util.ArrayList (); 195 196 while ( iter.hasNext() ) 197 { 198 final String serverName = (String )iter.next(); 199 200 if ( configName.equals( getConfigNameForServer( serverName ) ) ) 201 { 202 namesOut.add( serverName ); 203 } 204 } 205 206 final String [] namesOutArray = new String [ namesOut.size() ]; 207 namesOut.toArray( namesOutArray ); 208 209 return( namesOutArray ); 210 } 211 } 212 213 214 215 216 217 218 219 220 221 | Popular Tags |