Search in sources :

Example 1 with SettableFuture

use of com.google_voltpatches.common.util.concurrent.SettableFuture in project voltdb by VoltDB.

the class VoltTrace method write.

/**
     * Write the events in the queue to file.
     * @param logDir The directory to write the file to.
     * @return The file path if successfully written, or null if the there is
     * already a write in progress.
     */
private String write(String logDir) throws IOException, ExecutionException, InterruptedException {
    final File file = new File(logDir, "trace_" + System.currentTimeMillis() + ".json.gz");
    if (file.exists()) {
        throw new IOException("Trace file " + file.getAbsolutePath() + " already exists");
    }
    if (!file.getParentFile().canWrite() || !file.getParentFile().canExecute()) {
        throw new IOException("Trace file " + file.getAbsolutePath() + " is not writable");
    }
    SettableFuture<Future> f = SettableFuture.create();
    m_work.offer(() -> f.set(dumpEvents(file)));
    final Future writeFuture = f.get();
    if (writeFuture != null) {
        // Wait for the write to finish without blocking new events
        writeFuture.get();
        return file.getAbsolutePath();
    } else {
        // A write is already in progress, ignore this request
        return null;
    }
}
Also used : SettableFuture(com.google_voltpatches.common.util.concurrent.SettableFuture) ListenableFuture(com.google_voltpatches.common.util.concurrent.ListenableFuture) Future(java.util.concurrent.Future) IOException(java.io.IOException) File(java.io.File)

Aggregations

ListenableFuture (com.google_voltpatches.common.util.concurrent.ListenableFuture)1 SettableFuture (com.google_voltpatches.common.util.concurrent.SettableFuture)1 File (java.io.File)1 IOException (java.io.IOException)1 Future (java.util.concurrent.Future)1