public boolean isClosed() { synchronized (getSynchronizationLock()) { return closed; } }
/** * Adds a mapping to the registry map, respecting locking. */ protected final void addCloseableInternal(Closeable closeable, T metaData) { synchronized (getSynchronizationLock()) { closeableToRef.put(closeable, metaData); } }
/** * Removes a mapping from the registry map, respecting locking. */ protected final void removeCloseableInternal(Closeable closeable) { synchronized (getSynchronizationLock()) { closeableToRef.remove(closeable); } }
@VisibleForTesting public final int getNumberOfRegisteredCloseables() { synchronized (getSynchronizationLock()) { return closeableToRef.size(); } }
@VisibleForTesting public final boolean isCloseableRegistered(Closeable c) { synchronized (getSynchronizationLock()) { return closeableToRef.containsKey(c); } } }
@Override public void close() throws IOException { Collection<Closeable> toCloseCopy; synchronized (getSynchronizationLock()) { if (closed) { return; } closed = true; toCloseCopy = new ArrayList<>(closeableToRef.keySet()); closeableToRef.clear(); } IOUtils.closeAllQuietly(toCloseCopy); }
/** * Removes a {@link Closeable} from the registry. * * @param closeable instance to remove from the registry. * @return true if the closeable was previously registered and became unregistered through this call. */ public final boolean unregisterCloseable(C closeable) { if (null == closeable) { return false; } synchronized (getSynchronizationLock()) { return doUnRegister(closeable, closeableToRef); } }
/** * Registers a {@link Closeable} with the registry. In case the registry is already closed, this method throws an * {@link IllegalStateException} and closes the passed {@link Closeable}. * * @param closeable Closeable tor register * @throws IOException exception when the registry was closed before */ public final void registerCloseable(C closeable) throws IOException { if (null == closeable) { return; } synchronized (getSynchronizationLock()) { if (!closed) { doRegister(closeable, closeableToRef); return; } } IOUtils.closeQuietly(closeable); throw new IOException("Cannot register Closeable, registry is already closed. Closing argument."); }
public boolean isClosed() { synchronized (getSynchronizationLock()) { return closed; } }
public boolean isClosed() { synchronized (getSynchronizationLock()) { return closed; } }
/** * Removes a mapping from the registry map, respecting locking. */ protected final void removeCloseableInternal(Closeable closeable) { synchronized (getSynchronizationLock()) { closeableToRef.remove(closeable); } }
/** * Adds a mapping to the registry map, respecting locking. */ protected final void addCloseableInternal(Closeable closeable, T metaData) { synchronized (getSynchronizationLock()) { closeableToRef.put(closeable, metaData); } }
/** * Removes a mapping from the registry map, respecting locking. */ protected final void removeCloseableInternal(Closeable closeable) { synchronized (getSynchronizationLock()) { closeableToRef.remove(closeable); } }
/** * Adds a mapping to the registry map, respecting locking. */ protected final void addCloseableInternal(Closeable closeable, T metaData) { synchronized (getSynchronizationLock()) { closeableToRef.put(closeable, metaData); } }
@VisibleForTesting public final int getNumberOfRegisteredCloseables() { synchronized (getSynchronizationLock()) { return closeableToRef.size(); } }
@VisibleForTesting public final int getNumberOfRegisteredCloseables() { synchronized (getSynchronizationLock()) { return closeableToRef.size(); } }
@VisibleForTesting public final boolean isCloseableRegistered(Closeable c) { synchronized (getSynchronizationLock()) { return closeableToRef.containsKey(c); } } }
@VisibleForTesting public final boolean isCloseableRegistered(Closeable c) { synchronized (getSynchronizationLock()) { return closeableToRef.containsKey(c); } } }
@Override public void close() throws IOException { Collection<Closeable> toCloseCopy; synchronized (getSynchronizationLock()) { if (closed) { return; } closed = true; toCloseCopy = new ArrayList<>(closeableToRef.keySet()); closeableToRef.clear(); } IOUtils.closeAllQuietly(toCloseCopy); }
@Override public void close() throws IOException { Collection<Closeable> toCloseCopy; synchronized (getSynchronizationLock()) { if (closed) { return; } closed = true; toCloseCopy = new ArrayList<>(closeableToRef.keySet()); closeableToRef.clear(); } IOUtils.closeAllQuietly(toCloseCopy); }