Class ConcurrentLazyFactory<T>
java.lang.Object
io.github.cowwoc.pouch10.core.ConcurrentLazyFactory<T>
- Type Parameters:
T- the type of the value
- All Implemented Interfaces:
Factory<T>,Reference<T>,Closeable,AutoCloseable
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclose()Disposes the Factory and the value.static <T extends AutoCloseable>
ConcurrentLazyFactory<T> Creates a newConcurrentLazyFactorythat disposes its value by invokingclose().static <T> ConcurrentLazyFactory<T> Creates a newConcurrentLazyFactory.protected abstract TCreates the value.protected abstract voiddisposeValue(T value) Disposes the value.final TgetValue()Returns the value.booleanIndicates if the value was initialized.toString()
-
Constructor Details
-
ConcurrentLazyFactory
protected ConcurrentLazyFactory()Creates a new instance.
-
-
Method Details
-
create
Creates a newConcurrentLazyFactory.- Type Parameters:
T- the type of value returned by the factory- Parameters:
supplier- supplies the factory valuedisposer- implementsdisposeValue(T)- Returns:
- a new
ConcurrentLazyFactory
-
create
Creates a newConcurrentLazyFactorythat disposes its value by invokingclose(). Ifclose()throws a checked exception, it is wrapped in aRuntimeExceptionor an exception that extends it.- Type Parameters:
T- the type of value returned by the factory- Parameters:
supplier- supplies the factory value- Returns:
- a new
ConcurrentLazyFactory
-
createValue
Creates the value. This method is invoked the first timegetValue()is invoked.- Returns:
- the value
-
disposeValue
-
getValue
Returns the value. Subsequent invocations of this method return the same value.- Specified by:
getValuein interfaceReference<T>- Returns:
- an object of type
<T> - Throws:
IllegalStateException- if the factory is closed
-
isInitialized
public boolean isInitialized()Description copied from interface:ReferenceIndicates if the value was initialized.A value may get initialized immediately after this method returns
falsebut once it returnstrueit will continue to do so indefinitely.- Specified by:
isInitializedin interfaceReference<T>- Returns:
trueif the value was initialized
-
close
public final void close()Description copied from interface:FactoryDisposes the Factory and the value. Subsequent invocations of this method have no effect. Invoking any other method after this one results inIllegalStateExceptionbeing thrown. -
toString
-