Class AbstractConcurrentInitializer<T,​E extends java.lang.Exception>

    • Field Detail

      • closer

        private final FailableConsumer<? super T,​? extends java.lang.Exception> closer
        Closer consumer called by close().
      • initializer

        private final FailableSupplier<? extends T,​? extends java.lang.Exception> initializer
        Initializer supplier called by initialize().
    • Constructor Detail

      • AbstractConcurrentInitializer

        public AbstractConcurrentInitializer()
        Constructs a new instance.
      • AbstractConcurrentInitializer

        AbstractConcurrentInitializer​(FailableSupplier<? extends T,​? extends java.lang.Exception> initializer,
                                      FailableConsumer<? super T,​? extends java.lang.Exception> closer)
        Constructs a new instance.
        Parameters:
        initializer - the initializer supplier called by initialize().
        closer - the closer consumer called by close().
    • Method Detail

      • getTypedException

        protected abstract E getTypedException​(java.lang.Exception e)
        Gets an Exception with a type of E as defined by a concrete subclass of this class.
        Parameters:
        e - The actual exception that was thrown
        Returns:
        a new exception with the actual type of E, that wraps e.
      • initialize

        protected T initialize()
                        throws E extends java.lang.Exception
        Creates and initializes the object managed by this ConcurrentInitializer. This method is called by FailableSupplier.get() when the object is accessed for the first time. An implementation can focus on the creation of the object. No synchronization is needed, as this is already handled by get().

        Subclasses and clients that do not provide an initializer are expected to implement this method.

        Returns:
        the managed data object
        Throws:
        E - if an error occurs during object creation
        E extends java.lang.Exception
      • isInitialized

        protected abstract boolean isInitialized()
        Returns true if initialization has been completed. If initialization threw an exception this will return false, but it will return true if a subsequent call to initialize completes successfully. If the implementation of ConcurrentInitializer can initialize multiple objects, this will only return true if all objects have been initialized.
        Returns:
        true if all initialization is complete, otherwise false