Skip to content

Commit 1bf5f65

Browse files
authored
Background thread on settings change (#1968)
* background-thread-on-settings-change * background-thread-on-settings-change
1 parent 444407d commit 1bf5f65

File tree

4 files changed

+48
-26
lines changed

4 files changed

+48
-26
lines changed

ide-common/src/main/java/org/digma/intellij/plugin/common/EDT.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public static void assertIsDispatchThread(){
4747

4848
public static void assertNonDispatchThread(){
4949
if (ApplicationManager.getApplication().isDispatchThread()) {
50-
RuntimeException runtimeException = new RuntimeException("Must not run on EDT");
51-
LOGGER.error("Must not run on EDT", runtimeException);
52-
ErrorReporter.getInstance().reportInternalFatalError("assertNonDispatchThread", runtimeException, Collections.emptyMap());
53-
throw runtimeException;
50+
EDTAccessException edtAccessException = new EDTAccessException("Must not run on EDT");
51+
LOGGER.error("Must not run on EDT", edtAccessException);
52+
ErrorReporter.getInstance().reportInternalFatalError("assertNonDispatchThread", edtAccessException, Collections.emptyMap());
53+
throw edtAccessException;
5454
}
5555
}
5656

@@ -63,4 +63,12 @@ public static boolean isEdt() {
6363
public static void invokeAndWait(@NotNull Runnable task) {
6464
ApplicationManager.getApplication().invokeAndWait(task);
6565
}
66+
67+
68+
public static class EDTAccessException extends RuntimeException {
69+
public EDTAccessException(String message) {
70+
super(message);
71+
}
72+
}
73+
6674
}

ide-common/src/main/java/org/digma/intellij/plugin/common/ReadActions.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public static void assertReadAccessAllowed() {
1717

1818
public static void assertNotInReadAccess() {
1919
if (ApplicationManager.getApplication().isReadAccessAllowed()) {
20-
RuntimeException runtimeException = new RuntimeException("Must not run in read access");
21-
LOGGER.error("Must not run in read access", runtimeException);
22-
ErrorReporter.getInstance().reportInternalFatalError("assertNotInReadAccess", runtimeException, Collections.emptyMap());
23-
throw runtimeException;
20+
ReadAccessException readAccessException = new ReadAccessException("Must not run in read access");
21+
LOGGER.error("Must not run in read access", readAccessException);
22+
ErrorReporter.getInstance().reportInternalFatalError("assertNotInReadAccess", readAccessException, Collections.emptyMap());
23+
throw readAccessException;
2424
}
2525
}
2626

@@ -47,4 +47,11 @@ public static void ensureReadAction(Runnable runnable){
4747
public static boolean isReadAccessAllowed() {
4848
return ApplicationManager.getApplication().isReadAccessAllowed();
4949
}
50+
51+
52+
public static class ReadAccessException extends RuntimeException {
53+
public ReadAccessException(String message) {
54+
super(message);
55+
}
56+
}
5057
}

ide-common/src/main/kotlin/org/digma/intellij/plugin/posthog/SettingsChangeTracker.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.digma.intellij.plugin.posthog
22

3+
import org.digma.intellij.plugin.common.Backgroundable
34
import org.digma.intellij.plugin.settings.SettingsState
45

56
class SettingsChangeTracker {
@@ -12,18 +13,20 @@ class SettingsChangeTracker {
1213

1314
fun start(activityMonitor: ActivityMonitor) {
1415

15-
activityMonitor.registerSettingsEvent("initial",myTrackedSettings)
16+
activityMonitor.registerSettingsEvent("initial", myTrackedSettings)
1617

1718
SettingsState.getInstance().addChangeListener(
1819
{
19-
val oldSettings = mutableMapOf<String,String>()
20-
oldSettings.putAll(myTrackedSettings)
21-
updateTrackedSettings()
22-
val diff = getDiff(oldSettings,myTrackedSettings)
23-
activityMonitor.registerSettingsEvent("change",diff)
24-
20+
Backgroundable.executeOnPooledThread {
21+
val oldSettings = mutableMapOf<String, String>()
22+
oldSettings.putAll(myTrackedSettings)
23+
updateTrackedSettings()
24+
val diff = getDiff(oldSettings, myTrackedSettings)
25+
activityMonitor.registerSettingsEvent("change", diff)
26+
}
2527
},
26-
activityMonitor)
28+
activityMonitor
29+
)
2730
}
2831

2932
private fun getDiff(oldSettings: MutableMap<String, String>, myTrackedSettings: MutableMap<String, String>): Map<String,String> {

src/main/kotlin/org/digma/intellij/plugin/ui/jcef/JCefComponent.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import org.cef.handler.CefLifeSpanHandlerAdapter
1717
import org.digma.intellij.plugin.analytics.AnalyticsService
1818
import org.digma.intellij.plugin.analytics.AnalyticsServiceConnectionEvent
1919
import org.digma.intellij.plugin.analytics.EnvironmentChanged
20+
import org.digma.intellij.plugin.common.Backgroundable
2021
import org.digma.intellij.plugin.docker.DockerService
2122
import org.digma.intellij.plugin.env.Env
2223
import org.digma.intellij.plugin.errorreporting.ErrorReporter
@@ -111,16 +112,19 @@ private constructor(
111112

112113

113114
SettingsState.getInstance().addChangeListener({ settings ->
114-
try {
115-
val apiUrl = settings.apiUrl
116-
sendApiUrl(jbCefBrowser.cefBrowser, apiUrl)
117-
sendIsMicrometerProject(jbCefBrowser.cefBrowser, SpringBootMicrometerConfigureDepsService.isSpringBootWithMicrometer())
118-
sendIsJaegerButtonEnabledMessage(jbCefBrowser.cefBrowser)
119-
sendBackendAboutInfo(jbCefBrowser.cefBrowser, project)
120-
val status = service<DockerService>().getCurrentDigmaInstallationStatusOnConnectionLost()
121-
updateDigmaEngineStatus(jbCefBrowser.cefBrowser, status)
122-
} catch (e: Throwable) {
123-
ErrorReporter.getInstance().reportError("JCefComponent.settingsChanged", e)
115+
//this event run on EDT
116+
Backgroundable.executeOnPooledThread {
117+
try {
118+
val apiUrl = settings.apiUrl
119+
sendApiUrl(jbCefBrowser.cefBrowser, apiUrl)
120+
sendIsMicrometerProject(jbCefBrowser.cefBrowser, SpringBootMicrometerConfigureDepsService.isSpringBootWithMicrometer())
121+
sendIsJaegerButtonEnabledMessage(jbCefBrowser.cefBrowser)
122+
sendBackendAboutInfo(jbCefBrowser.cefBrowser, project)
123+
val status = service<DockerService>().getCurrentDigmaInstallationStatusOnConnectionLost()
124+
updateDigmaEngineStatus(jbCefBrowser.cefBrowser, status)
125+
} catch (e: Throwable) {
126+
ErrorReporter.getInstance().reportError("JCefComponent.settingsChanged", e)
127+
}
124128
}
125129
}, settingsListenerParentDisposable)
126130

0 commit comments

Comments
 (0)