Search in sources :

Example 1 with WindowUpdateFrame

use of org.eclipse.jetty.http2.frames.WindowUpdateFrame in project jetty.project by eclipse.

the class SimpleFlowControlStrategy method onDataConsumed.

@Override
public void onDataConsumed(ISession session, IStream stream, int length) {
    if (length <= 0)
        return;
    // This is the simple algorithm for flow control.
    // This method is called when a whole flow controlled frame has been consumed.
    // We send a WindowUpdate every time, even if the frame was very small.
    WindowUpdateFrame sessionFrame = new WindowUpdateFrame(0, length);
    session.updateRecvWindow(length);
    if (LOG.isDebugEnabled())
        LOG.debug("Data consumed, increased session recv window by {} for {}", length, session);
    Frame[] streamFrame = Frame.EMPTY_ARRAY;
    if (stream != null) {
        if (stream.isClosed()) {
            if (LOG.isDebugEnabled())
                LOG.debug("Data consumed, ignoring update stream recv window by {} for closed {}", length, stream);
        } else {
            streamFrame = new Frame[1];
            streamFrame[0] = new WindowUpdateFrame(stream.getId(), length);
            stream.updateRecvWindow(length);
            if (LOG.isDebugEnabled())
                LOG.debug("Data consumed, increased stream recv window by {} for {}", length, stream);
        }
    }
    session.frames(stream, Callback.NOOP, sessionFrame, streamFrame);
}
Also used : WindowUpdateFrame(org.eclipse.jetty.http2.frames.WindowUpdateFrame) WindowUpdateFrame(org.eclipse.jetty.http2.frames.WindowUpdateFrame) Frame(org.eclipse.jetty.http2.frames.Frame)

Example 2 with WindowUpdateFrame

use of org.eclipse.jetty.http2.frames.WindowUpdateFrame 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 3 with WindowUpdateFrame

use of org.eclipse.jetty.http2.frames.WindowUpdateFrame 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 4 with WindowUpdateFrame

use of org.eclipse.jetty.http2.frames.WindowUpdateFrame in project jetty.project by eclipse.

the class WindowUpdateBodyParser method onWindowUpdate.

private boolean onWindowUpdate(int windowDelta) {
    WindowUpdateFrame frame = new WindowUpdateFrame(getStreamId(), windowDelta);
    reset();
    notifyWindowUpdate(frame);
    return true;
}
Also used : WindowUpdateFrame(org.eclipse.jetty.http2.frames.WindowUpdateFrame)

Example 5 with WindowUpdateFrame

use of org.eclipse.jetty.http2.frames.WindowUpdateFrame in project jetty.project by eclipse.

the class HTTP2ServerSession method onPreface.

@Override
public void onPreface() {
    // SPEC: send a SETTINGS frame upon receiving the preface.
    Map<Integer, Integer> settings = notifyPreface(this);
    if (settings == null)
        settings = Collections.emptyMap();
    SettingsFrame settingsFrame = new SettingsFrame(settings, false);
    WindowUpdateFrame windowFrame = null;
    int sessionWindow = getInitialSessionRecvWindow() - FlowControlStrategy.DEFAULT_WINDOW_SIZE;
    if (sessionWindow > 0) {
        updateRecvWindow(sessionWindow);
        windowFrame = new WindowUpdateFrame(0, sessionWindow);
    }
    if (windowFrame == null)
        frames(null, Callback.NOOP, settingsFrame, Frame.EMPTY_ARRAY);
    else
        frames(null, Callback.NOOP, settingsFrame, windowFrame);
}
Also used : SettingsFrame(org.eclipse.jetty.http2.frames.SettingsFrame) WindowUpdateFrame(org.eclipse.jetty.http2.frames.WindowUpdateFrame) EndPoint(org.eclipse.jetty.io.EndPoint)

Aggregations

WindowUpdateFrame (org.eclipse.jetty.http2.frames.WindowUpdateFrame)5 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 Frame (org.eclipse.jetty.http2.frames.Frame)2 HeaderGenerator (org.eclipse.jetty.http2.generator.HeaderGenerator)2 WindowUpdateGenerator (org.eclipse.jetty.http2.generator.WindowUpdateGenerator)2 Parser (org.eclipse.jetty.http2.parser.Parser)2 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)2 MappedByteBufferPool (org.eclipse.jetty.io.MappedByteBufferPool)2 Test (org.junit.Test)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Stream (org.eclipse.jetty.http2.api.Stream)1 SettingsFrame (org.eclipse.jetty.http2.frames.SettingsFrame)1 EndPoint (org.eclipse.jetty.io.EndPoint)1