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