/** * Read the most recent element synchronously. * <p/> * No handler will be called. * * @return the most recent element or {@code null} if no element was in the buffer */ public E read() { synchronized (this) { return pending.poll(); } }
@Override @Nullable public BufferOrEvent getNext() { return queuedBuffers.poll(); }
@Override public void onComplete() { final ArrayDeque<UnicastSubject<T>> ws = windows; while (!ws.isEmpty()) { ws.poll().onComplete(); } downstream.onComplete(); }
@Override public void onComplete() { while (!buffers.isEmpty()) { downstream.onNext(buffers.poll()); } downstream.onComplete(); } }
@Override public void onSettingsAckRead(ChannelHandlerContext ctx) { Handler<Void> handler; synchronized (this) { handler = updateSettingsHandlers.poll(); } if (handler != null) { // No need to run on a particular context it shall be done by the handler instead context.executeFromIO(handler); } }
@Override public void onError(Throwable t) { final ArrayDeque<UnicastSubject<T>> ws = windows; while (!ws.isEmpty()) { ws.poll().onError(t); } downstream.onError(t); }
void disposeAll() { InnerQueuedObserver<R> inner = current; if (inner != null) { inner.dispose(); } for (;;) { inner = observers.poll(); if (inner == null) { return; } inner.dispose(); } }
@Override public void onPingAckRead(ChannelHandlerContext ctx, long data) throws Http2Exception { Handler<AsyncResult<Buffer>> handler = pongHandlers.poll(); if (handler != null) { context.executeFromIO(v -> { Buffer buff = Buffer.buffer().appendLong(data); handler.handle(Future.succeededFuture(buff)); }); } }
@Override public AsyncResult poll() throws InterruptedException { lock.lockInterruptibly(); try { while (queue.isEmpty() || !queue.peek().isDone()) { headIsCompleted.await(); } notFull.signalAll(); LOG.debug("Polled head element from ordered stream element queue. New filling degree " + "({}/{}).", queue.size() - 1, capacity); return queue.poll(); } finally { lock.unlock(); } }
/** * Remove the first {@link ByteBuf} from the queue. * @param aggregatePromise used to aggregate the promises and listeners for the returned buffer. * @return the first {@link ByteBuf} from the queue. */ public final ByteBuf removeFirst(ChannelPromise aggregatePromise) { Object entry = bufAndListenerPairs.poll(); if (entry == null) { return null; } assert entry instanceof ByteBuf; ByteBuf result = (ByteBuf) entry; decrementReadableBytes(result.readableBytes()); entry = bufAndListenerPairs.peek(); if (entry instanceof ChannelFutureListener) { aggregatePromise.addListener((ChannelFutureListener) entry); bufAndListenerPairs.poll(); } return result; }
@Override public void onComplete() { while (!buffers.isEmpty()) { actual.onNext(buffers.poll()); } actual.onComplete(); } }
@Override public void onComplete() { final ArrayDeque<UnicastSubject<T>> ws = windows; while (!ws.isEmpty()) { ws.poll().onComplete(); } actual.onComplete(); }
@Override public void onError(Throwable t) { final ArrayDeque<UnicastSubject<T>> ws = windows; while (!ws.isEmpty()) { ws.poll().onError(t); } actual.onError(t); }
void disposeAll() { InnerQueuedObserver<R> inner = current; if (inner != null) { inner.dispose(); } for (;;) { inner = observers.poll(); if (inner == null) { return; } inner.dispose(); } }
@Override public void onNext(T t) { final ArrayDeque<UnicastSubject<T>> ws = windows; long i = index; long s = skip; if (i % s == 0 && !cancelled) { wip.getAndIncrement(); UnicastSubject<T> w = UnicastSubject.create(capacityHint, this); ws.offer(w); downstream.onNext(w); } long c = firstEmission + 1; for (UnicastSubject<T> w : ws) { w.onNext(t); } if (c >= count) { ws.poll().onComplete(); if (ws.isEmpty() && cancelled) { this.upstream.dispose(); return; } firstEmission = c - s; } else { firstEmission = c; } index = i + 1; }
@Override public HashMap<KafkaTopicPartition, Long> snapshotCurrentState() { checkState(!stateSnapshotsToReturn.isEmpty()); return stateSnapshotsToReturn.poll(); }
@Override public void close() { BufferOrEvent boe; while ((boe = currentBuffers.poll()) != null) { if (boe.isBuffer()) { boe.getBuffer().recycleBuffer(); } } }
@Override public void cleanup() { BufferOrEvent boe; while ((boe = queuedBuffers.poll()) != null) { if (boe.isBuffer()) { boe.getBuffer().recycleBuffer(); } } }
produced = p - skip; Processor<T, T> w = windows.poll(); if (w != null) { w.onComplete();