/** * @return true if this iterator has a "next" element */ @Override public boolean hasNext() { return !pathStack.isEmpty(); }
/** * Are there pending buffers in the queue. */ public final boolean isEmpty() { return bufAndListenerPairs.isEmpty(); }
/** * @return whether the buffer is empty */ public synchronized boolean isEmpty() { return pending.isEmpty(); }
/** * Are there pending buffers in the queue. */ public final boolean isEmpty() { return bufAndListenerPairs.isEmpty(); }
synchronized boolean pong(ByteString payload) { // Don't send pongs after we've failed or sent the close frame. if (failed || (enqueuedClose && messageAndCloseQueue.isEmpty())) return false; pongQueue.add(payload); runWriter(); return true; }
@Override public synchronized void onReadPing(ByteString payload) { // Don't respond to pings after we've failed or sent the close frame. if (failed || (enqueuedClose && messageAndCloseQueue.isEmpty())) return; pongQueue.add(payload); runWriter(); receivedPingCount++; }
/** * @return TreeNode next. The next element according to our in-order traversal of the given BST * @throws NoSuchElementException if this iterator does not have a next element */ @Override public TreeNode<T> next() throws NoSuchElementException { if (pathStack.isEmpty()) { throw new NoSuchElementException(); } TreeNode<T> next = pathStack.pop(); pushPathToNextSmallest(next.getRight()); return next; }
@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 onError(Throwable t) { final ArrayDeque<UnicastSubject<T>> ws = windows; while (!ws.isEmpty()) { ws.poll().onError(t); } downstream.onError(t); }
synchronized boolean pong(ByteString payload) { // Don't send pongs after we've failed or sent the close frame. if (failed || (enqueuedClose && messageAndCloseQueue.isEmpty())) return false; pongQueue.add(payload); runWriter(); return true; }
@Override public synchronized void onReadPing(ByteString payload) { // Don't respond to pings after we've failed or sent the close frame. if (failed || (enqueuedClose && messageAndCloseQueue.isEmpty())) return; pongQueue.add(payload); runWriter(); pingCount++; }
@Override public void onError(Throwable t) { final ArrayDeque<UnicastSubject<T>> ws = windows; while (!ws.isEmpty()) { ws.poll().onError(t); } actual.onError(t); }
@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 onReadClose(int code, String reason) { if (code == -1) throw new IllegalArgumentException(); Streams toClose = null; synchronized (this) { if (receivedCloseCode != -1) throw new IllegalStateException("already closed"); receivedCloseCode = code; receivedCloseReason = reason; if (enqueuedClose && messageAndCloseQueue.isEmpty()) { toClose = this.streams; this.streams = null; if (cancelFuture != null) cancelFuture.cancel(false); this.executor.shutdown(); } } try { listener.onClosing(this, code, reason); if (toClose != null) { listener.onClosed(this, code, reason); } } finally { closeQuietly(toClose); } }
/** * Returns a flattened list of Throwables from tree-like CompositeException chain. * @param t the starting throwable * @return the list of Throwables flattened in a depth-first manner */ public static List<Throwable> flatten(Throwable t) { List<Throwable> list = new ArrayList<Throwable>(); ArrayDeque<Throwable> deque = new ArrayDeque<Throwable>(); deque.offer(t); while (!deque.isEmpty()) { Throwable e = deque.removeFirst(); if (e instanceof CompositeException) { CompositeException ce = (CompositeException) e; List<Throwable> exceptions = ce.getExceptions(); for (int i = exceptions.size() - 1; i >= 0; i--) { deque.offerFirst(exceptions.get(i)); } } else { list.add(e); } } return list; }
public void initReaderAndWriter(String name, Streams streams) throws IOException { synchronized (this) { this.streams = streams; this.writer = new WebSocketWriter(streams.client, streams.sink, random); this.executor = new ScheduledThreadPoolExecutor(1, Util.threadFactory(name, false)); if (pingIntervalMillis != 0) { executor.scheduleAtFixedRate( new PingRunnable(), pingIntervalMillis, pingIntervalMillis, MILLISECONDS); } if (!messageAndCloseQueue.isEmpty()) { runWriter(); // Send messages that were enqueued before we were connected. } } reader = new WebSocketReader(streams.client, streams.source, this); }
@Override public Bitmap get(int width, int height, Bitmap.Config config) { return bitmaps.isEmpty() ? null : bitmaps.removeLast(); }
@Override protected Record makeNext() { if (innerEntries.isEmpty()) return allDone(); AbstractLegacyRecordBatch entry = innerEntries.remove(); // Convert offset to absolute offset if needed. if (wrapperMagic == RecordBatch.MAGIC_VALUE_V1) { long absoluteOffset = absoluteBaseOffset + entry.offset(); entry = new BasicLegacyRecordBatch(absoluteOffset, entry.outerRecord()); } if (entry.isCompressed()) throw new InvalidRecordException("Inner messages must not be compressed"); return entry; }