< prev index next >

src/jdk.management.agent/share/classes/jdk/internal/agent/Agent.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 36,60 **** --- 36,67 ---- import java.net.MalformedURLException; import java.net.UnknownHostException; import java.security.AccessController; import java.security.PrivilegedAction; import java.text.MessageFormat; + import java.util.Collections; import java.util.HashMap; + import java.util.LinkedHashMap; + import java.util.List; import java.util.Map; import java.util.MissingResourceException; + import java.util.Optional; import java.util.Properties; import java.util.ResourceBundle; import java.util.ServiceLoader; + import java.util.Set; import java.util.function.Function; import java.util.function.Predicate; import javax.management.remote.JMXConnectorServer; import javax.management.remote.JMXServiceURL; import static jdk.internal.agent.AgentConfigurationError.*; import jdk.internal.agent.spi.AgentProvider; import jdk.internal.vm.VMSupport; + import sun.management.ManagementFactoryHelper; + import sun.management.VMManagement; import sun.management.jdp.JdpController; import sun.management.jdp.JdpException; import sun.management.jmxremote.ConnectorBootstrap; /**
*** 260,273 **** --- 267,298 ---- // The only active agent allowed private static JMXConnectorServer jmxServer = null; // The properties used to configure the server private static Properties configProps = null; + private static final Map<String, String> XMANAGEMENTFLAS = Collections.unmodifiableMap(new LinkedHashMap<>() {{ + put("config_file", "com.sun.management.config.file"); + put("local", "com.sun.management.jmxremote"); + put("port", "com.sun.management.jmxremote.port"); + put("host", "com.sun.management.jmxremote.host"); + put("rmiserver_port", "com.sun.management.jmxremote.rmi.port"); + put("rmi_registry_ssl", "com.sun.management.jmxremote.registry.ssl"); + put("ssl", "com.sun.management.jmxremote.ssl"); + put("ssl_config_file", "com.sun.management.jmxremote.ssl.config.file"); + put("ssl_client_auth", "com.sun.management.jmxremote.ssl.need.client.auth"); + put("password_file", "com.sun.management.jmxremote.password.file"); + put("authenticate", "com.sun.management.jmxremote.authenticate"); + put("access_file", "com.sun.management.jmxremote.access.file"); + }}); + // Parse string com.sun.management.prop=xxx,com.sun.management.prop=yyyy // and return property set if args is null or empty // return empty property set private static Properties parseString(String args) { + if(args.startsWith("-Xmanagement")) { + return parseXmgmtArgs(args); + } Properties argProps = new Properties(); if (args != null && !args.trim().equals("")) { for (String option : args.split(",")) { String s[] = option.split("=", 2); String name = s[0].trim();
*** 607,622 **** --- 632,683 ---- } } } } + private static Properties parseXmgmtArgs(String args) { + Properties props = new Properties(); + if(args != null && !args.trim().isEmpty()) { + args = args.trim(); + if (args.equals("-Xmanagement") || args.equals("-Xmanagement:")) { + props.setProperty("com.sun.management.jmxremote", "true"); + return props; + } + + args = args.replaceFirst("^-Xmanagement:", ""); + Set<String> keys = XMANAGEMENTFLAS.keySet(); + for (String param : args.split(",")) { + String[] tokens = param.trim().split("=",2); + String name = tokens[0].trim(); + if(keys.contains(name)) { + name = XMANAGEMENTFLAS.get(name); + String value = (tokens.length > 1) ? tokens[1].trim() : ""; + props.setProperty(name, value); + } else { + error(INVALID_OPTION, name); + } + } + } + return props; + } + + public static void startAgent() throws Exception { String prop = System.getProperty("com.sun.management.agent.class"); // -Dcom.sun.management.agent.class not set so read management // properties and start agent if (prop == null) { + VMManagement vmManagement = ManagementFactoryHelper.getVMManagement(); + if (vmManagement != null) { + List<String> vmArguments = vmManagement.getVmArguments(); + Optional<String> argStr = vmArguments.stream().filter(a -> a.startsWith("-Xmanagement")).findFirst(); + if (argStr.isPresent()) { + Properties props = parseXmgmtArgs(argStr.get()); + props.forEach((a,b) -> System.setProperty((String) a,(String) b)); + } + } // initialize management properties Properties props = getManagementProperties(); if (props != null) { startAgent(props); }
< prev index next >