src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/WindowUpdateSender.java
branchhttp-client-branch
changeset 55763 634d8e14c172
parent 47216 71c04702a3d5
child 55818 725576a6821e
equal deleted inserted replaced
55762:e947a3a50a95 55763:634d8e14c172
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 package jdk.incubator.http;
    25 package jdk.incubator.http;
    26 
    26 
       
    27 import java.lang.System.Logger.Level;
    27 import jdk.incubator.http.internal.frame.SettingsFrame;
    28 import jdk.incubator.http.internal.frame.SettingsFrame;
    28 import jdk.incubator.http.internal.frame.WindowUpdateFrame;
    29 import jdk.incubator.http.internal.frame.WindowUpdateFrame;
       
    30 import jdk.incubator.http.internal.common.Utils;
    29 
    31 
    30 import java.util.concurrent.atomic.AtomicInteger;
    32 import java.util.concurrent.atomic.AtomicInteger;
    31 
    33 
    32 abstract class WindowUpdateSender {
    34 abstract class WindowUpdateSender {
    33 
    35 
       
    36     final static boolean DEBUG = Utils.DEBUG;
       
    37     final System.Logger debug =
       
    38             Utils.getDebugLogger(this::dbgString, DEBUG);
    34 
    39 
    35     final int limit;
    40     final int limit;
    36     final Http2Connection connection;
    41     final Http2Connection connection;
    37     final AtomicInteger received = new AtomicInteger(0);
    42     final AtomicInteger received = new AtomicInteger(0);
    38 
    43 
    57     }
    62     }
    58 
    63 
    59     abstract int getStreamId();
    64     abstract int getStreamId();
    60 
    65 
    61     void update(int delta) {
    66     void update(int delta) {
       
    67         debug.log(Level.DEBUG, "update: %d", delta);
    62         if (received.addAndGet(delta) > limit) {
    68         if (received.addAndGet(delta) > limit) {
    63             synchronized (this) {
    69             synchronized (this) {
    64                 int tosend = received.get();
    70                 int tosend = received.get();
    65                 if( tosend > limit) {
    71                 if( tosend > limit) {
    66                     received.getAndAdd(-tosend);
    72                     received.getAndAdd(-tosend);
    69             }
    75             }
    70         }
    76         }
    71     }
    77     }
    72 
    78 
    73     void sendWindowUpdate(int delta) {
    79     void sendWindowUpdate(int delta) {
       
    80         debug.log(Level.DEBUG, "sending window update: %d", delta);
    74         connection.sendUnorderedFrame(new WindowUpdateFrame(getStreamId(), delta));
    81         connection.sendUnorderedFrame(new WindowUpdateFrame(getStreamId(), delta));
    75     }
    82     }
    76 
    83 
       
    84     String dbgString() {
       
    85         return "WindowUpdateSender(stream: " + getStreamId() + ")";
       
    86     }
    77 
    87 
    78 }
    88 }