View Javadoc

1   //========================================================================
2   //Copyright 2011-2012 Mort Bay Consulting Pty. Ltd.
3   //------------------------------------------------------------------------
4   //All rights reserved. This program and the accompanying materials
5   //are made available under the terms of the Eclipse Public License v1.0
6   //and Apache License v2.0 which accompanies this distribution.
7   //The Eclipse Public License is available at
8   //http://www.eclipse.org/legal/epl-v10.html
9   //The Apache License v2.0 is available at
10  //http://www.opensource.org/licenses/apache2.0.php
11  //You may elect to redistribute this code under either of these licenses.
12  //========================================================================
13  package org.eclipse.jetty.spdy;
14  
15  import org.eclipse.jetty.spdy.api.DataInfo;
16  
17  // TODO: add methods that tell how much written and whether we're TCP congested ?
18  public interface FlowControlStrategy
19  {
20      public int getWindowSize(ISession session);
21  
22      public void setWindowSize(ISession session, int windowSize);
23  
24      public void onNewStream(ISession session, IStream stream);
25  
26      public void onWindowUpdate(ISession session, IStream stream, int delta);
27  
28      public void updateWindow(ISession session, IStream stream, int delta);
29  
30      public void onDataReceived(ISession session, IStream stream, DataInfo dataInfo);
31  
32      public void onDataConsumed(ISession session, IStream stream, DataInfo dataInfo, int delta);
33  
34      public static class None implements FlowControlStrategy
35      {
36          private volatile int windowSize;
37  
38          public None()
39          {
40              this(65536);
41          }
42  
43          public None(int windowSize)
44          {
45              this.windowSize = windowSize;
46          }
47  
48          @Override
49          public int getWindowSize(ISession session)
50          {
51              return windowSize;
52          }
53  
54          @Override
55          public void setWindowSize(ISession session, int windowSize)
56          {
57              this.windowSize = windowSize;
58          }
59  
60          @Override
61          public void onNewStream(ISession session, IStream stream)
62          {
63              stream.updateWindowSize(windowSize);
64          }
65  
66          @Override
67          public void onWindowUpdate(ISession session, IStream stream, int delta)
68          {
69          }
70  
71          @Override
72          public void updateWindow(ISession session, IStream stream, int delta)
73          {
74          }
75  
76          @Override
77          public void onDataReceived(ISession session, IStream stream, DataInfo dataInfo)
78          {
79          }
80  
81          @Override
82          public void onDataConsumed(ISession session, IStream stream, DataInfo dataInfo, int delta)
83          {
84          }
85      }
86  }