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>
closeableToRef
Map 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 void
close()
protected abstract void
doClose(List<R> toClose)
protected abstract void
doRegister(C closeable, Map<R,T> closeableMap)
Does the actual registration of the closeable with the registry map.protected abstract boolean
doUnRegister(C closeable, Map<R,T> closeableMap)
Does the actual un-registration of the closeable from the registry map.int
getNumberOfRegisteredCloseables()
protected Object
getSynchronizationLock()
Returns the lock on which manipulations to members closeableToRef and closeable must be synchronized.boolean
isCloseableRegistered(R c)
boolean
isClosed()
void
registerCloseable(C closeable)
Registers aAutoCloseable
with the registry.protected boolean
removeCloseableInternal(R closeable)
Removes a mapping from the registry map, respecting locking.boolean
unregisterCloseable(C closeable)
Removes aCloseable
from 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 aAutoCloseable
with the registry. In case the registry is already closed, this method throws anIllegalStateException
and 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 aCloseable
from 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:
close
in 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 is 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 is 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)
-
-