Skip to content

Commit 73cad3a

Browse files
Fix envs setting on connection reestablished event #303
1 parent 2acb78c commit 73cad3a

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
import org.digma.intellij.plugin.model.rest.debugger.DebuggerEventRequest;
1414
import org.digma.intellij.plugin.model.rest.errordetails.CodeObjectErrorDetails;
1515
import org.digma.intellij.plugin.model.rest.errors.CodeObjectError;
16-
import org.digma.intellij.plugin.model.rest.insights.*;
16+
import org.digma.intellij.plugin.model.rest.insights.CodeObjectInsight;
17+
import org.digma.intellij.plugin.model.rest.insights.CustomStartTimeInsightRequest;
18+
import org.digma.intellij.plugin.model.rest.insights.GlobalInsight;
19+
import org.digma.intellij.plugin.model.rest.insights.InsightsRequest;
20+
import org.digma.intellij.plugin.model.rest.insights.SpanHistogramQuery;
1721
import org.digma.intellij.plugin.model.rest.usage.UsageStatusRequest;
1822
import org.digma.intellij.plugin.model.rest.usage.UsageStatusResult;
1923
import org.digma.intellij.plugin.notifications.NotificationUtil;
@@ -34,8 +38,15 @@
3438
import java.net.UnknownHostException;
3539
import java.net.http.HttpTimeoutException;
3640
import java.time.Instant;
37-
import java.util.*;
41+
import java.util.ArrayList;
42+
import java.util.Arrays;
43+
import java.util.Collections;
44+
import java.util.HashMap;
45+
import java.util.List;
46+
import java.util.Map;
47+
import java.util.Objects;
3848
import java.util.concurrent.TimeUnit;
49+
import java.util.concurrent.atomic.AtomicBoolean;
3950
import java.util.function.Supplier;
4051
import java.util.stream.Collectors;
4152

@@ -305,6 +316,9 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
305316

306317
//reset status on success call
307318
if (status.isInConnectionError()) {
319+
// change status here because connectionGained() will trigger call to this invoke() again
320+
// and without changing the status Notification will be displayed several times in a loop
321+
status.ok();
308322
NotificationUtil.showNotification(project, "Digma: Connection reestablished !");
309323
project.getMessageBus().syncPublisher(AnalyticsServiceConnectionEvent.ANALYTICS_SERVICE_CONNECTION_EVENT_TOPIC).connectionGained();
310324
}
@@ -463,29 +477,29 @@ private static class Status {
463477

464478
private final Map<String, Boolean> errorsHistory = new HashMap<>();
465479

466-
private boolean hadConnectException = false;
480+
private final AtomicBoolean hadConnectException = new AtomicBoolean(false);
467481
private boolean hadError = false;
468482

469483
boolean isInError() {
470-
return hadConnectException || hadError;
484+
return hadConnectException.get() || hadError;
471485
}
472486

473487
boolean isInConnectionError() {
474-
return hadConnectException;
488+
return hadConnectException.get();
475489
}
476490

477491
boolean isOk() {
478492
return !isInError();
479493
}
480494

481495
public void ok() {
482-
hadConnectException = false;
496+
hadConnectException.set(false);
483497
hadError = false;
484498
errorsHistory.clear();
485499
}
486500

487501
public void connectError() {
488-
hadConnectException = true;
502+
hadConnectException.set(true);
489503
}
490504

491505

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public void connectionLost() {
5555

5656
@Override
5757
public void connectionGained() {
58-
//do nothing ,usually connectionGained will be a result of refresh environment
58+
if (getCurrent() == null || getCurrent().isEmpty()) {
59+
refreshNowOnBackground();
60+
}
5961
}
6062
});
6163
}

0 commit comments

Comments
 (0)