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;
}
}
Aggregations