AbstractConcurrentInitializer (Apache Commons Lang 3.17.0 API)
Description: declaration: package: org.apache.commons.lang3.concurrent, class: AbstractConcurrentInitializer

Package org.apache.commons.lang3.concurrent

# Class AbstractConcurrentInitializer<T,E extends Exception>

java.lang.Object
org.apache.commons.lang3.concurrent.AbstractConcurrentInitializer<T,E>

Type Parameters:
  `T` - the type of the object managed by this initializer class.
  `E` - The exception type thrown by `initialize()`.

All Implemented Interfaces:
  `ConcurrentInitializer<T>`, `FailableSupplier<T,ConcurrentException>`

Direct Known Subclasses:
  `AtomicInitializer`, `AtomicSafeInitializer`, `BackgroundInitializer`, `LazyInitializer`

public abstract class AbstractConcurrentInitializer<T,E extends Exception> extends Object implements ConcurrentInitializer<T>
Abstracts and defines operations for `ConcurrentInitializer` implementations.

Since:
  3.14.0

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `AbstractConcurrentInitializer.AbstractBuilder<I extends AbstractConcurrentInitializer<T,E>,T,B extends AbstractConcurrentInitializer.AbstractBuilder<I,T,B,E>,E extends Exception>`
  Builds a new instance for subclasses.

- ## Field Summary

  ### Fields inherited from interface org.apache.commons.lang3.function.FailableSupplier

  `NUL`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AbstractConcurrentInitializer()`
  Constructs a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  Calls the closer with the manager object.
  `protected abstract E`
  `getTypedException(Exception e)`
  Gets an Exception with a type of E as defined by a concrete subclass of this class.
  `protected T`
  `initialize()`
  Creates and initializes the object managed by this `ConcurrentInitializer`.
  `protected abstract boolean`
  `isInitialized()`
  Returns true if initialization has been completed.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.apache.commons.lang3.function.FailableSupplier

  `get`

- ## Constructor Details

  - ### AbstractConcurrentInitializer

    public AbstractConcurrentInitializer()
    Constructs a new instance.

- ## Method Details

  - ### close

    public void close() throws ConcurrentException
    Calls the closer with the manager object.
    Throws:
      `ConcurrentException` - Thrown by the closer.
    Since:
      3.14.0

  - ### getTypedException

    protected abstract E getTypedException(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
    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

  - ### 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