Skip to content

Commit 34f3d7e

Browse files
committed
Ensure that ping is delayed for at least 5 seconds
1 parent f814116 commit 34f3d7e

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/service/HeartbeatService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private void sendPing(ChannelActiveListener writeListener, StreamConnection stre
153153
if (!streamConn.isOpen()) return;
154154

155155
try {
156-
streamConn.getSinkChannel().write(ByteBuffer.wrap(WEBSOCKET_PING));
156+
((DelegatingStreamSinkConduit) streamConn.getSinkChannel().getConduit()).writeWithoutNotifying(ByteBuffer.wrap(WEBSOCKET_PING));
157157
streamConn.getSinkChannel().flush();
158158
} catch (IOException e) {
159159
// Ignore failure, keep trying as long as the stream connection is valid.

src/main/java/eu/openanalytics/containerproxy/util/ChannelActiveListener.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public class ChannelActiveListener implements Runnable {
2828

29-
long lastWrite = 0;
29+
private long lastWrite = 0;
3030

3131
@Override
3232
public void run() {
@@ -38,6 +38,12 @@ public void run() {
3838
*/
3939
public boolean isActive(long period) {
4040
long diff = System.currentTimeMillis() - lastWrite;
41+
42+
// make sure the period is at least 5 seconds
43+
// this ensures that when the socket is active, the ping is delayed for at least 5 seconds
44+
if (period < 5000) {
45+
period = 5000;
46+
}
4147

4248
if (diff <= period) {
4349
return true;

src/main/java/eu/openanalytics/containerproxy/util/DelegatingStreamSinkConduit.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ public int write(ByteBuffer src) throws IOException {
127127
return delegate.write(src);
128128
}
129129

130+
public int writeWithoutNotifying(ByteBuffer src) throws IOException {
131+
return delegate.write(src);
132+
}
133+
130134
@Override
131135
public long write(ByteBuffer[] srcs, int offs, int len) throws IOException {
132136
return delegate.write(srcs, offs, len);

0 commit comments

Comments
 (0)