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