1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.spdy;
15
16 import java.util.concurrent.TimeUnit;
17
18 import org.eclipse.jetty.spdy.api.DataInfo;
19 import org.eclipse.jetty.spdy.api.Stream;
20 import org.eclipse.jetty.spdy.frames.WindowUpdateFrame;
21
22 public class SPDYv3FlowControlStrategy implements FlowControlStrategy
23 {
24 private volatile int windowSize;
25
26 @Override
27 public int getWindowSize(ISession session)
28 {
29 return windowSize;
30 }
31
32 @Override
33 public void setWindowSize(ISession session, int windowSize)
34 {
35 int prevWindowSize = this.windowSize;
36 this.windowSize = windowSize;
37 for (Stream stream : session.getStreams())
38 ((IStream)stream).updateWindowSize(windowSize - prevWindowSize);
39 }
40
41 @Override
42 public void onNewStream(ISession session, IStream stream)
43 {
44 stream.updateWindowSize(windowSize);
45 }
46
47 @Override
48 public void onWindowUpdate(ISession session, IStream stream, int delta)
49 {
50 if (stream != null)
51 stream.updateWindowSize(delta);
52 }
53
54 @Override
55 public void updateWindow(ISession session, IStream stream, int delta)
56 {
57 stream.updateWindowSize(delta);
58 }
59
60 @Override
61 public void onDataReceived(ISession session, IStream stream, DataInfo dataInfo)
62 {
63
64 }
65
66 @Override
67 public void onDataConsumed(ISession session, IStream stream, DataInfo dataInfo, int delta)
68 {
69
70
71
72
73
74
75
76
77 int length = dataInfo.length();
78 if (dataInfo.consumed() == length && !stream.isClosed() && length > 0)
79 {
80 WindowUpdateFrame windowUpdateFrame = new WindowUpdateFrame(session.getVersion(), stream.getId(), length);
81 session.control(stream, windowUpdateFrame, 0, TimeUnit.MILLISECONDS, null, null);
82 }
83 }
84 }