Add self attach hint when JMX agent start fails
@@ -28,11 +28,15 @@ import java.lang.management.ManagementFactory;
import java.net.MalformedURLException;
import java.util.Properties;
+import static java.lang.String.format;
+
class JmxAgent9
implements JmxAgent
{
private static final Logger log = Logger.get(JmxAgent.class);
+ private static final String ALLOW_SELF_ATTACH = "jdk.attach.allowAttachSelf";
+
private final JMXServiceURL url;
@Inject
@@ -74,6 +78,12 @@ class JmxAgent9
catch (AttachNotSupportedException e) {
throw new RuntimeException(e);
}
+ catch (IOException e) {
+ if (!Boolean.getBoolean(ALLOW_SELF_ATTACH)) {
+ throw new IOException(format("%s (try adding '-D%s=true' to the JVM config)", e, ALLOW_SELF_ATTACH));
+ }
+ throw e;
+ }
HostAndPort address;
try {
@@ -89,7 +99,7 @@ class JmxAgent9
log.info("JMX agent started and listening on %s", address);
- this.url = new JMXServiceURL(String.format("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", address.getHost(), address.getPort()));
+ this.url = new JMXServiceURL(format("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", address.getHost(), address.getPort()));
}
else {
this.url = null;
