From f8dd7929fdec41c9c11e850d7e83ce4a4dc5dd15 Mon Sep 17 00:00:00 2001 From: Martin Lippert Date: Tue, 19 Nov 2019 14:41:37 +0100 Subject: [PATCH] added configs for fetching live hover data to allow users to customize the behaviour --- .../boot/ls/BootJavaPreferencesPage.java | 3 ++ .../tooling/boot/ls/Constants.java | 7 ++++- .../DelegatingStreamConnectionProvider.java | 5 ++++ .../tooling/boot/ls/PrefsInitializer.java | 6 ++++ .../ide/vscode/boot/app/BootJavaConfig.java | 14 +++++++++ .../BootJavaLanguageServerComponents.java | 4 +++ .../v2/SpringProcessConnectorOverJMX.java | 3 +- .../v2/SpringProcessConnectorService.java | 29 +++++++++++++------ .../src/browser/boot-preferences.ts | 12 ++++++++ .../vscode-spring-boot/package.json | 10 +++++++ 10 files changed, 81 insertions(+), 12 deletions(-) diff --git a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/BootJavaPreferencesPage.java b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/BootJavaPreferencesPage.java index bbfc8da92..629ecf851 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/BootJavaPreferencesPage.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/BootJavaPreferencesPage.java @@ -86,6 +86,9 @@ public class BootJavaPreferencesPage extends FieldEditorPreferencePage implement addField(new BooleanFieldEditor(Constants.PREF_LIVE_INFORMATION_AUTOMATIC_TRACKING_ENABLED, "Live Information - Automatic Process Tracking Enabled", fieldEditorParent)); addField(new StringFieldEditor(Constants.PREF_LIVE_INFORMATION_AUTOMATIC_TRACKING_DELAY, "Live Information - Automatic Process Tracking Delay in ms", fieldEditorParent)); + addField(new BooleanFieldEditor(Constants.PREF_LIVE_INFORMATION_FETCH_DATA_RETRY_MAX_NO, "Live Information - Max number of retries (before giving up)", fieldEditorParent)); + addField(new StringFieldEditor(Constants.PREF_LIVE_INFORMATION_FETCH_DATA_RETRY_DELAY_IN_SECONDS, "Live Information - Delay between retries in seconds", fieldEditorParent)); + addField(new BooleanFieldEditor(PreferenceConstants.HIGHLIGHT_CODELENS_PREFS, "Highlights CodeLens", fieldEditorParent) { @Override public IPreferenceStore getPreferenceStore() { diff --git a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/Constants.java b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/Constants.java index 15ae81bc4..0346148ee 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/Constants.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/Constants.java @@ -20,11 +20,16 @@ public class Constants { public static final String PREF_LIVE_INFORMATION_AUTOMATIC_TRACKING_ENABLED = "boot-java.live-information.automatic-tracking.on"; public static final String PREF_LIVE_INFORMATION_AUTOMATIC_TRACKING_DELAY = "boot-java.live-information.automatic-tracking.delay"; + public static final String PREF_LIVE_INFORMATION_FETCH_DATA_RETRY_MAX_NO = "boot-java.live-information.fetch-data.max-retries"; + public static final String PREF_LIVE_INFORMATION_FETCH_DATA_RETRY_DELAY_IN_SECONDS = "boot-java.live-information.fetch-data.retry-delay-in-seconds"; + + public static final String PREF_SCAN_JAVA_TEST_SOURCES = "boot-java.scan-java-test-sources"; + public static final String PREF_SUPPORT_SPRING_XML_CONFIGS = "boot-java.support-spring-xml-config.on"; public static final String PREF_XML_CONFIGS_SCAN_FOLDERS = "boot-java.support-spring-xml-config.scan-folders-globs"; - public static final String PREF_SCAN_JAVA_TEST_SOURCES = "boot-java.scan-java-test-sources"; public static final String PREF_XML_CONFIGS_HYPERLINKS = "boot-java.support-spring-xml-config.hyperlinks"; public static final String PREF_XML_CONFIGS_CONTENT_ASSIST = "boot-java.support-spring-xml-config.content-assist"; + public static final String PREF_CHANGE_DETECTION = "boot-java.change-detection.on"; } diff --git a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/DelegatingStreamConnectionProvider.java b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/DelegatingStreamConnectionProvider.java index 862a0cb67..a81637bb4 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/DelegatingStreamConnectionProvider.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/DelegatingStreamConnectionProvider.java @@ -231,6 +231,7 @@ public class DelegatingStreamConnectionProvider implements StreamConnectionProvi Map bootJavaObj = new HashMap<>(); Map liveInformation = new HashMap<>(); Map liveInformationAutomaticTracking = new HashMap<>(); + Map liveInformationFetchData = new HashMap<>(); Map supportXML = new HashMap<>(); Map bootChangeDetection = new HashMap<>(); Map scanTestJavaSources = new HashMap<>(); @@ -240,7 +241,11 @@ public class DelegatingStreamConnectionProvider implements StreamConnectionProvi liveInformationAutomaticTracking.put("on", preferenceStore.getBoolean(Constants.PREF_LIVE_INFORMATION_AUTOMATIC_TRACKING_ENABLED)); liveInformationAutomaticTracking.put("delay", preferenceStore.getInt(Constants.PREF_LIVE_INFORMATION_AUTOMATIC_TRACKING_DELAY)); + liveInformationFetchData.put("max-retries", preferenceStore.getInt(Constants.PREF_LIVE_INFORMATION_FETCH_DATA_RETRY_MAX_NO)); + liveInformationFetchData.put("retry-delay-in-seconds", preferenceStore.getInt(Constants.PREF_LIVE_INFORMATION_FETCH_DATA_RETRY_DELAY_IN_SECONDS)); + liveInformation.put("automatic-tracking", liveInformationAutomaticTracking); + liveInformation.put("fetch-data", liveInformationFetchData); supportXML.put("on", preferenceStore.getBoolean(Constants.PREF_SUPPORT_SPRING_XML_CONFIGS)); supportXML.put("scan-folders", preferenceStore.getString(Constants.PREF_XML_CONFIGS_SCAN_FOLDERS)); diff --git a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/PrefsInitializer.java b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/PrefsInitializer.java index 88db25744..521ee9d89 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/PrefsInitializer.java +++ b/eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/PrefsInitializer.java @@ -27,13 +27,19 @@ public class PrefsInitializer extends AbstractPreferenceInitializer { @Override public void initializeDefaultPreferences() { IPreferenceStore preferenceStore = BootLanguageServerPlugin.getDefault().getPreferenceStore(); + preferenceStore.setDefault(Constants.PREF_LIVE_INFORMATION_AUTOMATIC_TRACKING_ENABLED, true); preferenceStore.setDefault(Constants.PREF_LIVE_INFORMATION_AUTOMATIC_TRACKING_DELAY, 5000); + preferenceStore.setDefault(Constants.PREF_LIVE_INFORMATION_FETCH_DATA_RETRY_MAX_NO, 10); + preferenceStore.setDefault(Constants.PREF_LIVE_INFORMATION_FETCH_DATA_RETRY_DELAY_IN_SECONDS, 3); + preferenceStore.setDefault(Constants.PREF_SUPPORT_SPRING_XML_CONFIGS, false); preferenceStore.setDefault(Constants.PREF_XML_CONFIGS_HYPERLINKS, true); preferenceStore.setDefault(Constants.PREF_XML_CONFIGS_CONTENT_ASSIST, true); preferenceStore.setDefault(Constants.PREF_XML_CONFIGS_SCAN_FOLDERS, "src/main"); + preferenceStore.setDefault(Constants.PREF_CHANGE_DETECTION, false); + preferenceStore.setDefault(Constants.PREF_SCAN_JAVA_TEST_SOURCES, false); } diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/BootJavaConfig.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/BootJavaConfig.java index 2806eae4f..051ad2c21 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/BootJavaConfig.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/app/BootJavaConfig.java @@ -32,6 +32,10 @@ public class BootJavaConfig implements InitializingBean { public static final boolean LIVE_INFORMATION_AUTOMATIC_TRACKING_ENABLED_DEFAULT = true; public static final int LIVE_INFORMATION_AUTOMATIC_TRACKING_DELAY_DEFAULT = 5000; + + public static final int LIVE_INFORMATION_FETCH_DATA_RETRY_MAX_NO_DEFAULT = 10; + public static final int LIVE_INFORMATION_FETCH_DATA_RETRY_DELAY_IN_SECONDS_DEFAULT = 3; + //TODO: Consider changing this to something that raises Spring application events. // I.e. like described in here: https://www.baeldung.com/spring-events @@ -54,6 +58,16 @@ public class BootJavaConfig implements InitializingBean { return delay != null ? delay.intValue() : LIVE_INFORMATION_AUTOMATIC_TRACKING_DELAY_DEFAULT; } + public int getLiveInformationFetchDataMaxRetryCount() { + Integer delay = settings.getInt("boot-java", "live-information", "fetch-data", "max-retries"); + return delay != null ? delay.intValue() : LIVE_INFORMATION_FETCH_DATA_RETRY_MAX_NO_DEFAULT; + } + + public int getLiveInformationFetchDataRetryDelayInSeconds() { + Integer delay = settings.getInt("boot-java", "live-information", "fetch-data", "retry-delay-in-seconds"); + return delay != null ? delay.intValue() : LIVE_INFORMATION_FETCH_DATA_RETRY_DELAY_IN_SECONDS_DEFAULT; + } + public boolean isSpringXMLSupportEnabled() { Boolean enabled = settings.getBoolean("boot-java", "support-spring-xml-config", "on"); return enabled != null && enabled.booleanValue(); diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/BootJavaLanguageServerComponents.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/BootJavaLanguageServerComponents.java index e2785cf6f..2a89e2fee 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/BootJavaLanguageServerComponents.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/BootJavaLanguageServerComponents.java @@ -199,6 +199,10 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent liveProcessTracker.setDelay(config.getLiveInformationAutomaticTrackingDelay()); liveProcessTracker.setTrackingEnabled(config.isLiveInformationAutomaticTrackingEnabled()); + // live information data fetch params + liveDataService.setMaxRetryCount(config.getLiveInformationFetchDataMaxRetryCount()); + liveDataService.setRetryDelayInSeconds(config.getLiveInformationFetchDataRetryDelayInSeconds()); + // live change detection watchdog if (config.isChangeDetectionEnabled()) { liveChangeDetectionWatchdog.enableHighlights(); diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessConnectorOverJMX.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessConnectorOverJMX.java index 70b8f9cc7..5469e665e 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessConnectorOverJMX.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessConnectorOverJMX.java @@ -39,8 +39,7 @@ public class SpringProcessConnectorOverJMX implements SpringProcessConnector { private final String jmxURL; private final String urlScheme; private final String port; - final private String projectName; - + private final String projectName; // not final, might be updated with data from JMX process, if not initially set private String processID; diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessConnectorService.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessConnectorService.java index a885b9c71..24f25a26a 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessConnectorService.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessConnectorService.java @@ -18,6 +18,7 @@ import java.util.concurrent.TimeUnit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.ide.vscode.commons.languageserver.ProgressTask; +import org.springframework.ide.vscode.boot.app.BootJavaConfig; import org.springframework.ide.vscode.commons.languageserver.ProgressService; /** @@ -27,9 +28,6 @@ public class SpringProcessConnectorService { private static final Logger log = LoggerFactory.getLogger(SpringProcessConnectorService.class); - private static final int RETRY_MAX_NO = 10; - private static final int RETRY_DELAY_IN_SECONDS = 3; - private final SpringProcessLiveDataProvider liveDataProvider; private final ScheduledThreadPoolExecutor scheduler; @@ -41,6 +39,8 @@ public class SpringProcessConnectorService { private final ProgressService progressService; private int progressIdKey = 0; + private int maxRetryCount; + private int retryDelayInSeconds; public SpringProcessConnectorService(ProgressService progressService, SpringProcessLiveDataProvider liveDataProvider) { this.liveDataProvider = liveDataProvider; @@ -49,6 +49,9 @@ public class SpringProcessConnectorService { this.connectedSuccess = new ConcurrentHashMap<>(); this.progressService = progressService == null ? ProgressService.NO_PROGRESS : progressService; + this.maxRetryCount = BootJavaConfig.LIVE_INFORMATION_FETCH_DATA_RETRY_MAX_NO_DEFAULT; + this.retryDelayInSeconds = BootJavaConfig.LIVE_INFORMATION_FETCH_DATA_RETRY_DELAY_IN_SECONDS_DEFAULT; + this.connectorListener = new SpringProcessConnectionChangeListener() { @Override public void connectionClosed(String processKey) { @@ -57,6 +60,14 @@ public class SpringProcessConnectorService { }; } + public void setMaxRetryCount(int maxRetryCount) { + this.maxRetryCount = maxRetryCount; + } + + public void setRetryDelayInSeconds(int retryDelayInSeconds) { + this.retryDelayInSeconds = retryDelayInSeconds; + } + public void connectProcess(String processKey, SpringProcessConnector connector) { log.info("connect to process: " + processKey); @@ -130,8 +141,8 @@ public class SpringProcessConnectorService { catch (Exception e) { log.info("problem occured during process connect", e); - if (retryNo < RETRY_MAX_NO) { - scheduleConnect(connectProgressTask, processKey, connector, RETRY_DELAY_IN_SECONDS, TimeUnit.SECONDS, retryNo + 1); + if (retryNo < maxRetryCount) { + scheduleConnect(connectProgressTask, processKey, connector, retryDelayInSeconds, TimeUnit.SECONDS, retryNo + 1); } else { connectProgressTask.progressDone(); } @@ -149,8 +160,8 @@ public class SpringProcessConnectorService { catch (Exception e) { log.info("problem occured during process disconnect", e); - if (retryNo < RETRY_MAX_NO) { - scheduleDisconnect(processKey, connector, RETRY_DELAY_IN_SECONDS, TimeUnit.SECONDS, retryNo + 1); + if (retryNo < maxRetryCount) { + scheduleDisconnect(processKey, connector, retryDelayInSeconds, TimeUnit.SECONDS, retryNo + 1); } } }, delay, unit); @@ -183,8 +194,8 @@ public class SpringProcessConnectorService { log.info("problem occured during process live data refresh", e); - if (retryNo < RETRY_MAX_NO) { - scheduleRefresh(refreshProgressTask, processKey, connector, RETRY_DELAY_IN_SECONDS, TimeUnit.SECONDS, + if (retryNo < maxRetryCount) { + scheduleRefresh(refreshProgressTask, processKey, connector, retryDelayInSeconds, TimeUnit.SECONDS, retryNo + 1); } else { diff --git a/theia-extensions/theia-spring-boot/spring-boot/src/browser/boot-preferences.ts b/theia-extensions/theia-spring-boot/spring-boot/src/browser/boot-preferences.ts index c473ddc6f..8adc5d1d1 100644 --- a/theia-extensions/theia-spring-boot/spring-boot/src/browser/boot-preferences.ts +++ b/theia-extensions/theia-spring-boot/spring-boot/src/browser/boot-preferences.ts @@ -30,6 +30,16 @@ export const BootConfigSchema: PreferenceSchema = { description: 'Live Information - Automatic Process Tracking Delay in ms', default: 5000 }, + 'boot-java.live-information.fetch-data.max-retries': { + type: 'number', + default: 10, + description: 'Live Information - Max number of retries (before giving up)' + }, + 'boot-java.live-information.fetch-data.retry-delay-in-seconds': { + type: 'number', + default: 3, + description: 'Live Information - Delay between retries in seconds' + }, 'boot-java.scan-java-test-sources.on': { type: 'boolean', description: 'Enable/Disable Java test sources files scanning', @@ -81,6 +91,8 @@ export const BootConfigSchema: PreferenceSchema = { export interface BootConfiguration { 'boot-java.live-information.automatic-tracking.on': boolean; 'boot-java.live-information.automatic-tracking.delay': number; + 'boot-java.live-information.fetch-data.max-retries': number; + 'boot-java.live-information.fetch-data.retry-delay-in-seconds': number; 'boot-java.scan-java-test-sources.on': boolean; 'boot-java.support-spring-xml-config.on': boolean; 'boot-java.support-spring-xml-config.hyperlinks': boolean; diff --git a/vscode-extensions/vscode-spring-boot/package.json b/vscode-extensions/vscode-spring-boot/package.json index c89d52cf1..4ffaed2bd 100644 --- a/vscode-extensions/vscode-spring-boot/package.json +++ b/vscode-extensions/vscode-spring-boot/package.json @@ -84,6 +84,16 @@ "default": 5000, "description": "Live Information - Automatic Process Tracking Delay in ms" }, + "boot-java.live-information.fetch-data.max-retries": { + "type": "number", + "default": 10, + "description": "Live Information - Max number of retries (before giving up)" + }, + "boot-java.live-information.fetch-data.retry-delay-in-seconds": { + "type": "number", + "default": 3, + "description": "Live Information - Delay between retries in seconds" + }, "boot-java.scan-java-test-sources.on": { "type": "boolean", "default": false,