private <T> Stream<T> attach(final DataTransaction transaction, final Stream<T> stream) { return stream.onClose(new Closeable() { @Override public void close() throws IOException { transaction.end(true); } }); }
private <T> Stream<T> attach(final TripleTransaction transaction, final Stream<T> stream) { return stream.onClose(new Closeable() { @Override public void close() throws IOException { transaction.end(true); } }); }
@Nullable private <T> Stream<T> logClose(@Nullable final Stream<T> stream, final String name, final long ts) { final AtomicLong count = new AtomicLong(0); final AtomicBoolean eof = new AtomicBoolean(false); return stream.track(count, eof).onClose(new Runnable() { @Override public void run() { LOGGER.debug("{} - {} closed after {} ms, {} records, eof={}", LoggingDataTransaction.this, name, System.currentTimeMillis() - ts, count, eof); } }); }
@Nullable private <T> Stream<T> logClose(@Nullable final Stream<T> stream, final String name, final long ts) { final AtomicLong count = new AtomicLong(0); final AtomicBoolean eof = new AtomicBoolean(false); return stream.track(count, eof).onClose(new Runnable() { @Override public void run() { LOGGER.debug("{} - {} closed after {} ms, {} files, eof={}", LoggingFileStore.this, name, System.currentTimeMillis() - ts, count, eof); } }); }
@Override public Stream<String> list() throws IOException { checkState(INITIALIZED); this.synchronizer.beginTransaction(true); try { checkState(INITIALIZED); final Stream<String> stream = super.list(); synchronized (this.pendingListStreams) { this.pendingListStreams.add(stream); } stream.onClose(new Runnable() { @Override public void run() { SynchronizedFileStore.this.synchronizer.endTransaction(true); synchronized (SynchronizedFileStore.this.pendingListStreams) { SynchronizedFileStore.this.pendingListStreams.remove(this); } } }); return stream; } catch (final Throwable ex) { this.synchronizer.endTransaction(true); Throwables.propagateIfPossible(ex, IOException.class); throw Throwables.propagate(ex); } }
}).onClose(buffer);