Skip to content

Commit

Permalink
Allow connection via JMXServiceURL
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Oct 10, 2019
1 parent 8af81d9 commit 5b03cee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies {
}

publishing {
def coreVersion = '0.3.0';
def coreVersion = '0.3.1';
publications {
maven(MavenPublication) {
groupId = 'com.redhat.rhjmc'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ public class JFRConnection implements AutoCloseable {

private final ClientWriter cw;
private final Clock clock;
private final String host;
private final int port;
private final JMXServiceURL url;
private final RJMXConnection rjmxConnection;
private final IConnectionHandle handle;
private final IFlightRecorderService service;

JFRConnection(ClientWriter cw, Clock clock, String host, int port) throws Exception {
this(cw, clock, new JMXServiceURL(String.format(URL_FORMAT, host, port)));
}

JFRConnection(ClientWriter cw, Clock clock, JMXServiceURL url) throws Exception {
this.cw = cw;
this.clock = clock;
this.host = host;
this.port = port;
this.rjmxConnection = attemptConnect(host, port, 0);
this.url = url;
this.rjmxConnection = attemptConnect(url, 0);
this.handle = new DefaultConnectionHandle(rjmxConnection, "RJMX Connection", new IConnectionListener[0]);
this.service = new FlightRecorderServiceFactory().getServiceInstance(handle);
}
Expand All @@ -50,11 +52,11 @@ public long getApproximateServerTime(Clock clock) {
}

public String getHost() {
return this.host;
return this.url.getHost();
}

public int getPort() {
return this.port;
return this.url.getPort();
}

public void disconnect() {
Expand All @@ -66,9 +68,9 @@ public void close() {
this.disconnect();
}

private RJMXConnection attemptConnect(String host, int port, int maxRetry) throws Exception {
private RJMXConnection attemptConnect(JMXServiceURL url, int maxRetry) throws Exception {
JMXConnectionDescriptor cd = new JMXConnectionDescriptor(
new JMXServiceURL(String.format(URL_FORMAT, host, port)),
url,
new InMemoryCredentials(null, null));
ServerDescriptor sd = new ServerDescriptor(null, "Container", null);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.redhat.rhjmc.containerjfr.core.net;

import javax.management.remote.JMXServiceURL;

import com.redhat.rhjmc.containerjfr.core.sys.Clock;
import com.redhat.rhjmc.containerjfr.core.tui.ClientWriter;

Expand All @@ -13,6 +15,10 @@ public JFRConnectionToolkit(ClientWriter cw, Clock clock) {
this.clock = clock;
}

public JFRConnection connect(JMXServiceURL url) throws Exception {
return new JFRConnection(cw, clock, url);
}

public JFRConnection connect(String host) throws Exception {
return connect(host, JFRConnection.DEFAULT_PORT);
}
Expand Down

0 comments on commit 5b03cee

Please sign in to comment.