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