@Override public void data(DataInfo dataInfo, Callback callback) { notIdle(); if (!canSend()) { session.rst(new RstInfo(getId(), StreamStatus.PROTOCOL_ERROR), new StreamCallback()); throw new IllegalStateException("Protocol violation: cannot send a DATA frame before a SYN_REPLY frame"); } if (isLocallyClosed()) { session.rst(new RstInfo(getId(), StreamStatus.PROTOCOL_ERROR), new StreamCallback()); throw new IllegalStateException("Protocol violation: cannot send a DATA frame on a locally closed stream"); } // Cannot update the close state here, because the data that we send may // be flow controlled, so we need the stream to update the window size. session.data(this, dataInfo, dataInfo.getTimeout(), dataInfo.getUnit(), new StreamCallback(callback)); }
@Override public void reply(ReplyInfo replyInfo, Callback callback) { notIdle(); if (isUnidirectional()) { close(); throw new IllegalStateException("Protocol violation: cannot send SYN_REPLY frames in unidirectional streams"); } openState = OpenState.REPLY_SENT; updateCloseState(replyInfo.isClose(), true); SynReplyFrame frame = new SynReplyFrame(session.getVersion(), replyInfo.getFlags(), getId(), replyInfo.getHeaders()); session.control(this, frame, replyInfo.getTimeout(), replyInfo.getUnit(), new StreamCallback(callback)); }
@Override public void push(PushInfo pushInfo, Promise<Stream> promise) { notIdle(); if (isClosed() || isReset()) { close(); promise.failed(new StreamException(getId(), StreamStatus.STREAM_ALREADY_CLOSED, "Stream: " + this + " already closed or reset!")); return; } PushSynInfo pushSynInfo = new PushSynInfo(getId(), pushInfo); session.syn(pushSynInfo, null, new StreamPromise(promise)); }
@Override public void headers(HeadersInfo headersInfo, Callback callback) { notIdle(); if (!canSend()) { session.rst(new RstInfo(getId(), StreamStatus.PROTOCOL_ERROR), new StreamCallback()); throw new IllegalStateException("Protocol violation: cannot send a HEADERS frame before a SYN_REPLY frame"); } if (isLocallyClosed()) { session.rst(new RstInfo(getId(), StreamStatus.PROTOCOL_ERROR), new StreamCallback()); throw new IllegalStateException("Protocol violation: cannot send a HEADERS frame on a closed stream"); } updateCloseState(headersInfo.isClose(), true); HeadersFrame frame = new HeadersFrame(session.getVersion(), headersInfo.getFlags(), getId(), headersInfo.getHeaders()); session.control(this, frame, headersInfo.getTimeout(), headersInfo.getUnit(), new StreamCallback(callback)); }
@Override public void process(DataInfo dataInfo) { notIdle(); // TODO: in v3 we need to send a rst instead of just ignoring // ignore data frame if this stream is remotelyClosed already if (isRemotelyClosed()) { if (LOG.isDebugEnabled()) LOG.debug("Stream is remotely closed, ignoring {}", dataInfo); return; } if (!canReceive()) { if (LOG.isDebugEnabled()) LOG.debug("Protocol error receiving {}, resetting", dataInfo); session.rst(new RstInfo(getId(), StreamStatus.PROTOCOL_ERROR), Callback.Adapter.INSTANCE); return; } updateCloseState(dataInfo.isClose(), false); notifyOnData(dataInfo); }
@Override public void process(ControlFrame frame) notIdle(); switch (frame.getType())