Skip to content

Commit

Permalink
feat: add close method to UpdateChecker
Browse files Browse the repository at this point in the history
Executes shutdownNow() on it's executor service
  • Loading branch information
khakers committed Jan 23, 2024
1 parent 0bb58ff commit 1d6a9ac
Showing 1 changed file with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.Closeable;
import java.io.IOException;
import java.time.Instant;
import java.util.Optional;
Expand All @@ -15,7 +16,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

public class UpdateChecker {
public class UpdateChecker implements AutoCloseable {

private static final Logger logger = LogManager.getLogger();

Expand Down Expand Up @@ -49,6 +50,7 @@ public UpdateChecker() {

}


public static boolean isContainerized() {
return System.getProperty("ENV_TYPE").equalsIgnoreCase("containerized");
}
Expand Down Expand Up @@ -132,5 +134,53 @@ public boolean isSemVerUpdateAvailable(String version) {
}


/**
* Closes this resource, relinquishing any underlying resources.
* This method is invoked automatically on objects managed by the
* {@code try}-with-resources statement.
*
* @throws Exception if this resource cannot be closed
* @apiNote While this interface method is declared to throw {@code
* Exception}, implementers are <em>strongly</em> encouraged to
* declare concrete implementations of the {@code close} method to
* throw more specific exceptions, or to throw no exception at all
* if the close operation cannot fail.
*
* <p> Cases where the close operation may fail require careful
* attention by implementers. It is strongly advised to relinquish
* the underlying resources and to internally <em>mark</em> the
* resource as closed, prior to throwing the exception. The {@code
* close} method is unlikely to be invoked more than once and so
* this ensures that the resources are released in a timely manner.
* Furthermore it reduces problems that could arise when the resource
* wraps, or is wrapped, by another resource.
*
* <p><em>Implementers of this interface are also strongly advised
* to not have the {@code close} method throw {@link
* InterruptedException}.</em>
* <p>
* This exception interacts with a thread's interrupted status,
* and runtime misbehavior is likely to occur if an {@code
* InterruptedException} is {@linkplain Throwable#addSuppressed
* suppressed}.
* <p>
* More generally, if it would cause problems for an
* exception to be suppressed, the {@code AutoCloseable.close}
* method should not throw it.
*
* <p>Note that unlike the {@link Closeable#close close}
* method of {@link Closeable}, this {@code close} method
* is <em>not</em> required to be idempotent. In other words,
* calling this {@code close} method more than once may have some
* visible side effect, unlike {@code Closeable.close} which is
* required to have no effect if called more than once.
* <p>
* However, implementers of this interface are strongly encouraged
* to make their {@code close} methods idempotent.
*/
@Override
public void close() throws Exception {
this.executorService.shutdownNow();
}
}

0 comments on commit 1d6a9ac

Please sign in to comment.