added new settings for automatic process tracking
This commit is contained in:
@@ -34,6 +34,9 @@ public class BootJavaConfig implements InitializingBean {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BootJavaConfig.class);
|
||||
|
||||
public static final boolean LIVE_INFORMATION_AUTOMATIC_TRACKING_ENABLED_DEFAULT = true;
|
||||
public static final int LIVE_INFORMATION_AUTOMATIC_TRACKING_DELAY_DEFAULT = 5000;
|
||||
|
||||
//TODO: Consider changing this to something that raises Spring application events.
|
||||
// I.e. like described in here: https://www.baeldung.com/spring-events
|
||||
|
||||
@@ -45,10 +48,14 @@ public class BootJavaConfig implements InitializingBean {
|
||||
this.workspace = server.getWorkspaceService();
|
||||
}
|
||||
|
||||
public boolean isLiveInformationAutomaticTrackingEnabled() {
|
||||
Boolean enabled = settings.getBoolean("boot-java", "live-information", "automatic-tracking", "on");
|
||||
return enabled != null ? enabled.booleanValue() : LIVE_INFORMATION_AUTOMATIC_TRACKING_ENABLED_DEFAULT;
|
||||
}
|
||||
|
||||
public boolean isBootHintsEnabled() {
|
||||
Boolean enabled = settings.getBoolean("boot-java", "boot-hints", "on");
|
||||
return enabled == null || enabled.booleanValue();
|
||||
public int getLiveInformationAutomaticTrackingDelay() {
|
||||
Integer delay = settings.getInt("boot-java", "live-information", "automatic-tracking", "delay");
|
||||
return delay != null ? delay.intValue() : LIVE_INFORMATION_AUTOMATIC_TRACKING_DELAY_DEFAULT;
|
||||
}
|
||||
|
||||
public boolean isSpringXMLSupportEnabled() {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -176,7 +177,7 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
|
||||
new SpringProcessCommandHandler(server, liveDataService, liveDataLocalProcessConnector, liveDataRemoteProcessConnector);
|
||||
|
||||
// track locally running processes and automatically connect to them if configured to do so
|
||||
liveProcessTracker = new SpringProcessTracker(liveDataLocalProcessConnector, serverParams.watchDogInterval);
|
||||
liveProcessTracker = new SpringProcessTracker(liveDataLocalProcessConnector, Duration.ofMillis(config.getLiveInformationAutomaticTrackingDelay()));
|
||||
|
||||
//
|
||||
//
|
||||
@@ -200,8 +201,10 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
|
||||
|
||||
config.addListener(ignore -> {
|
||||
// live hover watchdog
|
||||
// liveProcessTracker.setTrackingEnabled(config.isBootHintsEnabled());
|
||||
// if (config.isBootHintsEnabled()) {
|
||||
liveProcessTracker.setDelay(config.getLiveInformationAutomaticTrackingDelay());
|
||||
liveProcessTracker.setTrackingEnabled(config.isLiveInformationAutomaticTrackingEnabled());
|
||||
|
||||
// if (config.isBootHintsEnabled()) {
|
||||
// liveHoverWatchdog.enableHighlights();
|
||||
// } else {
|
||||
// liveHoverWatchdog.disableHighlights();
|
||||
|
||||
@@ -16,26 +16,28 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.boot.app.BootJavaConfig;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
*/
|
||||
public class SpringProcessTracker {
|
||||
|
||||
private static final Duration DEFAULT_INTERVAL = Duration.ofMillis(5000);
|
||||
private static final long DELAY_MINIMUM = 1000;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SpringProcessTracker.class);
|
||||
|
||||
private final long POLLING_INTERVAL_MILLISECONDS;
|
||||
private final SpringProcessConnectorLocal localProcessConnector;
|
||||
private final boolean isConnectorAvailable;
|
||||
|
||||
private boolean automaticTrackingEnabled;
|
||||
private Duration POLLING_INTERVAL;
|
||||
private ScheduledThreadPoolExecutor timer;
|
||||
|
||||
public SpringProcessTracker(SpringProcessConnectorLocal localProcessConnector, Duration pollingInterval) {
|
||||
this.localProcessConnector = localProcessConnector;
|
||||
this.POLLING_INTERVAL_MILLISECONDS = pollingInterval == null ? DEFAULT_INTERVAL.toMillis() : pollingInterval.toMillis();
|
||||
this.automaticTrackingEnabled = true;
|
||||
this.POLLING_INTERVAL = pollingInterval != null ? pollingInterval : Duration.ofMillis(BootJavaConfig.LIVE_INFORMATION_AUTOMATIC_TRACKING_DELAY_DEFAULT);
|
||||
this.automaticTrackingEnabled = false;
|
||||
|
||||
this.isConnectorAvailable = SpringProcessConnectorLocal.isAvailable();
|
||||
}
|
||||
@@ -52,6 +54,19 @@ public class SpringProcessTracker {
|
||||
}
|
||||
}
|
||||
|
||||
public void setDelay(long delay) {
|
||||
Duration newDelay = Duration.ofMillis(Math.max(DELAY_MINIMUM, delay));
|
||||
|
||||
if (!newDelay.equals(POLLING_INTERVAL)) {
|
||||
this.POLLING_INTERVAL = newDelay;
|
||||
|
||||
if (automaticTrackingEnabled) {
|
||||
stop();
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void start() {
|
||||
if (!isConnectorAvailable) {
|
||||
log.error("virtual machine connector library not available, no automatic local process tracking possible");
|
||||
@@ -61,7 +76,7 @@ public class SpringProcessTracker {
|
||||
if (automaticTrackingEnabled && timer == null) {
|
||||
log.info("Starting SpringProcessTracker");
|
||||
this.timer = new ScheduledThreadPoolExecutor(1);
|
||||
this.timer.scheduleWithFixedDelay(() -> this.update(), 0, POLLING_INTERVAL_MILLISECONDS, TimeUnit.MILLISECONDS);
|
||||
this.timer.scheduleWithFixedDelay(() -> this.update(), 0, POLLING_INTERVAL.toMillis(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,19 +89,18 @@ public class SpringProcessTracker {
|
||||
}
|
||||
|
||||
private void update() {
|
||||
// log.info("scan for local processes cycle...");
|
||||
// try {
|
||||
// SpringProcessDescriptor[] autoConnectProcesses = this.localProcessConnector.getProcesses(true, SpringProcessStatus.AUTO_CONNECT);
|
||||
//
|
||||
// for (SpringProcessDescriptor process : autoConnectProcesses) {
|
||||
// log.info("auto-connect to process: " + process.getProcessKey());
|
||||
//
|
||||
// this.localProcessConnector.connectProcess(process);
|
||||
// }
|
||||
// }
|
||||
// catch (Throwable e) {
|
||||
// log.error("error searching for local processes", e);
|
||||
// }
|
||||
try {
|
||||
SpringProcessDescriptor[] autoConnectProcesses = this.localProcessConnector.getProcesses(true, SpringProcessStatus.AUTO_CONNECT);
|
||||
|
||||
for (SpringProcessDescriptor process : autoConnectProcesses) {
|
||||
log.info("auto-connect to process: " + process.getProcessKey());
|
||||
|
||||
this.localProcessConnector.connectProcess(process);
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
log.error("error searching for local processes", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user