Skip to content

Commit

Permalink
Do not reference availability type in field to allow reflection witho…
Browse files Browse the repository at this point in the history
…ut errors.
  • Loading branch information
raphw committed Dec 16, 2016
1 parent b432aa5 commit f9ba5d8
Showing 1 changed file with 11 additions and 9 deletions.
Expand Up @@ -192,9 +192,10 @@ public static class OnUnix extends ForHotSpot {
private static final String ATTACH_FILE_PREFIX = ".attach_pid";

/**
* The Unix socket to use for communication.
* The Unix socket to use for communication. The containing object is supposed to be an instance
* of {@link AFUNIXSocket} which is however not set to avoid eager loading
*/
private final AFUNIXSocket socket;
private final Object socket;

/**
* The number of attempts to connect.
Expand Down Expand Up @@ -226,7 +227,7 @@ public static class OnUnix extends ForHotSpot {
* @param timeout The socket timeout.
* @param timeUnit The time unit of the pause time.
*/
public OnUnix(String processId, AFUNIXSocket socket, int attempts, long pause, long timeout, TimeUnit timeUnit) {
public OnUnix(String processId, Object socket, int attempts, long pause, long timeout, TimeUnit timeUnit) {
super(processId);
this.socket = socket;
this.attempts = attempts;
Expand All @@ -240,8 +241,9 @@ public OnUnix(String processId, AFUNIXSocket socket, int attempts, long pause, l
* if this VM does not support Unix socket communication, a {@link Throwable} is thrown.
*
* @return This virtual machine type.
* @throws Throwable If this VM does not support POSIX sockets or is not running on a HotSpot VM.
*/
public static Class<?> assertAvailability() {
public static Class<?> assertAvailability() throws Throwable {
if (!AFUNIXSocket.isSupported()) {
throw new IllegalStateException("POSIX sockets are not supported on the current system");
} else if (!System.getProperty("java.vm.name").toLowerCase(Locale.US).contains("hotspot")) {
Expand Down Expand Up @@ -314,23 +316,23 @@ protected void connect() throws IOException {
}
}
}
socket.setSoTimeout((int) timeUnit.toMillis(timeout));
socket.connect(new AFUNIXSocketAddress(socketFile));
((AFUNIXSocket) socket).setSoTimeout((int) timeUnit.toMillis(timeout));
((AFUNIXSocket) socket).connect(new AFUNIXSocketAddress(socketFile));
}

@Override
public int read(byte[] buffer) throws IOException {
return socket.getInputStream().read(buffer);
return ((AFUNIXSocket) this.socket).getInputStream().read(buffer);
}

@Override
public void write(byte[] buffer) throws IOException {
socket.getOutputStream().write(buffer);
((AFUNIXSocket) this.socket).getOutputStream().write(buffer);
}

@Override
public void detach() throws IOException {
socket.close();
((AFUNIXSocket) this.socket).close();
}

@Override
Expand Down

0 comments on commit f9ba5d8

Please sign in to comment.