Skip to content

Commit

Permalink
fix: Remove exception from close method (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
thced authored Nov 10, 2023
1 parent 724784c commit c5dbd6f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/retailsvc/gcp/pubsub/PubSubClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ void publish(Object payloadObject, Map<String, String> attributesMap)
* @return True if client has been closed, false otherwise.
*/
boolean isClosed();

@Override
void close();
}
21 changes: 13 additions & 8 deletions src/main/java/com/retailsvc/gcp/pubsub/PubSubClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,18 @@ protected void publish(ByteString payload, Map<String, String> attributes) {
}

@Override
public void close() throws Exception {
Integer timeout =
Optional.ofNullable(System.getenv(PUBSUB_CLOSE_TIMEOUT_SECONDS))
.map(Integer::parseInt)
.orElse(DEFAULT_CLOSE_TIMEOUT);
this.isClosed.set(true);
publisher.shutdown();
publisher.awaitTermination(timeout, TimeUnit.SECONDS);
public void close() {
try {
Integer timeout =
Optional.ofNullable(System.getenv(PUBSUB_CLOSE_TIMEOUT_SECONDS))
.map(Integer::parseInt)
.orElse(DEFAULT_CLOSE_TIMEOUT);
this.isClosed.set(true);
publisher.shutdown();
publisher.awaitTermination(timeout, TimeUnit.SECONDS);
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
LOG.error("Interrupted while closing client");
}
}
}

0 comments on commit c5dbd6f

Please sign in to comment.