Interface BeanHolder<T>

  • Type Parameters:
    T - The type of the bean instance.
    All Superinterfaces:

    public interface BeanHolder<T>
    extends AutoCloseable
    An object holding a bean instance, and allowing to release it.
    • Method Detail

      • get

        T get()
        The bean instance. Guaranteed to always return the exact same object, i.e. beanHolder.get() == beanHolder.get() is always true.
      • close

        void close()
        Release any resource currently held by the BeanHolder.

        After this method has been called, the result of calling get() on the same instance is undefined.

        Warning: this method only releases resources that were allocated by the creator of the bean instance, and of which the bean instance itself may not be aware. If the bean instance itself (the one returned by get()) exposes any close() or other release method, they should be called before the BeanHolder is released.

        Specified by:
        close in interface AutoCloseable
        RuntimeException - If an error occurs while releasing resources.
      • withDependencyAutoClosing

        default BeanHolder<T> withDependencyAutoClosing​(BeanHolder<?>... dependencies)
        dependencies - Dependencies that should be closed eventually.
        A bean holder that wraps the current bean holder, and ensures the dependencies are also closed when its close() method is called.
      • of

        static <T> BeanHolder<T> of​(T instance)
        Type Parameters:
        T - The type of the bean instance.
        instance - The bean instance.
        A BeanHolder whose get() method returns the given instance, and whose close() method does not do anything.
      • of

        static <T> BeanHolder<List<T>> of​(List<? extends BeanHolder<? extends T>> beanHolders)
        Type Parameters:
        T - The type of the bean instances.
        beanHolders - The bean holders.
        A BeanHolder whose get() method returns a list containing the instance of each given bean holder, in order, and whose close() method closes every given bean holder.