Skip to content

Commit

Permalink
adds Close method for local client to gracefully shutdown Config and …
Browse files Browse the repository at this point in the history
…Event Managers
  • Loading branch information
kaushalkapasi committed Feb 10, 2023
1 parent dfd62af commit 7039170
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public final class DVCLocalClient {

private EventQueueManager eventQueueManager;

private Boolean isInitialized = false;

public DVCLocalClient(String serverKey) {
this(serverKey, DVCLocalOptions.builder().build());
}
Expand All @@ -35,6 +37,7 @@ public DVCLocalClient(String serverKey, DVCLocalOptions dvcOptions) {
} catch (Exception e) {
System.out.printf("Error creating event queue due to error: %s%n", e.getMessage());
}
isInitialized = true;
}

/**
Expand Down Expand Up @@ -143,6 +146,18 @@ public void track(User user, Event event) {
}
}

/**
* Gracefully close the client
*
*/
public void close() {
if (!isInitialized) {
return;
}
configManager.cleanup();
eventQueueManager.cleanup();
}

private void validateUser(User user) {
if (user == null) {
throw new IllegalArgumentException("User cannot be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ private ProjectConfig getConfigResponse(Call<ProjectConfig> call) throws DVCExce
throw new DVCException(httpResponseCode, errorResponse);
}
}

public void cleanup() {
scheduler.shutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,13 @@ private boolean checkEventQueueSize() throws Exception {
}
return false;
}

public void cleanup() {
try {
flushEvents();
} catch (Exception e) {
System.out.printf("DVC Cleanup error: %s%n", e.getMessage());
}
scheduler.shutdown();
}
}

0 comments on commit 7039170

Please sign in to comment.