added check for availability of the tools.jar types

This commit is contained in:
Martin Lippert
2019-09-04 12:49:14 +02:00
parent e04df5ff2c
commit 9d0d2862ba
3 changed files with 29 additions and 11 deletions

View File

@@ -256,7 +256,6 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
}
private void shutdown() {
// this.liveHoverWatchdog.shutdown();
this.liveProcessTracker.stop();
this.liveChangeDetectionWatchdog.shutdown();
this.cuCache.dispose();

View File

@@ -87,6 +87,20 @@ public class SpringProcessConnectorLocal {
});
}
/**
* checks whether this class can operate normally or not - it is recommended to check this before calling out to this class
* (if the attach to VirtualMachine library is not around, this class cannot really do anything and will throw exceptions)
*/
public static boolean isAvailable() {
try {
Class<?> vmClass = VirtualMachine.class;
return vmClass != null;
}
catch (NoClassDefFoundError e) {
return false;
}
}
public void searchForNewProcesses() {
List<VirtualMachineDescriptor> currentVms = VirtualMachine.list();
Set<String> currentVMKeys = new HashSet<>();
@@ -211,5 +225,5 @@ public class SpringProcessConnectorLocal {
int firstSpace = rawName.indexOf(' ');
return firstSpace < 0 ? rawName : rawName.substring(0, firstSpace);
}
}

View File

@@ -27,6 +27,7 @@ public class SpringProcessTracker {
private final long POLLING_INTERVAL_MILLISECONDS;
private final SpringProcessConnectorLocal localProcessConnector;
private final boolean isConnectorAvailable;
private boolean automaticTrackingEnabled;
private ScheduledThreadPoolExecutor timer;
@@ -35,16 +36,28 @@ public class SpringProcessTracker {
this.localProcessConnector = localProcessConnector;
this.POLLING_INTERVAL_MILLISECONDS = pollingInterval == null ? DEFAULT_INTERVAL.toMillis() : pollingInterval.toMillis();
this.automaticTrackingEnabled = true;
this.isConnectorAvailable = SpringProcessConnectorLocal.isAvailable();
}
public synchronized void setTrackingEnabled(boolean trackingEnabled) {
if (automaticTrackingEnabled != trackingEnabled) {
automaticTrackingEnabled = trackingEnabled;
refresh();
if (automaticTrackingEnabled) {
start();
} else {
stop();
}
}
}
public synchronized void start() {
if (!isConnectorAvailable) {
log.error("virtual machine connector library not available, no automatic local process tracking possible");
return;
}
if (automaticTrackingEnabled && timer == null) {
log.info("Starting SpringProcessTracker");
this.timer = new ScheduledThreadPoolExecutor(1);
@@ -70,12 +83,4 @@ public class SpringProcessTracker {
}
}
private void refresh() {
if (automaticTrackingEnabled) {
start();
} else {
stop();
}
}
}