/** * Returns a {@link Closeable} which action is to call {@link #decrement()} only once. If close() is called on the * returned Closeable object for the second time, it won't call {@link #decrement()} again. */ public Closeable decrementOnceCloseable() { AtomicBoolean decremented = new AtomicBoolean(false); return () -> { if (decremented.compareAndSet(false, true)) { decrement(); } else { log.warn("close() is called more than once on ReferenceCountingSegment.decrementOnceCloseable()"); } }; }
@Override public Sequence<T> run(final QueryPlus<T> queryPlus, Map<String, Object> responseContext) { if (adapter.increment()) { try { final Sequence<T> baseSequence = factory.createRunner(adapter).run(queryPlus, responseContext); return Sequences.withBaggage(baseSequence, adapter.decrementOnceCloseable()); } catch (Throwable t) { try { adapter.decrement(); } catch (Exception e) { t.addSuppressed(e); } throw t; } } else { // Segment was closed before we had a chance to increment the reference count return new ReportTimelineMissingSegmentQueryRunner<T>(descriptor).run(queryPlus, responseContext); } } }
@Override public Sequence<T> run(final QueryPlus<T> queryPlus, Map<String, Object> responseContext) { if (adapter.increment()) { try { final Sequence<T> baseSequence = factory.createRunner(adapter).run(queryPlus, responseContext); return Sequences.withBaggage(baseSequence, adapter.decrementOnceCloseable()); } catch (Throwable t) { try { adapter.decrement(); } catch (Exception e) { t.addSuppressed(e); } throw t; } } else { // Segment was closed before we had a chance to increment the reference count return new ReportTimelineMissingSegmentQueryRunner<T>(descriptor).run(queryPlus, responseContext); } } }
segment.decrement();
segment.decrement();
segment.decrement();
/** * Returns a {@link Closeable} which action is to call {@link #decrement()} only once. If close() is called on the * returned Closeable object for the second time, it won't call {@link #decrement()} again. */ public Closeable decrementOnceCloseable() { AtomicBoolean decremented = new AtomicBoolean(false); return () -> { if (decremented.compareAndSet(false, true)) { decrement(); } else { log.warn("close() is called more than once on ReferenceCountingSegment.decrementOnceCloseable()"); } }; }