/** * Delete all registered temp files. */ public void deleteAll() { for (String tempFile : new ArrayList<>(refMap.values())) { deleteFile(null, tempFile); } deleteUnused(); }
public static TempFileDeleter getInstance() { return new TempFileDeleter(); }
/** * Automatically delete the file once it is no longer in use. */ public void autoDelete() { if (autoDeleteReference == null) { autoDeleteReference = tempFileDeleter.addFile(name, this); } }
/** * Add a file to the list of temp files to delete. The file is deleted once * the file object is garbage collected. * * @param fileName the file name * @param file the object to monitor * @return the reference that can be used to stop deleting the file */ public synchronized Reference<?> addFile(String fileName, Object file) { IOUtils.trace("TempFileDeleter.addFile", fileName, file); PhantomReference<?> ref = new PhantomReference<Object>(file, queue); refMap.put(ref, fileName); deleteUnused(); return ref; }
/** * Delete all unused files now. */ public void deleteUnused() { while (queue != null) { Reference<? extends Object> ref = queue.poll(); if (ref == null) { break; } deleteFile(ref, null); } }
/** * No longer automatically delete the file once it is no longer in use. */ public void stopAutoDelete() { tempFileDeleter.stopAutoDelete(autoDeleteReference, name); autoDeleteReference = null; }
@Override public TempFileDeleter getTempFileDeleter() { return TempFileDeleter.getInstance(); }
trace.error(e, "close"); tempFileDeleter.deleteAll(); try { closeOpenFilesAndUnlock(true);
/** * Flush all changes and open a new transaction log. */ public void checkpoint() { if (persistent) { transactionEngine.checkpoint(); } getTempFileDeleter().deleteUnused(); }
/** * Close the file (ignoring exceptions) and delete the file. */ public void closeAndDeleteSilently() { if (file != null) { closeSilently(); tempFileDeleter.deleteFile(autoDeleteReference, name); name = null; } }
/** * This method is called if a file should no longer be deleted if the object * is garbage collected. * * @param ref the reference as returned by addFile * @param fileName the file name */ public void stopAutoDelete(Reference<?> ref, String fileName) { IOUtils.trace("TempFileDeleter.stopAutoDelete", fileName, ref); if (ref != null) { String f2 = refMap.remove(ref); if (SysProperties.CHECK) { if (f2 == null || !f2.equals(fileName)) { DbException.throwInternalError("f2:" + f2 + " " + (f2 == null ? "" : f2) + " f:" + fileName); } } } deleteUnused(); }