use of com.palantir.util.SafeShutdownRunner in project atlasdb by palantir.
the class SnapshotTransactionManager method close.
/**
* Frees resources used by this SnapshotTransactionManager, and invokes any callbacks registered to run on close.
* This includes the cleaner, the key value service (and attendant thread pools), and possibly the lock service.
*
* Concurrency: If this method races with registerClosingCallback(closingCallback), then closingCallback
* may be called (but is not necessarily called). Callbacks registered before the invocation of close() are
* guaranteed to be executed (because we use a synchronized list) as long as no exceptions arise. If an exception
* arises, then no guarantees are made with regard to subsequent callbacks being executed.
*/
@Override
public void close() {
log.info("Calling close on snapshot transaction manager");
if (!isClosed.compareAndSet(false, true)) {
log.info("Snapshot transaction manager has already been closed, performing no action");
return;
}
try (SafeShutdownRunner shutdownRunner = SafeShutdownRunner.createWithCachedThreadpool(Duration.ofSeconds(20))) {
shutdownRunner.shutdownSafely(super::close);
shutdownRunner.shutdownSafely(cleaner::close);
shutdownRunner.shutdownSafely(keyValueService::close);
shutdownRunner.shutdownSafely(() -> shutdownExecutor(deleteExecutor));
shutdownRunner.shutdownSafely(() -> shutdownExecutor(getRangesExecutor));
shutdownRunner.shutdownSafely(this::closeLockServiceIfPossible);
for (Runnable callback : Lists.reverse(closingCallbacks)) {
shutdownRunner.shutdownSafely(callback);
}
shutdownRunner.shutdownSafely(metricsManager::deregisterMetrics);
log.info("Close callbacks complete in snapshot transaction manager");
}
log.info("Closed snapshot transaction manager without any errors");
}
Aggregations