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 import org.eclipse.jetty.util.Callback;
27
28 public class SPDYv3FlowControlStrategy implements FlowControlStrategy
29 {
30 private volatile int windowSize;
31
32 @Override
33 public int getWindowSize(ISession session)
34 {
35 return windowSize;
36 }
37
38 @Override
39 public void setWindowSize(ISession session, int windowSize)
40 {
41 int prevWindowSize = this.windowSize;
42 this.windowSize = windowSize;
43 for (Stream stream : session.getStreams())
44 ((IStream)stream).updateWindowSize(windowSize - prevWindowSize);
45 }
46
47 @Override
48 public void onNewStream(ISession session, IStream stream)
49 {
50 stream.updateWindowSize(windowSize);
51 }
52
53 @Override
54 public void onWindowUpdate(ISession session, IStream stream, int delta)
55 {
56 if (stream != null)
57 stream.updateWindowSize(delta);
58 }
59
60 @Override
61 public void updateWindow(ISession session, IStream stream, int delta)
62 {
63 stream.updateWindowSize(delta);
64 }
65
66 @Override
67 public void onDataReceived(ISession session, IStream stream, DataInfo dataInfo)
68 {
69
70 }
71
72 @Override
73 public void onDataConsumed(ISession session, IStream stream, DataInfo dataInfo, int delta)
74 {
75
76
77
78
79
80
81
82
83 int length = dataInfo.length();
84 if (dataInfo.consumed() == length && !stream.isClosed() && length > 0)
85 {
86 WindowUpdateFrame windowUpdateFrame = new WindowUpdateFrame(session.getVersion(), stream.getId(), length);
87 session.control(stream, windowUpdateFrame, 0, TimeUnit.MILLISECONDS, new Callback.Adapter());
88 }
89 }
90 }