Skip to content

Commit

Permalink
Make singleton
Browse files Browse the repository at this point in the history
Signed-off-by: Siddhant Deshmukh <deshsid@amazon.com>
  • Loading branch information
deshsidd committed Jul 18, 2024
1 parent 49bcc31 commit 2c3e40a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ private void executeRequest(
originalSearchRequest,
logger,
TraceableSearchRequestOperationsListener.create(tracer, requestSpan),
new SearchTaskRequestOperationsListener(taskResourceTrackingService)
SearchTaskRequestOperationsListener.getInstance(taskResourceTrackingService)
);
SearchRequestContext searchRequestContext = new SearchRequestContext(
requestOperationsListeners,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@
*
*/
public final class SearchTaskRequestOperationsListener extends SearchRequestOperationsListener {
private static SearchTaskRequestOperationsListener instance;
private final TaskResourceTrackingService taskResourceTrackingService;

public SearchTaskRequestOperationsListener(TaskResourceTrackingService taskResourceTrackingService) {
private SearchTaskRequestOperationsListener(TaskResourceTrackingService taskResourceTrackingService) {
this.taskResourceTrackingService = taskResourceTrackingService;
}

public static synchronized SearchTaskRequestOperationsListener getInstance(TaskResourceTrackingService taskResourceTrackingService) {
if (instance == null) {
instance = new SearchTaskRequestOperationsListener(taskResourceTrackingService);
}
return instance;
}

@Override
public void onRequestEnd(SearchPhaseContext context, SearchRequestContext searchRequestContext) {
taskResourceTrackingService.refreshResourceStats(context.getTask());
Expand Down

0 comments on commit 2c3e40a

Please sign in to comment.