Skip to content

Commit

Permalink
Implement JvmDiscoveryClient
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Oct 10, 2019
1 parent 5b03cee commit c9fcf61
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ dependencies {
api "org.openjdk.jmc:org.openjdk.jmc.rjmx.services.jfr:${jmcVersion}", {
exclude group: 'org.jacoco', module: 'jacoco-maven-plugin'
}
api "org.openjdk.jmc:org.openjdk.jmc.jdp:${jmcVersion}", {
exclude group: 'org.jacoco', module: 'jacoco-maven-plugin'
}
api "org.openjdk.jmc:org.openjdk.jmc.ui.common:${jmcVersion}", {
exclude group: 'org.jacoco', module: 'jacoco-maven-plugin'
}
Expand All @@ -39,7 +42,7 @@ dependencies {
}

publishing {
def coreVersion = '0.3.1';
def coreVersion = '0.3.2';
publications {
maven(MavenPublication) {
groupId = 'com.redhat.rhjmc'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.redhat.rhjmc.containerjfr.core.net.discovery;

import java.net.MalformedURLException;
import java.util.Map;

import javax.management.remote.JMXServiceURL;

public class DiscoveredJvmDescriptor {

private final Map<String, String> o;

DiscoveredJvmDescriptor(Map<String, String> o) {
this.o = o;
}

public String getMainClass() {
return o.get("MAIN_CLASS");
}

public JMXServiceURL getJmxServiceUrl() throws MalformedURLException {
return new JMXServiceURL(o.get("JMX_SERVICE_URL"));
}

@Override
public String toString() {
return o.toString();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.redhat.rhjmc.containerjfr.core.net.discovery;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

import com.redhat.rhjmc.containerjfr.core.log.Logger;

import org.openjdk.jmc.jdp.client.JDPClient;

public class JvmDiscoveryClient {

private final Logger logger;
private final JDPClient jdp;

public JvmDiscoveryClient(Logger logger) {
this.logger = logger;
this.jdp = new JDPClient();
}

public void start() throws IOException {
this.logger.info("JDP Discovery started");
this.jdp.start();
}

public void stop() {
this.logger.info("JDP Discovery stopped");
this.jdp.stop();
}

public List<DiscoveredJvmDescriptor> getDiscoveredJvmDescriptors() {
return this.jdp.getDiscoverables()
.stream()
.map(d -> new DiscoveredJvmDescriptor(d.getPayload()))
.collect(Collectors.toList());
}

}

0 comments on commit c9fcf61

Please sign in to comment.