IStream stream = frameBytes.getStream(); frameBytes.failed(new StreamException(frameBytes.getStream().getId(), StreamStatus.INVALID_STREAM, "Stream: " + frameBytes.getStream() + " is reset!")); continue; buffers[i] = active.get(i).getByteBuffer();
@Override public void succeeded() { synchronized (lock) { if (LOG.isDebugEnabled()) LOG.debug("Succeeded write of {}, q={}", active, queue.size()); succeeded.addAll(active); active.clear(); } // Notify outside the synchronized block. for (FrameBytes frame : succeeded) frame.succeeded(); succeeded.clear(); super.succeeded(); }
public Throwable prepend(StandardSession.FrameBytes frameBytes) { synchronized (lock) { Throwable failure = this.failure; if (failure == null) { // Scan from the front of the queue looking to skip higher priority messages int index = 0; int size = queue.size(); while (index < size) { StandardSession.FrameBytes element = queue.getUnsafe(index); if (element.compareTo(frameBytes) <= 0) break; ++index; } queue.add(index, frameBytes); } return failure; } }
public Throwable append(StandardSession.DataFrameBytes frameBytes) { synchronized (lock) { Throwable failure = this.failure; if (failure == null) { // DataFrameBytes are inserted by priority int index = queue.size(); while (index > 0) { StandardSession.FrameBytes element = queue.getUnsafe(index - 1); if (element.compareTo(frameBytes) >= 0) break; --index; } queue.add(index, frameBytes); } return failure; } }
@Override public void onCompleteFailure(Throwable x) { List<StandardSession.FrameBytes> failed = new ArrayList<>(); synchronized (lock) { failure = x; if (LOG.isDebugEnabled()) { String logMessage = String.format("Failed write of %s, failing all %d frame(s) in queue", this, queue.size()); LOG.debug(logMessage, x); } failed.addAll(active); active.clear(); failed.addAll(queue); queue.clear(); } // Notify outside the synchronized block. for (StandardSession.FrameBytes frame : failed) frame.failed(x); } }
public void removeFrameBytesFromQueue(Stream stream) { synchronized (lock) { for (StandardSession.FrameBytes frameBytes : queue) if (frameBytes.getStream() == stream) queue.remove(frameBytes); } }
@Override public int compareTo(FrameBytes that) { // FrameBytes may have or not have a related stream (for example, PING do not have a related stream) // FrameBytes without related streams have higher priority IStream thisStream = getStream(); IStream thatStream = that.getStream(); if (thisStream == null) return thatStream == null ? 0 : -1; if (thatStream == null) return 1; // If this.stream.priority > that.stream.priority => this.stream has less priority than that.stream return thatStream.getPriority() - thisStream.getPriority(); }
private void flush(FrameBytes frameBytes, Throwable throwable) { if (throwable != null) frameBytes.failed(throwable); else flusher.flush(); }