@Override public void setWindowSize(ISession session, int windowSize) { int prevWindowSize = this.windowSize; this.windowSize = windowSize; for (Stream stream : session.getStreams()) ((IStream)stream).updateWindowSize(windowSize - prevWindowSize); }
@Override public String toString() { return String.format("stream=%d v%d windowSize=%d reset=%s prio=%d %s %s", getId(), session.getVersion(), getWindowSize(), isReset(), priority, openState, closeState); }
protected void goAway(ISession session) { if (session != null) session.goAway(new GoAwayInfo(), Callback.Adapter.INSTANCE); }
@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 onDataConsumed(ISession session, IStream stream, DataInfo dataInfo, int delta) { // This is the algorithm for flow control. // This method may be called multiple times with delta=1, but we only send a window // update when the whole dataInfo has been consumed. // Other policies may be to send window updates when consumed() is greater than // a certain threshold, etc. but for now the policy is not pluggable for simplicity. // Note that the frequency of window updates depends on the read buffer, that // should not be too smaller than the window size to avoid frequent window updates. // Therefore, a pluggable policy should be able to modify the read buffer capacity. int length = dataInfo.length(); if (dataInfo.consumed() == length && !stream.isClosed() && length > 0) { WindowUpdateFrame windowUpdateFrame = new WindowUpdateFrame(session.getVersion(), stream.getId(), length); session.control(stream, windowUpdateFrame, 0, TimeUnit.MILLISECONDS, Callback.Adapter.INSTANCE); } } }
@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)); }
private void shutdown(ISession session) { if (session != null && !getEndPoint().isOutputShutdown()) session.shutdown(); }
public ProxyHTTPSPDYAsyncConnection(SPDYServerConnector connector, EndPoint endPoint, short version, ProxyEngineSelector proxyEngineSelector) { super(connector, endPoint, connector.getServer()); this.version = version; this.proxyEngineSelector = proxyEngineSelector; this.generator = (HttpGenerator)_generator; this.session = new HTTPSession(version, connector); this.session.setAttribute("org.eclipse.jetty.spdy.remoteAddress", endPoint.getRemoteAddr()); }
@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 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 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)); }