42 final AtomicInteger received = new AtomicInteger(0); 43 44 WindowUpdateSender(Http2Connection connection) { 45 this(connection, connection.clientSettings.getParameter(SettingsFrame.INITIAL_WINDOW_SIZE)); 46 } 47 48 WindowUpdateSender(Http2Connection connection, int initWindowSize) { 49 this(connection, connection.getMaxReceiveFrameSize(), initWindowSize); 50 } 51 52 WindowUpdateSender(Http2Connection connection, int maxFrameSize, int initWindowSize) { 53 this.connection = connection; 54 int v0 = Math.max(0, initWindowSize - maxFrameSize); 55 int v1 = (initWindowSize + (maxFrameSize - 1)) / maxFrameSize; 56 v1 = v1 * maxFrameSize / 2; 57 // send WindowUpdate heuristic: 58 // - we got data near half of window size 59 // or 60 // - remaining window size reached max frame size. 61 limit = Math.min(v0, v1); 62 } 63 64 abstract int getStreamId(); 65 66 void update(int delta) { 67 debug.log(Level.DEBUG, "update: %d", delta); 68 if (received.addAndGet(delta) > limit) { 69 synchronized (this) { 70 int tosend = received.get(); 71 if( tosend > limit) { 72 received.getAndAdd(-tosend); 73 sendWindowUpdate(tosend); 74 } 75 } 76 } 77 } 78 79 void sendWindowUpdate(int delta) { 80 debug.log(Level.DEBUG, "sending window update: %d", delta); 81 connection.sendUnorderedFrame(new WindowUpdateFrame(getStreamId(), delta)); | 42 final AtomicInteger received = new AtomicInteger(0); 43 44 WindowUpdateSender(Http2Connection connection) { 45 this(connection, connection.clientSettings.getParameter(SettingsFrame.INITIAL_WINDOW_SIZE)); 46 } 47 48 WindowUpdateSender(Http2Connection connection, int initWindowSize) { 49 this(connection, connection.getMaxReceiveFrameSize(), initWindowSize); 50 } 51 52 WindowUpdateSender(Http2Connection connection, int maxFrameSize, int initWindowSize) { 53 this.connection = connection; 54 int v0 = Math.max(0, initWindowSize - maxFrameSize); 55 int v1 = (initWindowSize + (maxFrameSize - 1)) / maxFrameSize; 56 v1 = v1 * maxFrameSize / 2; 57 // send WindowUpdate heuristic: 58 // - we got data near half of window size 59 // or 60 // - remaining window size reached max frame size. 61 limit = Math.min(v0, v1); 62 debug.log(Level.DEBUG, "maxFrameSize=%d, initWindowSize=%d, limit=%d", 63 maxFrameSize, initWindowSize, limit); 64 } 65 66 abstract int getStreamId(); 67 68 void update(int delta) { 69 debug.log(Level.DEBUG, "update: %d", delta); 70 if (received.addAndGet(delta) > limit) { 71 synchronized (this) { 72 int tosend = received.get(); 73 if( tosend > limit) { 74 received.getAndAdd(-tosend); 75 sendWindowUpdate(tosend); 76 } 77 } 78 } 79 } 80 81 void sendWindowUpdate(int delta) { 82 debug.log(Level.DEBUG, "sending window update: %d", delta); 83 connection.sendUnorderedFrame(new WindowUpdateFrame(getStreamId(), delta)); |