Search in sources :

Example 6 with IStream

use of org.eclipse.jetty.http2.IStream in project jetty.project by eclipse.

the class AbstractFlowControlStrategy method updateInitialStreamWindow.

@Override
public void updateInitialStreamWindow(ISession session, int initialStreamWindow, boolean local) {
    int previousInitialStreamWindow;
    if (local) {
        previousInitialStreamWindow = getInitialStreamRecvWindow();
        this.initialStreamRecvWindow = initialStreamWindow;
    } else {
        previousInitialStreamWindow = getInitialStreamSendWindow();
        this.initialStreamSendWindow = initialStreamWindow;
    }
    int delta = initialStreamWindow - previousInitialStreamWindow;
    // SPEC: updates of the initial window size only affect stream windows, not session's.
    for (Stream stream : session.getStreams()) {
        if (local) {
            ((IStream) stream).updateRecvWindow(delta);
            if (LOG.isDebugEnabled())
                LOG.debug("Updated initial stream recv window {} -> {} for {}", previousInitialStreamWindow, initialStreamWindow, stream);
        } else {
            session.onWindowUpdate((IStream) stream, new WindowUpdateFrame(stream.getId(), delta));
        }
    }
}
Also used : WindowUpdateFrame(org.eclipse.jetty.http2.frames.WindowUpdateFrame) Stream(org.eclipse.jetty.http2.api.Stream)

Example 7 with IStream

use of org.eclipse.jetty.http2.IStream in project jetty.project by eclipse.

the class BufferingFlowControlStrategy method onDataConsumed.

@Override
public void onDataConsumed(ISession session, IStream stream, int length) {
    if (length <= 0)
        return;
    float ratio = bufferRatio;
    WindowUpdateFrame windowFrame = null;
    int level = sessionLevel.addAndGet(length);
    int maxLevel = (int) (maxSessionRecvWindow.get() * ratio);
    if (level > maxLevel) {
        if (sessionLevel.compareAndSet(level, 0)) {
            session.updateRecvWindow(level);
            if (LOG.isDebugEnabled())
                LOG.debug("Data consumed, {} bytes, updated session recv window by {}/{} for {}", length, level, maxLevel, session);
            windowFrame = new WindowUpdateFrame(0, level);
        } else {
            if (LOG.isDebugEnabled())
                LOG.debug("Data consumed, {} bytes, concurrent session recv window level {}/{} for {}", length, sessionLevel, maxLevel, session);
        }
    } else {
        if (LOG.isDebugEnabled())
            LOG.debug("Data consumed, {} bytes, session recv window level {}/{} for {}", length, level, maxLevel, session);
    }
    Frame[] windowFrames = Frame.EMPTY_ARRAY;
    if (stream != null) {
        if (stream.isClosed()) {
            if (LOG.isDebugEnabled())
                LOG.debug("Data consumed, {} bytes, ignoring update stream recv window for closed {}", length, stream);
        } else {
            AtomicInteger streamLevel = streamLevels.get(stream);
            if (streamLevel != null) {
                level = streamLevel.addAndGet(length);
                maxLevel = (int) (getInitialStreamRecvWindow() * ratio);
                if (level > maxLevel) {
                    level = streamLevel.getAndSet(0);
                    stream.updateRecvWindow(level);
                    if (LOG.isDebugEnabled())
                        LOG.debug("Data consumed, {} bytes, updated stream recv window by {}/{} for {}", length, level, maxLevel, stream);
                    WindowUpdateFrame frame = new WindowUpdateFrame(stream.getId(), level);
                    if (windowFrame == null)
                        windowFrame = frame;
                    else
                        windowFrames = new Frame[] { frame };
                } else {
                    if (LOG.isDebugEnabled())
                        LOG.debug("Data consumed, {} bytes, stream recv window level {}/{} for {}", length, level, maxLevel, stream);
                }
            }
        }
    }
    if (windowFrame != null)
        session.frames(stream, Callback.NOOP, windowFrame, windowFrames);
}
Also used : WindowUpdateFrame(org.eclipse.jetty.http2.frames.WindowUpdateFrame) WindowUpdateFrame(org.eclipse.jetty.http2.frames.WindowUpdateFrame) Frame(org.eclipse.jetty.http2.frames.Frame) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 8 with IStream

use of org.eclipse.jetty.http2.IStream in project jetty.project by eclipse.

the class HTTP2Session method newStream.

@Override
public void newStream(HeadersFrame frame, Promise<Stream> promise, Stream.Listener listener) {
    // Synchronization is necessary to atomically create
    // the stream id and enqueue the frame to be sent.
    boolean queued;
    synchronized (this) {
        int streamId = frame.getStreamId();
        if (streamId <= 0) {
            streamId = streamIds.getAndAdd(2);
            PriorityFrame priority = frame.getPriority();
            priority = priority == null ? null : new PriorityFrame(streamId, priority.getParentStreamId(), priority.getWeight(), priority.isExclusive());
            frame = new HeadersFrame(streamId, frame.getMetaData(), priority, frame.isEndStream());
        }
        final IStream stream = createLocalStream(streamId, promise);
        if (stream == null)
            return;
        stream.setListener(listener);
        ControlEntry entry = new ControlEntry(frame, stream, new PromiseCallback<>(promise, stream));
        queued = flusher.append(entry);
    }
    // Iterate outside the synchronized block.
    if (queued)
        flusher.iterate();
}
Also used : PriorityFrame(org.eclipse.jetty.http2.frames.PriorityFrame) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) EndPoint(org.eclipse.jetty.io.EndPoint)

Example 9 with IStream

use of org.eclipse.jetty.http2.IStream in project jetty.project by eclipse.

the class HTTP2Session method createRemoteStream.

protected IStream createRemoteStream(int streamId) {
    // SPEC: exceeding max concurrent streams is treated as stream error.
    while (true) {
        int remoteCount = remoteStreamCount.get();
        int maxCount = getMaxRemoteStreams();
        if (maxCount >= 0 && remoteCount >= maxCount) {
            reset(new ResetFrame(streamId, ErrorCode.REFUSED_STREAM_ERROR.code), Callback.NOOP);
            return null;
        }
        if (remoteStreamCount.compareAndSet(remoteCount, remoteCount + 1))
            break;
    }
    IStream stream = newStream(streamId, false);
    // SPEC: duplicate stream is treated as connection error.
    if (streams.putIfAbsent(streamId, stream) == null) {
        updateLastStreamId(streamId);
        stream.setIdleTimeout(getStreamIdleTimeout());
        flowControl.onStreamCreated(stream);
        if (LOG.isDebugEnabled())
            LOG.debug("Created remote {}", stream);
        return stream;
    } else {
        close(ErrorCode.PROTOCOL_ERROR.code, "duplicate_stream", Callback.NOOP);
        return null;
    }
}
Also used : ResetFrame(org.eclipse.jetty.http2.frames.ResetFrame) EndPoint(org.eclipse.jetty.io.EndPoint)

Example 10 with IStream

use of org.eclipse.jetty.http2.IStream in project jetty.project by eclipse.

the class HTTP2Session method priority.

@Override
public int priority(PriorityFrame frame, Callback callback) {
    int streamId = frame.getStreamId();
    IStream stream = streams.get(streamId);
    if (stream == null) {
        streamId = streamIds.getAndAdd(2);
        frame = new PriorityFrame(streamId, frame.getParentStreamId(), frame.getWeight(), frame.isExclusive());
    }
    control(stream, callback, frame);
    return streamId;
}
Also used : PriorityFrame(org.eclipse.jetty.http2.frames.PriorityFrame) EndPoint(org.eclipse.jetty.io.EndPoint)

Aggregations

IStream (org.eclipse.jetty.http2.IStream)6 EndPoint (org.eclipse.jetty.io.EndPoint)6 Stream (org.eclipse.jetty.http2.api.Stream)5 MetaData (org.eclipse.jetty.http.MetaData)4 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)3 WindowUpdateFrame (org.eclipse.jetty.http2.frames.WindowUpdateFrame)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 HttpFields (org.eclipse.jetty.http.HttpFields)2 ISession (org.eclipse.jetty.http2.ISession)2 Session (org.eclipse.jetty.http2.api.Session)2 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)2 DataFrame (org.eclipse.jetty.http2.frames.DataFrame)2 Frame (org.eclipse.jetty.http2.frames.Frame)2 PriorityFrame (org.eclipse.jetty.http2.frames.PriorityFrame)2 ResetFrame (org.eclipse.jetty.http2.frames.ResetFrame)2 Callback (org.eclipse.jetty.util.Callback)2 FuturePromise (org.eclipse.jetty.util.FuturePromise)2 Test (org.junit.Test)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayDeque (java.util.ArrayDeque)1