jdk/src/java.management/share/classes/sun/management/Agent.java
author jbachorik
Fri, 03 Apr 2015 15:39:38 +0200
changeset 30803 17e70318af8b
parent 30334 22a5f09f4da9
child 33267 c9211ad104b5
permissions -rw-r--r--
8075926: Add a sun.management.JMXConnectorServer perf counter to track its state Reviewed-by: duke
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30334
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2285
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2285
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2285
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2285
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2285
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
    27
import java.io.BufferedInputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.FileInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
    32
import java.io.InputStream;
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
    33
import java.lang.management.ManagementFactory;
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    34
import java.lang.reflect.InvocationTargetException;
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
    35
import java.lang.reflect.Method;
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
    36
import java.net.InetAddress;
30334
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    37
import java.net.MalformedURLException;
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
    38
import java.net.UnknownHostException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.text.MessageFormat;
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
    40
import java.util.MissingResourceException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.remote.JMXConnectorServer;
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
    45
import javax.management.remote.JMXServiceURL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
    47
import static sun.management.AgentConfigurationError.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.management.jmxremote.ConnectorBootstrap;
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
    49
import sun.management.jdp.JdpController;
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
    50
import sun.management.jdp.JdpException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import sun.misc.VMSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
/**
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
    54
 * This Agent is started by the VM when -Dcom.sun.management.snmp or
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
    55
 * -Dcom.sun.management.jmxremote is set. This class will be loaded by the
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
    56
 * system class loader. Also jmx framework could be started by jcmd
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public class Agent {
30334
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    59
    /**
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    60
     * Agent status collector strategy class
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    61
     */
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    62
    private static abstract class StatusCollector {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    63
        final protected StringBuilder sb = new StringBuilder();
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    64
        final public String collect() {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    65
            Properties agentProps = VMSupport.getAgentProperties();
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    66
            String localConnAddr = (String)agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    67
            if (localConnAddr != null || jmxServer != null) {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    68
                addAgentStatus(true);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    69
                appendConnections(localConnAddr);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    70
            } else {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    71
                addAgentStatus(false);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    72
            }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    73
            return sb.toString();
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    74
        }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    75
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    76
        private void appendConnections(String localConnAddr) {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    77
            appendConnectionsHeader();
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    78
            if (localConnAddr != null) {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    79
                try {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    80
                    JMXServiceURL u = new JMXServiceURL(localConnAddr);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    81
                    addConnection(false, u);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    82
                } catch (MalformedURLException e) {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    83
                    // will never happen
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    84
                }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    85
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    86
            }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    87
            if (jmxServer != null) {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    88
                addConnection(true, jmxServer.getAddress());
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    89
            }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    90
            appendConnectionsFooter();
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    91
        }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    92
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    93
        private void addConnection(boolean remote, JMXServiceURL u) {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    94
            appendConnectionHeader(remote);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    95
            addConnectionDetails(u);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    96
            if (remote) {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    97
                addConfigProperties();
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    98
            }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
    99
            appendConnectionFooter(remote);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   100
        }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   101
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   102
        private void addConfigProperties() {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   103
            appendConfigPropsHeader();
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   104
            boolean[] first = new boolean[] {true};
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   105
            configProps.entrySet().stream().forEach((e) -> {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   106
                String key = (String)e.getKey();
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   107
                if (key.startsWith("com.sun.management.")) {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   108
                    addConfigProp(key, e.getValue(), first[0]);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   109
                    first[0] = false;
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   110
                }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   111
            });
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   112
            appendConfigPropsFooter();
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   113
        }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   114
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   115
        abstract protected void addAgentStatus(boolean enabled);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   116
        abstract protected void appendConnectionsHeader();
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   117
        abstract protected void appendConnectionsFooter();
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   118
        abstract protected void addConnectionDetails(JMXServiceURL u);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   119
        abstract protected void appendConnectionHeader(boolean remote);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   120
        abstract protected void appendConnectionFooter(boolean remote);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   121
        abstract protected void appendConfigPropsHeader();
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   122
        abstract protected void appendConfigPropsFooter();
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   123
        abstract protected void addConfigProp(String key, Object value, boolean first);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   124
    }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   125
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   126
    /**
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   127
     * Free-text status collector strategy implementation
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   128
     */
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   129
    final private static class TextStatusCollector extends StatusCollector {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   130
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   131
        @Override
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   132
        protected void addAgentStatus(boolean enabled) {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   133
            sb.append("Agent: ").append(enabled ? "enabled" : "disabled").append('\n');
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   134
        }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   135
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   136
        @Override
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   137
        protected void appendConnectionsHeader() {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   138
            sb.append('\n');
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   139
        }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   140
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   141
        @Override
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   142
        protected void addConnectionDetails(JMXServiceURL u) {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   143
            sb.append("Protocol       : ").append(u.getProtocol()).append('\n')
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   144
              .append("Host           : ").append(u.getHost()).append('\n')
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   145
              .append("URL            : ").append(u).append('\n');
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   146
        }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   147
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   148
        @Override
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   149
        protected void appendConnectionHeader(boolean remote) {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   150
            sb.append("Connection Type: ").append(remote ? "remote" : "local").append('\n');
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   151
        }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   152
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   153
        @Override
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   154
        protected void appendConfigPropsHeader() {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   155
            sb.append("Properties     :\n");
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   156
        }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   157
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   158
        @Override
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   159
        protected void addConfigProp(String key, Object value, boolean first) {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   160
            if (!first) {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   161
                sb.append('\n');
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   162
            }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   163
            sb.append("  ").append(key).append(" = ").append(value);
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   164
        }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   165
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   166
        @Override
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   167
        protected void appendConnectionsFooter() {}
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   168
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   169
        @Override
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   170
        protected void appendConnectionFooter(boolean remote) {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   171
            sb.append('\n');
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   172
        }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   173
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   174
        @Override
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   175
        protected void appendConfigPropsFooter() {}
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   176
    }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   177
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    // management properties
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   179
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    private static Properties mgmtProps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    private static ResourceBundle messageRB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    private static final String CONFIG_FILE =
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   183
            "com.sun.management.config.file";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    private static final String SNMP_PORT =
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   185
            "com.sun.management.snmp.port";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    private static final String JMXREMOTE =
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   187
            "com.sun.management.jmxremote";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    private static final String JMXREMOTE_PORT =
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   189
            "com.sun.management.jmxremote.port";
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   190
    private static final String RMI_PORT =
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   191
            "com.sun.management.jmxremote.rmi.port";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private static final String ENABLE_THREAD_CONTENTION_MONITORING =
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   193
            "com.sun.management.enableThreadContentionMonitoring";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    private static final String LOCAL_CONNECTOR_ADDRESS_PROP =
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   195
            "com.sun.management.jmxremote.localConnectorAddress";
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   196
    private static final String SNMP_ADAPTOR_BOOTSTRAP_CLASS_NAME =
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   197
            "sun.management.snmp.AdaptorBootstrap";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
17721
1d6516794d05 8014420: Default JDP address does not match the one assigned by IANA
dsamersoff
parents: 15531
diff changeset
   199
    private static final String JDP_DEFAULT_ADDRESS = "224.0.23.178";
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   200
    private static final int JDP_DEFAULT_PORT = 7095;
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   201
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   202
    // The only active agent allowed
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   203
    private static JMXConnectorServer jmxServer = null;
30334
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   204
    // The properties used to configure the server
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   205
    private static Properties configProps = null;
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   206
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   207
    // Parse string com.sun.management.prop=xxx,com.sun.management.prop=yyyy
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   208
    // and return property set if args is null or empty
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   209
    // return empty property set
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   210
    private static Properties parseString(String args) {
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   211
        Properties argProps = new Properties();
24980
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   212
        if (args != null && !args.trim().equals("")) {
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   213
            for (String option : args.split(",")) {
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   214
                String s[] = option.split("=", 2);
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   215
                String name = s[0].trim();
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   216
                String value = (s.length > 1) ? s[1].trim() : "";
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   217
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   218
                if (!name.startsWith("com.sun.management.")) {
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   219
                    error(INVALID_OPTION, name);
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   220
                }
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   221
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   222
                argProps.setProperty(name, value);
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   223
            }
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   224
        }
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   225
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   226
        return argProps;
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   227
    }
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   228
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    // invoked by -javaagent or -Dcom.sun.management.agent.class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public static void premain(String args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        agentmain(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    // invoked by attach mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public static void agentmain(String args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (args == null || args.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            args = JMXREMOTE;           // default to local management
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   240
        Properties arg_props = parseString(args);
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   241
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   242
        // Read properties from the config file
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   243
        Properties config_props = new Properties();
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   244
        String fname = arg_props.getProperty(CONFIG_FILE);
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   245
        readConfiguration(fname, config_props);
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   246
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   247
        // Arguments override config file
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   248
        config_props.putAll(arg_props);
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   249
        startAgent(config_props);
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   250
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   252
    // jcmd ManagementAgent.start_local entry point
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   253
    // Also called due to command-line via startAgent()
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   254
    private static synchronized void startLocalManagementAgent() {
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   255
        Properties agentProps = VMSupport.getAgentProperties();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   257
        // start local connector if not started
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   258
        if (agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP) == null) {
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   259
            JMXConnectorServer cs = ConnectorBootstrap.startLocalConnectorServer();
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   260
            String address = cs.getAddress().toString();
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   261
            // Add the local connector address to the agent properties
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   262
            agentProps.put(LOCAL_CONNECTOR_ADDRESS_PROP, address);
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   263
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   264
            try {
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   265
                // export the address to the instrumentation buffer
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   266
                ConnectorAddressLink.export(address);
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   267
            } catch (Exception x) {
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   268
                // Connector server started but unable to export address
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   269
                // to instrumentation buffer - non-fatal error.
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   270
                warning(EXPORT_ADDRESS_FAILED, x.getMessage());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   273
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   275
    // jcmd ManagementAgent.start entry point
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   276
    // This method starts the remote JMX agent and starts neither
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   277
    // the local JMX agent nor the SNMP agent
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   278
    // @see #startLocalManagementAgent and also @see #startAgent.
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   279
    private static synchronized void startRemoteManagementAgent(String args) throws Exception {
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   280
        if (jmxServer != null) {
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   281
            throw new RuntimeException(getText(INVALID_STATE, "Agent already started"));
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   282
        }
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   283
24980
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   284
        try {
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   285
            Properties argProps = parseString(args);
30334
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   286
            configProps = new Properties();
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   287
24980
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   288
            // Load the management properties from the config file
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   289
            // if config file is not specified readConfiguration implicitly
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 26488
diff changeset
   290
            // reads <java.home>/conf/management/management.properties
24980
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   291
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   292
            String fname = System.getProperty(CONFIG_FILE);
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   293
            readConfiguration(fname, configProps);
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   294
24980
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   295
            // management properties can be overridden by system properties
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   296
            // which take precedence
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   297
            Properties sysProps = System.getProperties();
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   298
            synchronized (sysProps) {
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   299
                configProps.putAll(sysProps);
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   300
            }
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   301
24980
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   302
            // if user specifies config file into command line for either
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   303
            // jcmd utilities or attach command it overrides properties set in
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   304
            // command line at the time of VM start
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   305
            String fnameUser = argProps.getProperty(CONFIG_FILE);
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   306
            if (fnameUser != null) {
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   307
                readConfiguration(fnameUser, configProps);
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   308
            }
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   309
24980
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   310
            // arguments specified in command line of jcmd utilities
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   311
            // override both system properties and one set by config file
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   312
            // specified in jcmd command line
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   313
            configProps.putAll(argProps);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
24980
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   315
            // jcmd doesn't allow to change ThreadContentionMonitoring, but user
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   316
            // can specify this property inside config file, so enable optional
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   317
            // monitoring functionality if this property is set
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   318
            final String enableThreadContentionMonitoring =
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   319
                    configProps.getProperty(ENABLE_THREAD_CONTENTION_MONITORING);
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   320
24980
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   321
            if (enableThreadContentionMonitoring != null) {
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   322
                ManagementFactory.getThreadMXBean().
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   323
                        setThreadContentionMonitoringEnabled(true);
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   324
            }
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   325
24980
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   326
            String jmxremotePort = configProps.getProperty(JMXREMOTE_PORT);
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   327
            if (jmxremotePort != null) {
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   328
                jmxServer = ConnectorBootstrap.
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   329
                        startRemoteConnectorServer(jmxremotePort, configProps);
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   330
24980
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   331
                startDiscoveryService(configProps);
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   332
            } else {
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   333
                throw new AgentConfigurationError(INVALID_JMXREMOTE_PORT, "No port specified");
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   334
            }
26488
5b5fccd9d016 8057746: Cannot handle JdpException in JMX agent initialization.
dsamersoff
parents: 25859
diff changeset
   335
        } catch (JdpException e) {
5b5fccd9d016 8057746: Cannot handle JdpException in JMX agent initialization.
dsamersoff
parents: 25859
diff changeset
   336
            error(e);
24980
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   337
        } catch (AgentConfigurationError err) {
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   338
            error(err.getError(), err.getParams());
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   339
        }
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   340
    }
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   341
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   342
    private static synchronized void stopRemoteManagementAgent() throws Exception {
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   343
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   344
        JdpController.stopDiscoveryService();
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   345
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   346
        if (jmxServer != null) {
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   347
            ConnectorBootstrap.unexportRegistry();
30803
17e70318af8b 8075926: Add a sun.management.JMXConnectorServer perf counter to track its state
jbachorik
parents: 30334
diff changeset
   348
            ConnectorAddressLink.unexportRemote();
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   349
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   350
            // Attempt to stop already stopped agent
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   351
            // Don't cause any errors.
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   352
            jmxServer.stop();
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   353
            jmxServer = null;
30334
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   354
            configProps = null;
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   355
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
30334
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   358
    private static synchronized String getManagementAgentStatus() throws Exception {
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   359
        return new TextStatusCollector().collect();
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   360
    }
22a5f09f4da9 8023093: Add ManagementAgent.status diagnostic command
jbachorik
parents: 27957
diff changeset
   361
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    private static void startAgent(Properties props) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        String snmpPort = props.getProperty(SNMP_PORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        String jmxremote = props.getProperty(JMXREMOTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        String jmxremotePort = props.getProperty(JMXREMOTE_PORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        // Enable optional monitoring functionality if requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        final String enableThreadContentionMonitoring =
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   369
                props.getProperty(ENABLE_THREAD_CONTENTION_MONITORING);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        if (enableThreadContentionMonitoring != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            ManagementFactory.getThreadMXBean().
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   372
                    setThreadContentionMonitoringEnabled(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            if (snmpPort != null) {
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   377
                loadSnmpAgent(snmpPort, props);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
             * If the jmxremote.port property is set then we start the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
             * RMIConnectorServer for remote M&M.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
             * If the jmxremote or jmxremote.port properties are set then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
             * we start a RMIConnectorServer for local M&M. The address
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
             * of this "local" server is exported as a counter to the jstat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
             * instrumentation buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
             */
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   389
            if (jmxremote != null || jmxremotePort != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                if (jmxremotePort != null) {
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   391
                    jmxServer = ConnectorBootstrap.
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   392
                            startRemoteConnectorServer(jmxremotePort, props);
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   393
                    startDiscoveryService(props);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                }
11991
800d0ff7b043 7110104: It should be possible to stop and start JMX Agent at runtime
dsamersoff
parents: 11530
diff changeset
   395
                startLocalManagementAgent();
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   396
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        } catch (AgentConfigurationError e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            error(e.getError(), e.getParams());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            error(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   405
    private static void startDiscoveryService(Properties props)
26488
5b5fccd9d016 8057746: Cannot handle JdpException in JMX agent initialization.
dsamersoff
parents: 25859
diff changeset
   406
            throws IOException, JdpException {
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   407
        // Start discovery service if requested
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   408
        String discoveryPort = props.getProperty("com.sun.management.jdp.port");
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   409
        String discoveryAddress = props.getProperty("com.sun.management.jdp.address");
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   410
        String discoveryShouldStart = props.getProperty("com.sun.management.jmxremote.autodiscovery");
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   411
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   412
        // Decide whether we should start autodicovery service.
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   413
        // To start autodiscovery following conditions should be met:
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   414
        // autodiscovery==true OR (autodicovery==null AND jdp.port != NULL)
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   415
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   416
        boolean shouldStart = false;
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   417
        if (discoveryShouldStart == null){
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   418
            shouldStart = (discoveryPort != null);
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   419
        }
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   420
        else{
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   421
            try{
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   422
               shouldStart = Boolean.parseBoolean(discoveryShouldStart);
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   423
            } catch (NumberFormatException e) {
26488
5b5fccd9d016 8057746: Cannot handle JdpException in JMX agent initialization.
dsamersoff
parents: 25859
diff changeset
   424
                throw new AgentConfigurationError(AGENT_EXCEPTION, "Couldn't parse autodiscovery argument");
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   425
            }
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   426
        }
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   427
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   428
        if (shouldStart) {
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   429
            // port and address are required arguments and have no default values
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   430
            InetAddress address;
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   431
            try {
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   432
                address = (discoveryAddress == null) ?
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   433
                        InetAddress.getByName(JDP_DEFAULT_ADDRESS) : InetAddress.getByName(discoveryAddress);
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   434
            } catch (UnknownHostException e) {
26488
5b5fccd9d016 8057746: Cannot handle JdpException in JMX agent initialization.
dsamersoff
parents: 25859
diff changeset
   435
                throw new AgentConfigurationError(AGENT_EXCEPTION, e, "Unable to broadcast to requested address");
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   436
            }
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   437
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   438
            int port = JDP_DEFAULT_PORT;
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   439
            if (discoveryPort != null) {
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   440
               try {
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   441
                  port = Integer.parseInt(discoveryPort);
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   442
               } catch (NumberFormatException e) {
26488
5b5fccd9d016 8057746: Cannot handle JdpException in JMX agent initialization.
dsamersoff
parents: 25859
diff changeset
   443
                 throw new AgentConfigurationError(AGENT_EXCEPTION, "Couldn't parse JDP port argument");
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   444
               }
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   445
            }
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   446
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   447
            // Rebuilding service URL to broadcast it
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   448
            String jmxremotePort = props.getProperty(JMXREMOTE_PORT);
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   449
            String rmiPort = props.getProperty(RMI_PORT);
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   450
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   451
            JMXServiceURL url = jmxServer.getAddress();
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   452
            String hostname = url.getHost();
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   453
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   454
            String jmxUrlStr = (rmiPort != null)
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   455
                    ? String.format(
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   456
                    "service:jmx:rmi://%s:%s/jndi/rmi://%s:%s/jmxrmi",
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   457
                    hostname, rmiPort, hostname, jmxremotePort)
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   458
                    : String.format(
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   459
                    "service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", hostname, jmxremotePort);
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   460
21298
d8a11a962ee3 8024071: In ManagementAgent.start it should be possible to set the jdp.name parameter.
dsamersoff
parents: 17721
diff changeset
   461
            String instanceName = props.getProperty("com.sun.management.jdp.name");
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   462
26488
5b5fccd9d016 8057746: Cannot handle JdpException in JMX agent initialization.
dsamersoff
parents: 25859
diff changeset
   463
            JdpController.startDiscoveryService(address, port, instanceName, jmxUrlStr);
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   464
        }
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   465
    }
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   466
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    public static Properties loadManagementProperties() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        Properties props = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        // Load the management properties from the config file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        String fname = System.getProperty(CONFIG_FILE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        readConfiguration(fname, props);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        // management properties can be overridden by system properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        // which take precedence
12694
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents: 11991
diff changeset
   477
        Properties sysProps = System.getProperties();
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   478
        synchronized (sysProps) {
12694
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents: 11991
diff changeset
   479
            props.putAll(sysProps);
543c5e6c5ed0 7164191: properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario
dsamersoff
parents: 11991
diff changeset
   480
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        return props;
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   483
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   485
    public static synchronized Properties getManagementProperties() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        if (mgmtProps == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            String configFile = System.getProperty(CONFIG_FILE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            String snmpPort = System.getProperty(SNMP_PORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            String jmxremote = System.getProperty(JMXREMOTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            String jmxremotePort = System.getProperty(JMXREMOTE_PORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   492
            if (configFile == null && snmpPort == null
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   493
                    && jmxremote == null && jmxremotePort == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                // return if out-of-the-management option is not specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            mgmtProps = loadManagementProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        return mgmtProps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   502
    private static void loadSnmpAgent(String snmpPort, Properties props) {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   503
        try {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   504
            // invoke the following through reflection:
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   505
            //     AdaptorBootstrap.initialize(snmpPort, props);
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   506
            final Class<?> adaptorClass =
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   507
                    Class.forName(SNMP_ADAPTOR_BOOTSTRAP_CLASS_NAME, true, null);
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   508
            final Method initializeMethod =
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   509
                    adaptorClass.getMethod("initialize",
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   510
                    String.class, Properties.class);
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   511
            initializeMethod.invoke(null, snmpPort, props);
11530
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   512
        } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException x) {
a9d059c15b80 7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents: 5506
diff changeset
   513
            // snmp runtime doesn't exist - initialization fails
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   514
            throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT, x);
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   515
        } catch (InvocationTargetException x) {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   516
            final Throwable cause = x.getCause();
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   517
            if (cause instanceof RuntimeException) {
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   518
                throw (RuntimeException) cause;
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   519
            } else if (cause instanceof Error) {
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   520
                throw (Error) cause;
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   521
            }
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   522
            // should not happen...
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   523
            throw new UnsupportedOperationException("Unsupported management property: " + SNMP_PORT, cause);
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   524
        }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   525
    }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   526
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    // read config file and initialize the properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    private static void readConfiguration(String fname, Properties p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        if (fname == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            String home = System.getProperty("java.home");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            if (home == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                throw new Error("Can't find java.home ??");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            }
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   534
            StringBuilder defaultFileName = new StringBuilder(home);
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 26488
diff changeset
   535
            defaultFileName.append(File.separator).append("conf");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            defaultFileName.append(File.separator).append("management");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            defaultFileName.append(File.separator).append("management.properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            // Set file name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            fname = defaultFileName.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        final File configFile = new File(fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        if (!configFile.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            error(CONFIG_FILE_NOT_FOUND, fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        InputStream in = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            in = new FileInputStream(configFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            BufferedInputStream bin = new BufferedInputStream(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            p.load(bin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        } catch (FileNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            error(CONFIG_FILE_OPEN_FAILED, e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            error(CONFIG_FILE_OPEN_FAILED, e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            error(CONFIG_FILE_ACCESS_DENIED, fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            if (in != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                    in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                    error(CONFIG_FILE_CLOSE_FAILED, fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                }
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   564
            }
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   565
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    public static void startAgent() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        String prop = System.getProperty("com.sun.management.agent.class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        // -Dcom.sun.management.agent.class not set so read management
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        // properties and start agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        if (prop == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            // initialize management properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            Properties props = getManagementProperties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            if (props != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                startAgent(props);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        // -Dcom.sun.management.agent.class=<agent classname>:<agent args>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        String[] values = prop.split(":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        if (values.length < 1 || values.length > 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            error(AGENT_CLASS_INVALID, "\"" + prop + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        String cname = values[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        String args = (values.length == 2 ? values[1] : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        if (cname == null || cname.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            error(AGENT_CLASS_INVALID, "\"" + prop + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        if (cname != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                // Instantiate the named class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                // invoke the premain(String args) method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                Class<?> clz = ClassLoader.getSystemClassLoader().loadClass(cname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                Method premain = clz.getMethod("premain",
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   600
                        new Class<?>[]{String.class});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                premain.invoke(null, /* static */
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   602
                        new Object[]{args});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            } catch (ClassNotFoundException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                error(AGENT_CLASS_NOT_FOUND, "\"" + cname + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            } catch (NoSuchMethodException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                error(AGENT_CLASS_PREMAIN_NOT_FOUND, "\"" + cname + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            } catch (SecurityException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                error(AGENT_CLASS_ACCESS_DENIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                String msg = (ex.getCause() == null
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   611
                        ? ex.getMessage()
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   612
                        : ex.getCause().getMessage());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                error(AGENT_CLASS_FAILED, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    public static void error(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        String keyText = getText(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        System.err.print(getText("agent.err.error") + ": " + keyText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        throw new RuntimeException(keyText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    public static void error(String key, String[] params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        if (params == null || params.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            error(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        } else {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   628
            StringBuilder message = new StringBuilder(params[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            for (int i = 1; i < params.length; i++) {
27957
24b4e6082f19 8055723: Replace concat String to append in StringBuilder parameters (dev)
weijun
parents: 27565
diff changeset
   630
                message.append(' ').append(params[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            error(key, message.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    public static void error(String key, String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        String keyText = getText(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        System.err.print(getText("agent.err.error") + ": " + keyText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        System.err.println(": " + message);
24980
dbf4ae2cafa4 8046778: Better error messages when starting JMX agent via attach or jcmd
sla
parents: 24969
diff changeset
   640
        throw new RuntimeException(keyText + ": " + message);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    public static void error(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        System.err.println(getText(AGENT_EXCEPTION) + ": " + e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    public static void warning(String key, String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        System.err.print(getText("agent.err.warning") + ": " + getText(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        System.err.println(": " + message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    private static void initResource() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            messageRB =
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   657
                    ResourceBundle.getBundle("sun.management.resources.agent");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        } catch (MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            throw new Error("Fatal: Resource for management agent is missing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    public static String getText(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        if (messageRB == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            initResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            return messageRB.getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        } catch (MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            return "Missing management agent resource bundle: key = \"" + key + "\"";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    public static String getText(String key, String... args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        if (messageRB == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            initResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        String format = messageRB.getString(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        if (format == null) {
15531
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   680
            format = "missing resource key: key = \"" + key + "\", "
071efc9f31ad 8002048: Protocol to discovery of manageable Java processes on a network
dsamersoff
parents: 12694
diff changeset
   681
                    + "arguments = \"{0}\", \"{1}\", \"{2}\"";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        return MessageFormat.format(format, (Object[]) args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
}