use of sun.management.jdp.JdpException in project jdk8u_jdk by JetBrains.
the class Agent method startDiscoveryService.
private static void startDiscoveryService(Properties props) throws IOException {
// Start discovery service if requested
String discoveryPort = props.getProperty("com.sun.management.jdp.port");
String discoveryAddress = props.getProperty("com.sun.management.jdp.address");
String discoveryShouldStart = props.getProperty("com.sun.management.jmxremote.autodiscovery");
// Decide whether we should start autodicovery service.
// To start autodiscovery following conditions should be met:
// autodiscovery==true OR (autodicovery==null AND jdp.port != NULL)
boolean shouldStart = false;
if (discoveryShouldStart == null) {
shouldStart = (discoveryPort != null);
} else {
try {
shouldStart = Boolean.parseBoolean(discoveryShouldStart);
} catch (NumberFormatException e) {
throw new AgentConfigurationError("Couldn't parse autodiscovery argument");
}
}
if (shouldStart) {
// port and address are required arguments and have no default values
InetAddress address;
try {
address = (discoveryAddress == null) ? InetAddress.getByName(JDP_DEFAULT_ADDRESS) : InetAddress.getByName(discoveryAddress);
} catch (UnknownHostException e) {
throw new AgentConfigurationError("Unable to broadcast to requested address", e);
}
int port = JDP_DEFAULT_PORT;
if (discoveryPort != null) {
try {
port = Integer.parseInt(discoveryPort);
} catch (NumberFormatException e) {
throw new AgentConfigurationError("Couldn't parse JDP port argument");
}
}
// Rebuilding service URL to broadcast it
String jmxremotePort = props.getProperty(JMXREMOTE_PORT);
String rmiPort = props.getProperty(RMI_PORT);
JMXServiceURL url = jmxServer.getAddress();
String hostname = url.getHost();
String jmxUrlStr = (rmiPort != null) ? String.format("service:jmx:rmi://%s:%s/jndi/rmi://%s:%s/jmxrmi", hostname, rmiPort, hostname, jmxremotePort) : String.format("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", hostname, jmxremotePort);
String instanceName = props.getProperty("com.sun.management.jdp.name");
try {
JdpController.startDiscoveryService(address, port, instanceName, jmxUrlStr);
} catch (JdpException e) {
throw new AgentConfigurationError("Couldn't start JDP service", e);
}
}
}
Aggregations