Package com.palantir.atlasdb.cassandra
Class ReloadingCloseableContainerImpl<T extends AutoCloseable>
- java.lang.Object
-
- com.palantir.atlasdb.cassandra.ReloadingCloseableContainerImpl<T>
-
- All Implemented Interfaces:
ReloadingCloseableContainer<T>
,AutoCloseable
public final class ReloadingCloseableContainerImpl<T extends AutoCloseable> extends Object implements ReloadingCloseableContainer<T>
This container creates new resources when the underlying refreshable changes. After a refresh, previous resources are closed to avoid resource leaks. There is no guarantee that a resource provided viaget()
will not be closed whilst in use. Consumers should be resilient to any uses after the resource has been closed, and where necessary, retry. Afterclose()
has returned, no further resources will be created, and all managed resources will be closed.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
A lock is taken out to ensure no new resources are created after retrieving the current stored resource to close.T
get()
Gets the latest resource that reflects any changes in the refreshable, providedclose()
has not been called.boolean
isClosed()
static <T extends AutoCloseable,K>
ReloadingCloseableContainerImpl<T>of(com.palantir.refreshable.Refreshable<K> refreshableParameter, Function<K,T> factory)
-
-
-
Method Detail
-
of
public static <T extends AutoCloseable,K> ReloadingCloseableContainerImpl<T> of(com.palantir.refreshable.Refreshable<K> refreshableParameter, Function<K,T> factory)
-
close
public void close()
A lock is taken out to ensure no new resources are created after retrieving the current stored resource to close. By doing so, we avoid closing a cluster and subsequently creating a new one that is never closed.- Specified by:
close
in interfaceAutoCloseable
-
get
public T get()
Gets the latest resource that reflects any changes in the refreshable, providedclose()
has not been called. The resource returned will be closed afterclose()
is called, or the refreshable is refreshed, even if the resource is in active use.- Specified by:
get
in interfaceReloadingCloseableContainer<T extends AutoCloseable>
- Throws:
com.palantir.logsafe.exceptions.SafeIllegalStateException
- if the container was closed prior to getting a resource.
-
isClosed
public boolean isClosed()
- Specified by:
isClosed
in interfaceReloadingCloseableContainer<T extends AutoCloseable>
-
-