C
- Type of the closeable this registersT
- Type for potential meta data associated with the registering closeables@Internal public abstract class AbstractCloseableRegistry<C extends Closeable,T> extends Object implements Closeable
Constructor and Description |
---|
AbstractCloseableRegistry(Map<Closeable,T> closeableToRef) |
Modifier and Type | Method and Description |
---|---|
protected void |
addCloseableInternal(Closeable closeable,
T metaData)
Adds a mapping to the registry map, respecting locking.
|
void |
close() |
protected abstract void |
doRegister(C closeable,
Map<Closeable,T> closeableMap)
Does the actual registration of the closeable with the registry map.
|
protected abstract boolean |
doUnRegister(C closeable,
Map<Closeable,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(Closeable c) |
boolean |
isClosed() |
void |
registerCloseable(C closeable)
Registers a
Closeable with the registry. |
protected void |
removeCloseableInternal(Closeable closeable)
Removes a mapping from the registry map, respecting locking.
|
boolean |
unregisterCloseable(C closeable)
Removes a
Closeable from the registry. |
public final void registerCloseable(C closeable) throws IOException
Closeable
with the registry. In case the registry is already closed, this method throws an
IllegalStateException
and closes the passed Closeable
.closeable
- Closeable tor registerIOException
- exception when the registry was closed beforepublic final boolean unregisterCloseable(C closeable)
Closeable
from the registry.closeable
- instance to remove from the registry.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public boolean isClosed()
protected abstract void doRegister(@Nonnull C closeable, @Nonnull Map<Closeable,T> closeableMap)
protected abstract boolean doUnRegister(@Nonnull C closeable, @Nonnull Map<Closeable,T> closeableMap)
protected final Object getSynchronizationLock()
protected final void addCloseableInternal(Closeable closeable, T metaData)
protected final void removeCloseableInternal(Closeable closeable)
@VisibleForTesting public final int getNumberOfRegisteredCloseables()
@VisibleForTesting public final boolean isCloseableRegistered(Closeable c)
Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.