Skip to content

Commit c65f7dc

Browse files
authored
better pause AuthManager
better pause AuthManager
2 parents 282368e + 3dcfb3e commit c65f7dc

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public AnalyticsService(@NotNull Project project) {
107107
if (shouldReplaceClient) {
108108
Log.log(LOGGER::debug, "api url changed to {}, calling replace client", myApiUrl);
109109
AuthManager.getInstance().logout();
110-
AuthManager.getInstance().pauseCurrentProxy();
110+
AuthManager.getInstance().pauseBeforeClientChange();
111111
replaceClient(myApiUrl);
112112
}
113113

ide-common/src/main/kotlin/org/digma/intellij/plugin/auth/AuthManager.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class AuthManager {
4545
private var analyticsProvider: RestAnalyticsProvider? = null
4646

4747
private val loginOrRefreshLock = ReentrantLock()
48-
private val isProxyPaused: AtomicBoolean = AtomicBoolean(true)
48+
private val isPaused: AtomicBoolean = AtomicBoolean(true)
4949

5050
companion object {
5151
@JvmStatic
@@ -96,7 +96,7 @@ class AuthManager {
9696
)
9797

9898
Log.log(logger::info, "resuming current proxy, analytics url {}", analyticsProvider?.apiUrl)
99-
isProxyPaused.set(false)
99+
isPaused.set(false)
100100
return proxy
101101
}
102102

@@ -281,6 +281,10 @@ class AuthManager {
281281

282282
private fun fireChange() {
283283

284+
if (isPaused.get()) {
285+
return
286+
}
287+
284288
Log.log(
285289
logger::trace, "firing authInfoChanged, default account {}, analytics url {}",
286290
DigmaDefaultAccountHolder.getInstance().account,
@@ -298,10 +302,12 @@ class AuthManager {
298302
}
299303

300304

301-
fun pauseCurrentProxy() {
305+
//pause the AuthManager before replacing the analytics provider.
306+
//can be resumed only from this class after a new client is set
307+
fun pauseBeforeClientChange() {
302308
Log.log(logger::info, "pausing current proxy, analytics url {}", analyticsProvider?.apiUrl)
303309
analyticsProvider = null
304-
isProxyPaused.set(true)
310+
isPaused.set(true)
305311
}
306312

307313

@@ -467,7 +473,7 @@ class AuthManager {
467473
} catch (e: InvocationTargetException) {
468474

469475
Log.debugWithException(logger, e, "Exception in proxy {}", ExceptionUtils.getNonEmptyMessage(e))
470-
if (isProxyPaused.get()) {
476+
if (isPaused.get()) {
471477
Log.log(logger::trace, "got Exception in proxy but proxy is paused, rethrowing")
472478
throw e
473479
}

0 commit comments

Comments
 (0)