protected IStream newStream(int streamId, boolean local) { return new HTTP2Stream(scheduler, this, streamId, local); }
@Override public Object getAttribute(String key) { return attributes().get(key); }
private void onReset(ResetFrame frame, Callback callback) { remoteReset = true; close(); session.removeStream(this); notifyReset(this, frame, callback); }
private void onData(DataFrame frame, Callback callback) if (getRecvWindow() < 0) if (isRemotelyClosed()) reset(new ResetFrame(streamId, ErrorCode.STREAM_CLOSED_ERROR.code), Callback.NOOP); callback.failed(new EOFException("stream_closed")); return; if (isReset()) if (frame.isEndStream() && dataLength != 0) reset(new ResetFrame(streamId, ErrorCode.PROTOCOL_ERROR.code), Callback.NOOP); callback.failed(new IOException("invalid_data_length")); return; if (updateClose(frame.isEndStream(), CloseState.Event.RECEIVED)) session.removeStream(this); notifyData(this, frame, callback);
@Override protected void onIdleExpired(TimeoutException timeout) { if (LOG.isDebugEnabled()) LOG.debug("Idle timeout {}ms expired on {}", getIdleTimeout(), this); // Notify the application. if (notifyIdleTimeout(this, timeout)) { // Tell the other peer that we timed out. reset(new ResetFrame(getId(), ErrorCode.CANCEL_STREAM_ERROR.code), Callback.NOOP); } }
updateStreamCount(0, 1); return false; close(); return true;
@Override public String toString() { return String.format("%s@%x#%d{sendWindow=%s,recvWindow=%s,reset=%b,%s,age=%d,attachment=%s}", getClass().getSimpleName(), hashCode(), getId(), sendWindow, recvWindow, isReset(), closeState, TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - timeStamp), attachment); } }
@Override public void succeeded() { Callback callback = endWrite(); if (callback != null) callback.succeeded(); }
private boolean updateCloseAfterSend() { while (true) { CloseState current = closeState.get(); switch (current) { case NOT_CLOSED: case LOCALLY_CLOSING: { if (closeState.compareAndSet(current, CloseState.LOCALLY_CLOSED)) return false; break; } case REMOTELY_CLOSED: case CLOSING: { close(); return true; } default: { return false; } } } }
@Override public boolean isOpen() { return !isClosed(); }
private void updateStreamCount(int deltaStream, int deltaClosing) { ((HTTP2Session)session).updateStreamCount(isLocal(), deltaStream, deltaClosing); }
@Override public String toString() { return String.format("%s@%x#%d{sendWindow=%s,recvWindow=%s,reset=%b/%b,%s,age=%d,attachment=%s}", getClass().getSimpleName(), hashCode(), getId(), sendWindow, recvWindow, localReset, remoteReset, closeState, TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - timeStamp), attachment); } }
private void onData(DataFrame frame, Callback callback) if (getRecvWindow() < 0) if (isRemotelyClosed()) reset(new ResetFrame(streamId, ErrorCode.STREAM_CLOSED_ERROR.code), Callback.NOOP); callback.failed(new EOFException("stream_closed")); return; if (isReset()) if (frame.isEndStream() && dataLength != 0) reset(new ResetFrame(streamId, ErrorCode.PROTOCOL_ERROR.code), Callback.NOOP); callback.failed(new IOException("invalid_data_length")); return; if (updateClose(frame.isEndStream(), CloseState.Event.RECEIVED)) session.removeStream(this); notifyData(this, frame, callback);
@Override protected void onIdleExpired(TimeoutException timeout) { if (LOG.isDebugEnabled()) LOG.debug("Idle timeout {}ms expired on {}", getIdleTimeout(), this); // Notify the application. if (notifyIdleTimeout(this, timeout)) { // Tell the other peer that we timed out. reset(new ResetFrame(getId(), ErrorCode.CANCEL_STREAM_ERROR.code), Callback.NOOP); } }
updateStreamCount(0, 1); return false; close(); return true;
@Override public void failed(Throwable x) { Callback callback = endWrite(); if (callback != null) callback.failed(x); }
private boolean updateCloseAfterSend() { while (true) { CloseState current = closeState.get(); switch (current) { case NOT_CLOSED: case LOCALLY_CLOSING: { if (closeState.compareAndSet(current, CloseState.LOCALLY_CLOSED)) return false; break; } case REMOTELY_CLOSED: case CLOSING: { close(); return true; } default: { return false; } } } }
@Override public boolean isOpen() { return !isClosed(); }
private void updateStreamCount(int deltaStream, int deltaClosing) { ((HTTP2Session)session).updateStreamCount(isLocal(), deltaStream, deltaClosing); }
private void onReset(ResetFrame frame, Callback callback) { remoteReset = true; close(); session.removeStream(this); notifyReset(this, frame, callback); }