if (isClosed()) { http2Session.sendMessageUpstream(stream, buildBrokenHttpContent( new EOFException(closeFlag.getDescription()))); switchOnExpectInput(); if ((queueSize = switchOffExpectInputIfQueueNotEmpty()) > 0) { passPayloadUpstream(null, queueSize);
/** * Retrieves available input buffer payload, waiting up to the * {@link Connection#getReadTimeout(java.util.concurrent.TimeUnit)} * wait time if necessary for payload to become available. * * @throws IOException if an error occurs with the poll operation. */ @Override public HttpContent poll() throws IOException { return buildHttpContent(poll0()); }
/** * The private method, which adds new InputElement to the input queue */ private void offer0(final InputElement inputElement) { if (switchOffExpectInput()) { // if "expect more input" switch is on - pass current input queue content upstream passPayloadUpstream(inputElement, inputQueueSize); } else { // if "expect more input" switch is off - enqueue the element if (!inputQueue.offer(inputElement)) { // Should never happen, but findbugs complains throw new IllegalStateException("New element can't be added"); } inputQueueSizeUpdater.incrementAndGet(this); final int readyBuffersCount; // double check if "expect more input" flag is still off if ((readyBuffersCount = switchOffExpectInputIfQueueNotEmpty()) > 0) { // if not - pass the input queue content upstream passPayloadUpstream(null, readyBuffersCount); } } }
if (readyBuffersCount > 0) { payload = poll0(); assert payload != null; http2Session.ackConsumedData(stream, bufSz(data)); } else if (payload == null) { payload = data; checkEOF(inputElement); final HttpContent content = buildHttpContent(payload);
new Object[]{stream.getId(), data, isLast}); final boolean isLastData = isLast | checkContentLength(data.remaining()); offer0(element); if (isClosed() && inputQueue.remove(element)) { data.tryDispose(); return false;
/** * Graceful input buffer close. * * Marks the input buffer as closed by adding Termination input element to the input queue. */ @Override public void close(final Termination termination) { if (inputClosed.compareAndSet(false, true)) { final Termination.TerminationType type = termination.getType(); if (termination.isSessionClosed()) { return; } offer0(new InputElement(termination, true, true)); } }
/** * Create HTTP2 stream. * * @param http2Session the {@link Http2Session} for this {@link Http2Stream}. * @param request the {@link HttpRequestPacket} initiating the stream. * @param streamId this stream's ID. * @param parentStreamId the parent stream, if any. * @param priority the priority of this stream. */ protected Http2Stream(final Http2Session http2Session, final HttpRequestPacket request, final int streamId, final int parentStreamId, final boolean exclusive, final int priority) { this.http2Session = http2Session; this.request = request; this.streamId = streamId; this.parentStreamId = parentStreamId; this.exclusive = exclusive; this.priority = priority; this.state = State.IDLE; inputBuffer = new DefaultInputBuffer(this); outputSink = new DefaultOutputSink(this); HTTP_RQST_HTTP2_STREAM_ATTR.set(request, this); }
/** * Builds {@link HttpContent} based on passed payload {@link Buffer}. * If the payload size is <tt>0</tt> and the input buffer has been terminated - * return {@link HttpBrokenContent}. */ private HttpContent buildHttpContent(final Buffer payload) { final Termination localTermination = closeFlag; final boolean isFin = localTermination == IN_FIN_TERMINATION; final HttpContent httpContent; // if payload size is not 0 or this is FIN payload if (payload.hasRemaining() || localTermination == null || isFin) { final HttpHeader inputHttpHeader = stream.getInputHttpHeader(); inputHttpHeader.setExpectContent(!isFin); httpContent = HttpContent.builder(inputHttpHeader) .content(payload) .last(isFin) .build(); } else { // create broken HttpContent httpContent = buildBrokenHttpContent( new EOFException(localTermination.getDescription())); } return httpContent; }
if (readyBuffersCount > 0) { payload = poll0(); assert payload != null; http2Session.ackConsumedData(stream, bufSz(data)); } else if (payload == null) { payload = data; checkEOF(inputElement); final HttpContent content = buildHttpContent(payload);
/** * The private method, which adds new InputElement to the input queue */ private void offer0(final InputElement inputElement) { if (switchOffExpectInput()) { // if "expect more input" switch is on - pass current input queue content upstream passPayloadUpstream(inputElement, inputQueueSize); } else { // if "expect more input" switch is off - enqueue the element if (!inputQueue.offer(inputElement)) { // Should never happen, but findbugs complains throw new IllegalStateException("New element can't be added"); } inputQueueSizeUpdater.incrementAndGet(this); final int readyBuffersCount; // double check if "expect more input" flag is still off if ((readyBuffersCount = switchOffExpectInputIfQueueNotEmpty()) > 0) { // if not - pass the input queue content upstream passPayloadUpstream(null, readyBuffersCount); } } }
new Object[]{stream.getId(), data, isLast}); final boolean isLastData = isLast | checkContentLength(data.remaining()); offer0(element); if (isClosed() && inputQueue.remove(element)) { data.tryDispose(); return false;
/** * Graceful input buffer close. * * Marks the input buffer as closed by adding Termination input element to the input queue. */ @Override public void close(final Termination termination) { if (inputClosed.compareAndSet(false, true)) { final Termination.TerminationType type = termination.getType(); if (termination.isSessionClosed()) { return; } offer0(new InputElement(termination, true, true)); } }
/** * Create HTTP2 stream. * * @param http2Session the {@link Http2Session} for this {@link Http2Stream}. * @param request the {@link HttpRequestPacket} initiating the stream. * @param streamId this stream's ID. * @param parentStreamId the parent stream, if any. * @param priority the priority of this stream. */ protected Http2Stream(final Http2Session http2Session, final HttpRequestPacket request, final int streamId, final int parentStreamId, final boolean exclusive, final int priority) { this.http2Session = http2Session; this.request = request; this.streamId = streamId; this.parentStreamId = parentStreamId; this.exclusive = exclusive; this.priority = priority; this.state = State.IDLE; inputBuffer = new DefaultInputBuffer(this); outputSink = new DefaultOutputSink(this); HTTP_RQST_HTTP2_STREAM_ATTR.set(request, this); }
/** * Builds {@link HttpContent} based on passed payload {@link Buffer}. * If the payload size is <tt>0</tt> and the input buffer has been terminated - * return {@link HttpBrokenContent}. */ private HttpContent buildHttpContent(final Buffer payload) { final Termination localTermination = closeFlag; final boolean isFin = localTermination == IN_FIN_TERMINATION; final HttpContent httpContent; // if payload size is not 0 or this is FIN payload if (payload.hasRemaining() || localTermination == null || isFin) { final HttpHeader inputHttpHeader = stream.getInputHttpHeader(); inputHttpHeader.setExpectContent(!isFin); httpContent = HttpContent.builder(inputHttpHeader) .content(payload) .last(isFin) .build(); } else { // create broken HttpContent httpContent = buildBrokenHttpContent( new EOFException(localTermination.getDescription())); } return httpContent; }
if (isClosed()) { http2Session.sendMessageUpstream(stream, buildBrokenHttpContent( new EOFException(closeFlag.getDescription()))); switchOnExpectInput(); if ((queueSize = switchOffExpectInputIfQueueNotEmpty()) > 0) { passPayloadUpstream(null, queueSize);
if (readyBuffersCount > 0) { payload = poll0(); assert payload != null; http2Session.ackConsumedData(stream, bufSz(data)); } else if (payload == null) { payload = data; checkEOF(inputElement); final HttpContent content = buildHttpContent(payload);
/** * The private method, which adds new InputElement to the input queue */ private void offer0(final InputElement inputElement) { if (switchOffExpectInput()) { // if "expect more input" switch is on - pass current input queue content upstream passPayloadUpstream(inputElement, inputQueueSize); } else { // if "expect more input" switch is off - enqueue the element if (!inputQueue.offer(inputElement)) { // Should never happen, but findbugs complains throw new IllegalStateException("New element can't be added"); } inputQueueSizeUpdater.incrementAndGet(this); final int readyBuffersCount; // double check if "expect more input" flag is still off if ((readyBuffersCount = switchOffExpectInputIfQueueNotEmpty()) > 0) { // if not - pass the input queue content upstream passPayloadUpstream(null, readyBuffersCount); } } }
new Object[]{stream.getId(), data, isLast}); final boolean isLastData = isLast | checkContentLength(data.remaining()); offer0(element); if (isClosed() && inputQueue.remove(element)) { data.tryDispose(); return false;