/** * Closes all given <tt>Closeable</tt>s, suppressing all thrown non {@link VirtualMachineError} exceptions. * Even if a {@link VirtualMachineError} is thrown all given closeable are closed. * @see #closeWhileHandlingException(Closeable...) */ public static void closeWhileHandlingException(Iterable<? extends Closeable> objects) { VirtualMachineError firstError = null; Throwable firstThrowable = null; for (Closeable object : objects) { try { if (object != null) { object.close(); } } catch (VirtualMachineError e) { firstError = useOrSuppress(firstError, e); } catch (Throwable t) { firstThrowable = useOrSuppress(firstThrowable, t); } } if (firstError != null) { // we ensure that we bubble up any errors. We can't recover from these but need to make sure they are // bubbled up. if a non-VMError is thrown we also add the suppressed exceptions to it. if (firstThrowable != null) { firstError.addSuppressed(firstThrowable); } throw firstError; } }
/** * Closes all given <tt>Closeable</tt>s. * @see #close(Closeable...) */ public static void close(Iterable<? extends Closeable> objects) throws IOException { Throwable th = null; for (Closeable object : objects) { try { if (object != null) { object.close(); } } catch (Throwable t) { th = useOrSuppress(th, t); } } if (th != null) { throw rethrowAlways(th); } }
/** * Deletes all given <tt>Path</tt>s, if they exist. Some of the * <tt>File</tt>s may be null; they are * ignored. After everything is deleted, the method either * throws the first exception it hit while deleting, or * completes normally if there were no exceptions. * * @param files files to delete */ public static void deleteFilesIfExist(Collection<? extends Path> files) throws IOException { Throwable th = null; for (Path file : files) { try { if (file != null) { Files.deleteIfExists(file); } } catch (Throwable t) { th = useOrSuppress(th, t); } } if (th != null) { throw rethrowAlways(th); } }
/** Remove all our references to readers, and commits * any pending changes. */ synchronized void dropAll() throws IOException { Throwable priorE = null; final Iterator<Map.Entry<SegmentCommitInfo,ReadersAndUpdates>> it = readerMap.entrySet().iterator(); while(it.hasNext()) { final ReadersAndUpdates rld = it.next().getValue(); // Important to remove as-we-go, not with .clear() // in the end, in case we hit an exception; // otherwise we could over-decref if close() is // called again: it.remove(); // NOTE: it is allowed that these decRefs do not // actually close the SRs; this happens when a // near real-time reader is kept open after the // IndexWriter instance is closed: try { rld.dropReaders(); } catch (Throwable t) { priorE = IOUtils.useOrSuppress(priorE, t); } } assert readerMap.size() == 0; if (priorE != null) { throw IOUtils.rethrowAlways(priorE); } }
/** Decrefs all provided files, even on exception; throws first exception hit, if any. */ void decRef(Collection<String> files) throws IOException { assert locked(); Set<String> toDelete = new HashSet<>(); Throwable firstThrowable = null; for(final String file : files) { try { if (decRef(file)) { toDelete.add(file); } } catch (Throwable t) { firstThrowable = IOUtils.useOrSuppress(firstThrowable, t); } } try { deleteFiles(toDelete); } catch (Throwable t) { firstThrowable = IOUtils.useOrSuppress(firstThrowable, t); } if (firstThrowable != null) { throw IOUtils.rethrowAlways(firstThrowable); } }
/** * Deletes all given file names. Some of the * file names may be null; they are * ignored. After everything is deleted, the method either * throws the first exception it hit while deleting, or * completes normally if there were no exceptions. * * @param dir Directory to delete files from * @param names file names to delete */ public static void deleteFiles(Directory dir, Collection<String> names) throws IOException { Throwable th = null; for (String name : names) { if (name != null) { try { dir.deleteFile(name); } catch (Throwable t) { th = useOrSuppress(th, t); } } } if (th != null) { throw rethrowAlways(th); } }
decRef(commit.files); } catch (Throwable t) { firstThrowable = IOUtils.useOrSuppress(firstThrowable, t);
/** * Closes all given <tt>Closeable</tt>s, suppressing all thrown non {@link VirtualMachineError} exceptions. * Even if a {@link VirtualMachineError} is thrown all given closeable are closed. * @see #closeWhileHandlingException(Closeable...) */ public static void closeWhileHandlingException(Iterable<? extends Closeable> objects) { VirtualMachineError firstError = null; Throwable firstThrowable = null; for (Closeable object : objects) { try { if (object != null) { object.close(); } } catch (VirtualMachineError e) { firstError = useOrSuppress(firstError, e); } catch (Throwable t) { firstThrowable = useOrSuppress(firstThrowable, t); } } if (firstError != null) { // we ensure that we bubble up any errors. We can't recover from these but need to make sure they are // bubbled up. if a non-VMError is thrown we also add the suppressed exceptions to it. if (firstThrowable != null) { firstError.addSuppressed(firstThrowable); } throw firstError; } }
/** * Closes all given <tt>Closeable</tt>s. * @see #close(Closeable...) */ public static void close(Iterable<? extends Closeable> objects) throws IOException { Throwable th = null; for (Closeable object : objects) { try { if (object != null) { object.close(); } } catch (Throwable t) { th = useOrSuppress(th, t); } } if (th != null) { throw rethrowAlways(th); } }
/** * Deletes all given <tt>Path</tt>s, if they exist. Some of the * <tt>File</tt>s may be null; they are * ignored. After everything is deleted, the method either * throws the first exception it hit while deleting, or * completes normally if there were no exceptions. * * @param files files to delete */ public static void deleteFilesIfExist(Collection<? extends Path> files) throws IOException { Throwable th = null; for (Path file : files) { try { if (file != null) { Files.deleteIfExists(file); } } catch (Throwable t) { th = useOrSuppress(th, t); } } if (th != null) { throw rethrowAlways(th); } }
/** Remove all our references to readers, and commits * any pending changes. */ synchronized void dropAll() throws IOException { Throwable priorE = null; final Iterator<Map.Entry<SegmentCommitInfo,ReadersAndUpdates>> it = readerMap.entrySet().iterator(); while(it.hasNext()) { final ReadersAndUpdates rld = it.next().getValue(); // Important to remove as-we-go, not with .clear() // in the end, in case we hit an exception; // otherwise we could over-decref if close() is // called again: it.remove(); // NOTE: it is allowed that these decRefs do not // actually close the SRs; this happens when a // near real-time reader is kept open after the // IndexWriter instance is closed: try { rld.dropReaders(); } catch (Throwable t) { priorE = IOUtils.useOrSuppress(priorE, t); } } assert readerMap.size() == 0; if (priorE != null) { throw IOUtils.rethrowAlways(priorE); } }
/** Decrefs all provided files, even on exception; throws first exception hit, if any. */ void decRef(Collection<String> files) throws IOException { assert locked(); Set<String> toDelete = new HashSet<>(); Throwable firstThrowable = null; for(final String file : files) { try { if (decRef(file)) { toDelete.add(file); } } catch (Throwable t) { firstThrowable = IOUtils.useOrSuppress(firstThrowable, t); } } try { deleteFiles(toDelete); } catch (Throwable t) { firstThrowable = IOUtils.useOrSuppress(firstThrowable, t); } if (firstThrowable != null) { throw IOUtils.rethrowAlways(firstThrowable); } }
/** * Deletes all given file names. Some of the * file names may be null; they are * ignored. After everything is deleted, the method either * throws the first exception it hit while deleting, or * completes normally if there were no exceptions. * * @param dir Directory to delete files from * @param names file names to delete */ public static void deleteFiles(Directory dir, Collection<String> names) throws IOException { Throwable th = null; for (String name : names) { if (name != null) { try { dir.deleteFile(name); } catch (Throwable t) { th = useOrSuppress(th, t); } } } if (th != null) { throw rethrowAlways(th); } }
decRef(commit.files); } catch (Throwable t) { firstThrowable = IOUtils.useOrSuppress(firstThrowable, t);