src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/WindowUpdateSender.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
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 } |