Package org.apache.flink.util
Class AbstractAutoCloseableRegistry<R extends AutoCloseable,C extends R,T,E extends Exception>
- java.lang.Object
-
- org.apache.flink.util.AbstractAutoCloseableRegistry<R,C,T,E>
-
- Type Parameters:
C- Type of the closeable this registersT- Type for potential meta data associated with the registering closeables
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
AutoCloseableRegistry,CloseableRegistry,SafetyNetCloseableRegistry
@Internal public abstract class AbstractAutoCloseableRegistry<R extends AutoCloseable,C extends R,T,E extends Exception> extends Object implements AutoCloseable
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<R,T>closeableToRefMap from tracked Closeables to some associated meta data.
-
Constructor Summary
Constructors Constructor Description AbstractAutoCloseableRegistry(Map<R,T> closeableToRef)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()protected abstract voiddoClose(List<R> toClose)protected abstract voiddoRegister(C closeable, Map<R,T> closeableMap)Does the actual registration of the closeable with the registry map.protected abstract booleandoUnRegister(C closeable, Map<R,T> closeableMap)Does the actual un-registration of the closeable from the registry map.intgetNumberOfRegisteredCloseables()protected ObjectgetSynchronizationLock()Returns the lock on which manipulations to members closeableToRef and closeable must be synchronized.booleanisCloseableRegistered(R c)booleanisClosed()voidregisterCloseable(C closeable)Registers aAutoCloseablewith the registry.protected booleanremoveCloseableInternal(R closeable)Removes a mapping from the registry map, respecting locking.booleanunregisterCloseable(C closeable)Removes aCloseablefrom the registry.
-
-
-
Field Detail
-
closeableToRef
protected final Map<R extends AutoCloseable,T> closeableToRef
Map from tracked Closeables to some associated meta data.
-
-
Method Detail
-
registerCloseable
public final void registerCloseable(C closeable) throws IOException
Registers aAutoCloseablewith the registry. In case the registry is already closed, this method throws anIllegalStateExceptionand closes the passedAutoCloseable.- Parameters:
closeable- Closeable to register.- Throws:
IOException- exception when the registry was closed before.
-
unregisterCloseable
public final boolean unregisterCloseable(C closeable)
Removes aCloseablefrom the registry.- Parameters:
closeable- instance to remove from the registry.- Returns:
- true if the closeable was previously registered and became unregistered through this call.
-
close
public void close() throws E extends Exception- Specified by:
closein interfaceAutoCloseable- Throws:
E extends Exception
-
isClosed
public boolean isClosed()
-
doRegister
protected abstract void doRegister(@Nonnull C closeable, @Nonnull Map<R,T> closeableMap)Does the actual registration of the closeable with the registry map. This should not do any long running or potentially blocking operations as it is executed under the registry's lock.
-
doUnRegister
protected abstract boolean doUnRegister(@Nonnull C closeable, @Nonnull Map<R,T> closeableMap)Does the actual un-registration of the closeable from the registry map. This should not do any long running or potentially blocking operations as it is executed under the registry's lock.
-
getSynchronizationLock
protected final Object getSynchronizationLock()
Returns the lock on which manipulations to members closeableToRef and closeable must be synchronized.
-
removeCloseableInternal
protected final boolean removeCloseableInternal(R closeable)
Removes a mapping from the registry map, respecting locking.
-
getNumberOfRegisteredCloseables
@VisibleForTesting public final int getNumberOfRegisteredCloseables()
-
isCloseableRegistered
@VisibleForTesting public final boolean isCloseableRegistered(R c)
-
-