1 7 8 package javax.management.remote; 9 10 import java.io.IOException ; 11 import java.net.MalformedURLException ; 12 import java.util.Collections ; 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.Map ; 16 17 import javax.management.MBeanServer ; 18 import javax.management.ObjectName ; 19 20 import com.sun.jmx.remote.util.ClassLogger; 21 import com.sun.jmx.remote.util.EnvHelp; 22 23 139 public class JMXConnectorServerFactory { 140 141 148 public static final String DEFAULT_CLASS_LOADER = 149 JMXConnectorFactory.DEFAULT_CLASS_LOADER; 150 151 158 public static final String DEFAULT_CLASS_LOADER_NAME = 159 "jmx.remote.default.class.loader.name"; 160 161 167 public static final String PROTOCOL_PROVIDER_PACKAGES = 168 "jmx.remote.protocol.provider.pkgs"; 169 170 176 public static final String PROTOCOL_PROVIDER_CLASS_LOADER = 177 "jmx.remote.protocol.provider.class.loader"; 178 179 private static final String PROTOCOL_PROVIDER_DEFAULT_PACKAGE = 180 "com.sun.jmx.remote.protocol"; 181 182 private static final ClassLogger logger = 183 new ClassLogger("javax.management.remote.misc","JMXConnectorServerFactory"); 184 185 186 private JMXConnectorServerFactory() { 187 } 188 189 private static JMXConnectorServer 190 getConnectorServerAsService(ClassLoader loader, 191 JMXServiceURL url, 192 Map map, 193 MBeanServer mbs) 194 throws IllegalArgumentException , JMXProviderException { 195 Iterator providers = 196 JMXConnectorFactory.getProviderIterator(JMXConnectorServerProvider .class, 197 loader); 198 JMXConnectorServerProvider provider = null; 199 JMXConnectorServer connection = null; 200 while(providers.hasNext()) { 201 provider = 202 (JMXConnectorServerProvider ) providers.next(); 203 try { 204 connection = provider.newJMXConnectorServer(url, map, mbs); 205 return connection; 206 } catch (JMXProviderException e) { 207 throw e; 208 } 209 catch (Exception e) { 210 if (logger.traceOn()) 211 logger.trace("getConnectorAsService", 212 "URL[" + url + 213 "] Service provider exception " + e); 214 continue; 215 } 216 } 217 return null; 218 } 219 220 257 public static JMXConnectorServer 258 newJMXConnectorServer(JMXServiceURL serviceURL, 259 Map <String ,?> environment, 260 MBeanServer mbeanServer) 261 throws IOException { 262 if (environment == null) 263 environment = new HashMap (); 264 else { 265 EnvHelp.checkAttributes(environment); 266 environment = new HashMap (environment); 267 } 268 269 final Class targetInterface = JMXConnectorServerProvider .class; 270 final ClassLoader loader = 271 JMXConnectorFactory.resolveClassLoader(environment); 272 final String protocol = serviceURL.getProtocol(); 273 final String providerClassName = "ServerProvider"; 274 275 JMXConnectorServerProvider provider = 276 (JMXConnectorServerProvider ) 277 JMXConnectorFactory.getProvider(serviceURL, environment, 278 providerClassName, 279 targetInterface, loader); 280 if(provider == null) { 281 if(loader != null) { 286 JMXConnectorServer connection = 287 getConnectorServerAsService(loader, 288 serviceURL, 289 environment, 290 mbeanServer); 291 if(connection != null) 292 return connection; 293 } 294 295 provider = (JMXConnectorServerProvider ) 296 JMXConnectorFactory.getProvider(protocol, 297 PROTOCOL_PROVIDER_DEFAULT_PACKAGE, 298 JMXConnectorFactory .class.getClassLoader(), 299 providerClassName, 300 targetInterface); 301 } 302 303 if(provider == null) 304 throw new MalformedURLException ("Unsupported protocol: " + 305 protocol); 306 307 environment = Collections.unmodifiableMap(environment); 308 309 return provider.newJMXConnectorServer(serviceURL, environment, 310 mbeanServer); 311 } 312 } 313 | Popular Tags |