docs: 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) {
              writeFuture.get(); // Wait for the write to finish without blocking new events
              return file.getAbsolutePath();
          } else {
              // A write is already in progress, ignore this request
              return null;
          }
      }