MCPcopy Index your code
hub / github.com/ccxt/ccxt / pingLoop

Method pingLoop

java/lib/src/main/java/io/github/ccxt/ws/WsClient.java:496–547  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

494 // ─── Ping/Pong keep-alive ───
495
496 private void pingLoop() {
497 try {
498 Thread.sleep(this.keepAlive);
499 long now = System.currentTimeMillis();
500 if (this.lastPong == 0) {
501 this.lastPong = now;
502 }
503
504 while (this.keepAlive > 0 && this.isConnected) {
505 now = System.currentTimeMillis();
506 if (this.lastPong + this.keepAlive * this.maxPingPongMisses < now) {
507 this.onError(new RuntimeException(
508 getFormattedDate() + "Connection to " + this.url + " lost, no pong within " + this.keepAlive + "ms"));
509 break;
510 }
511
512 if (this.pingCallback != null) {
513 try {
514 Object pingResult = this.pingCallback.apply(this);
515 if (pingResult != null) {
516 this.send(pingResult);
517 } else {
518 // callback was not overriden we still need to send the frame
519 if (this.channel != null && this.channel.isActive()) {
520 if (this.verbose) {
521 System.out.println(getFormattedDate() + "Ping Frame: " + this.lastPong);
522 }
523 this.channel.writeAndFlush(new PingWebSocketFrame());
524 }
525 }
526 } catch (Exception pingEx) {
527 this.onError(pingEx);
528 break;
529 }
530 } else if (this.channel != null && this.channel.isActive()) {
531 if (this.verbose) {
532 System.out.println(getFormattedDate() + "Ping Frame: " + this.lastPong);
533 }
534 this.channel.writeAndFlush(new PingWebSocketFrame());
535 }
536
537 Thread.sleep(this.keepAlive);
538 }
539 } catch (InterruptedException e) {
540 Thread.currentThread().interrupt();
541 } catch (Exception e) {
542 if (this.verbose) {
543 System.err.println(getFormattedDate() + "PingLoop error: " + e.getMessage());
544 }
545 this.onError(e);
546 }
547 }
548
549 // ─── Send ───
550

Callers

nothing calls this directly

Calls 4

onErrorMethod · 0.95
getFormattedDateMethod · 0.95
sendMethod · 0.95
sleepMethod · 0.45

Tested by

no test coverage detected