Skip to content

Commit

Permalink
Add support for building on Java 11
Browse files Browse the repository at this point in the history
  • Loading branch information
dnskr committed Apr 18, 2024
1 parent 88c682a commit 9a3cc82
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ on:

jobs:
build:

runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
java-version:
- 8
- 11
steps:
- uses: actions/checkout@v4
with:
show-progress: false
# needed for the git-commit-id-plugin to work
fetch-depth: 0
- name: Set up JDK 8
uses: actions/setup-java@v3
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '8'
java-version: ${{ matrix.java-version }}
distribution: 'temurin'
cache: maven
- name: Maven verify
Expand Down
17 changes: 14 additions & 3 deletions jmx/src/main/java/com/facebook/airlift/jmx/JmxAgent8.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.facebook.airlift.log.Logger;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.net.HostAndPort;
import sun.management.Agent;
import sun.management.jmxremote.ConnectorBootstrap;
import sun.rmi.server.UnicastRef;

Expand All @@ -41,6 +40,8 @@ class JmxAgent8
{
private static final Logger log = Logger.get(JmxAgent.class);

private static final Class<?> AGENT_CLASS = getAgentClass();

private final JMXServiceURL url;

@Inject
Expand Down Expand Up @@ -76,7 +77,7 @@ public JmxAgent8(JmxConfig config)
System.setProperty("com.sun.management.jmxremote.ssl", "false");

try {
Agent.startAgent();
AGENT_CLASS.getMethod("startAgent").invoke(null);
}
catch (Exception e) {
throwIfUnchecked(e);
Expand Down Expand Up @@ -111,7 +112,7 @@ static HostAndPort getRunningAgentAddress(Integer registryPort, Integer serverPo
RemoteObject registry;
int actualRegistryPort;
try {
jmxServer = getField(Agent.class, JMXConnectorServer.class, "jmxServer");
jmxServer = getField(AGENT_CLASS, JMXConnectorServer.class, "jmxServer");
registry = getField(ConnectorBootstrap.class, RemoteObject.class, "registry");

if (jmxServer == null || registry == null) {
Expand Down Expand Up @@ -160,4 +161,14 @@ private static <T> T getField(Class<?> clazz, Class<T> returnType, String name)
throw new IllegalArgumentException(format("Field %s in class %s is not of type %s, actual: %s", name, clazz.getName(), returnType.getName(), field.getType().getName()), e);
}
}

private static Class<?> getAgentClass()
{
try {
return Class.forName("sun.management.Agent");
}
catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}
5 changes: 5 additions & 0 deletions stats/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
<artifactId>jackson-annotations</artifactId>
</dependency>

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
Expand Down

0 comments on commit 9a3cc82

Please sign in to comment.