From c5dbd6fb835a9dd460e73a29d2e26224b4c9d5b4 Mon Sep 17 00:00:00 2001 From: Thomas Cederholm Date: Fri, 10 Nov 2023 21:12:47 +0100 Subject: [PATCH] fix: Remove exception from close method (#3) --- .../retailsvc/gcp/pubsub/PubSubClient.java | 3 +++ .../gcp/pubsub/PubSubClientImpl.java | 21 ++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/retailsvc/gcp/pubsub/PubSubClient.java b/src/main/java/com/retailsvc/gcp/pubsub/PubSubClient.java index 97f6176..af74dc1 100644 --- a/src/main/java/com/retailsvc/gcp/pubsub/PubSubClient.java +++ b/src/main/java/com/retailsvc/gcp/pubsub/PubSubClient.java @@ -24,4 +24,7 @@ void publish(Object payloadObject, Map attributesMap) * @return True if client has been closed, false otherwise. */ boolean isClosed(); + + @Override + void close(); } diff --git a/src/main/java/com/retailsvc/gcp/pubsub/PubSubClientImpl.java b/src/main/java/com/retailsvc/gcp/pubsub/PubSubClientImpl.java index f011c8b..60b50eb 100644 --- a/src/main/java/com/retailsvc/gcp/pubsub/PubSubClientImpl.java +++ b/src/main/java/com/retailsvc/gcp/pubsub/PubSubClientImpl.java @@ -88,13 +88,18 @@ protected void publish(ByteString payload, Map 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"); + } } }