Class ReloadingCloseableContainerImpl<T extends AutoCloseable>

  • 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 via get() will not be closed whilst in use. Consumers should be resilient to any uses after the resource has been closed, and where necessary, retry. After close() has returned, no further resources will be created, and all managed resources will be closed.
    • Method Detail

      • 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 interface AutoCloseable
      • get

        public T get()
        Gets the latest resource that reflects any changes in the refreshable, provided close() has not been called. The resource returned will be closed after close() is called, or the refreshable is refreshed, even if the resource is in active use.
        Specified by:
        get in interface ReloadingCloseableContainer<T extends AutoCloseable>
        Throws:
        com.palantir.logsafe.exceptions.SafeIllegalStateException - if the container was closed prior to getting a resource.