2424import org .digma .intellij .plugin .analytics .AnalyticsServiceException ;
2525import org .digma .intellij .plugin .analytics .BackendConnectionMonitor ;
2626import org .digma .intellij .plugin .analytics .EnvironmentChanged ;
27+ import org .digma .intellij .plugin .common .AsynchronousBackgroundTask ;
2728import org .digma .intellij .plugin .common .Backgroundable ;
2829import org .digma .intellij .plugin .common .CommonUtils ;
2930import org .digma .intellij .plugin .log .Log ;
4243import java .awt .*;
4344import java .util .ArrayList ;
4445import java .util .Collections ;
45- import java .util .Date ;
4646import java .util .List ;
4747import java .util .Map ;
48+ import java .util .concurrent .locks .ReentrantLock ;
4849
4950import static org .digma .intellij .plugin .toolwindow .recentactivity .ToolWindowUtil .RECENT_ACTIVITY_GET_DATA ;
5051import static org .digma .intellij .plugin .toolwindow .recentactivity .ToolWindowUtil .RECENT_ACTIVITY_GO_TO_SPAN ;
@@ -68,6 +69,8 @@ public class DigmaBottomToolWindowFactory implements ToolWindowFactory {
6869 private AnalyticsService analyticsService ;
6970 private String localHostname ;
7071
72+ private ReentrantLock recentActivityGetDataLock = new ReentrantLock ();
73+
7174 /**
7275 * this is the starting point of the plugin. this method is called when the tool window is opened.
7376 * before the window is opened there may be no reason to do anything, listen to events for example will be
@@ -125,15 +128,16 @@ public boolean onQuery(CefBrowser browser, CefFrame frame, long queryId, String
125128 Log .log (LOGGER ::debug , "request: {}" , request );
126129 JcefMessageRequest reactMessageRequest = parseJsonToObject (request , JcefMessageRequest .class );
127130 if (RECENT_ACTIVITY_GET_DATA .equalsIgnoreCase (reactMessageRequest .getAction ())) {
128- return processRecentActivityGetDataRequest (analyticsService , jbCefBrowser , callback );
131+ new AsynchronousBackgroundTask (recentActivityGetDataLock ,
132+ () -> processRecentActivityGetDataRequest (analyticsService , jbCefBrowser )).queue ();
129133 }
130134 if (RECENT_ACTIVITY_GO_TO_SPAN .equalsIgnoreCase (reactMessageRequest .getAction ())) {
131135 RecentActivityGoToSpanRequest recentActivityGoToSpanRequest = parseJsonToObject (request , RecentActivityGoToSpanRequest .class );
132- return processRecentActivityGoToSpanRequest (recentActivityGoToSpanRequest .getPayload (), project , callback );
136+ processRecentActivityGoToSpanRequest (recentActivityGoToSpanRequest .getPayload (), project );
133137 }
134138 if (RECENT_ACTIVITY_GO_TO_TRACE .equalsIgnoreCase (reactMessageRequest .getAction ())) {
135139 RecentActivityGoToTraceRequest recentActivityGoToTraceRequest = parseJsonToObject (request , RecentActivityGoToTraceRequest .class );
136- return processRecentActivityGoToTraceRequest (recentActivityGoToTraceRequest , project , callback );
140+ processRecentActivityGoToTraceRequest (recentActivityGoToTraceRequest , project );
137141 }
138142
139143 callback .success ("" );
@@ -163,7 +167,7 @@ public void onQueryCanceled(CefBrowser browser, CefFrame frame, long queryId) {
163167 return jcefContent ;
164168 }
165169
166- private boolean processRecentActivityGoToSpanRequest (RecentActivityEntrySpanPayload payload , Project project , CefQueryCallback callback ) {
170+ private void processRecentActivityGoToSpanRequest (RecentActivityEntrySpanPayload payload , Project project ) {
167171 if (payload != null ) {
168172 String methodCodeObjectId = payload .getSpan ().getMethodCodeObjectId ();
169173
@@ -186,46 +190,39 @@ private boolean processRecentActivityGoToSpanRequest(RecentActivityEntrySpanPayl
186190 }
187191 }
188192 });
189- callback .success (SUCCESSFULLY_PROCESSED_JCEF_REQUEST_MESSAGE + " RECENT_ACTIVITY_GO_TO_SPAN at " + new Date ());
190- return true ;
191- } else {
192- return false ;
193193 }
194194 }
195195
196- private boolean processRecentActivityGoToTraceRequest (RecentActivityGoToTraceRequest recentActivityGoToTraceRequest , Project project , CefQueryCallback callback ) {
196+ private void processRecentActivityGoToTraceRequest (RecentActivityGoToTraceRequest recentActivityGoToTraceRequest , Project project ) {
197197 RecentActivityEntrySpanForTracePayload payload = recentActivityGoToTraceRequest .getPayload ();
198198 if (payload != null ) {
199199 openJaegerFromRecentActivity (project , payload .getTraceId (), payload .getSpan ().getScopeId ());
200200 } else {
201201 Log .log (LOGGER ::debug , "processRecentActivityGoToTraceRequest payload is empty" );
202202 }
203- callback .success (SUCCESSFULLY_PROCESSED_JCEF_REQUEST_MESSAGE + " RECENT_ACTIVITY_GO_TO_TRACE at " + new Date ());
204- return true ;
205203 }
206204
207- private boolean processRecentActivityGetDataRequest (AnalyticsService analyticsService , JBCefBrowser jbCefBrowser , CefQueryCallback callback ) {
205+ private void processRecentActivityGetDataRequest (AnalyticsService analyticsService , JBCefBrowser jbCefBrowser ) {
208206 List <String > allEnvironments = analyticsService .getEnvironments ();
209207 List <String > sortedEnvironments = getSortedEnvironments (allEnvironments , localHostname );
210208 RecentActivityResult recentActivityData = null ;
211209 try {
212210 recentActivityData = analyticsService .getRecentActivity (allEnvironments );
213211 } catch (AnalyticsServiceException e ) {
214- Log .log (LOGGER ::debug , "AnalyticsServiceException for getRecentActivity: {}" , e .getMessage ());
212+ Log .log (LOGGER ::warn , "AnalyticsServiceException for getRecentActivity: {}" , e .getMessage ());
213+ }
214+ if (recentActivityData != null ) {
215+ String requestMessage = JBCefBrowserUtil .resultToString (new JcefMessageRequest (
216+ REQUEST_MESSAGE_TYPE ,
217+ RECENT_ACTIVITY_SET_DATA ,
218+ new JcefMessagePayload (
219+ sortedEnvironments ,
220+ getEntriesWithAdjustedLocalEnvs (recentActivityData )
221+ )
222+ ));
223+
224+ JBCefBrowserUtil .postJSMessage (requestMessage , jbCefBrowser );
215225 }
216- String requestMessage = JBCefBrowserUtil .resultToString (new JcefMessageRequest (
217- REQUEST_MESSAGE_TYPE ,
218- RECENT_ACTIVITY_SET_DATA ,
219- new JcefMessagePayload (
220- sortedEnvironments ,
221- getEntriesWithAdjustedLocalEnvs (recentActivityData )
222- )
223- ));
224-
225- JBCefBrowserUtil .postJSMessage (requestMessage , jbCefBrowser );
226-
227- callback .success (SUCCESSFULLY_PROCESSED_JCEF_REQUEST_MESSAGE + " RECENT_ACTIVITY_SET_DATA at " + new Date ());
228- return true ;
229226 }
230227
231228 private List <RecentActivityResponseEntry > getEntriesWithAdjustedLocalEnvs (RecentActivityResult recentActivityData ) {
@@ -244,7 +241,7 @@ private List<RecentActivityResponseEntry> getEntriesWithAdjustedLocalEnvs(Recent
244241 }
245242
246243 private String getAdjustedEnvName (String environment ) {
247- return environment .toUpperCase ().endsWith (SUFFIX_OF_LOCAL ) ? LOCAL_ENV : environment ;
244+ return environment .toUpperCase ().endsWith (SUFFIX_OF_LOCAL ) ? LOCAL_ENV : environment ;
248245 }
249246
250247 private String adjustBackEnvNameIfNeeded (String environment ) {
0 commit comments