Example usage for org.springframework.messaging.tcp TcpConnection onReadInactivity

List of usage examples for org.springframework.messaging.tcp TcpConnection onReadInactivity

Introduction

In this page you can find the example usage for org.springframework.messaging.tcp TcpConnection onReadInactivity.

Prototype

void onReadInactivity(Runnable runnable, long duration);

Source Link

Document

Register a task to invoke after a period of read inactivity.

Usage

From source file:org.springframework.messaging.simp.stomp.DefaultStompSession.java

private void initHeartbeatTasks(StompHeaders connectedHeaders) {
    long[] connect = this.connectHeaders.getHeartbeat();
    long[] connected = connectedHeaders.getHeartbeat();
    if (connect == null || connected == null) {
        return;//from  w  w  w.  j av  a 2s  .  c  om
    }
    TcpConnection<byte[]> con = this.connection;
    Assert.state(con != null, "No TcpConnection available");
    if (connect[0] > 0 && connected[1] > 0) {
        long interval = Math.max(connect[0], connected[1]);
        con.onWriteInactivity(new WriteInactivityTask(), interval);
    }
    if (connect[1] > 0 && connected[0] > 0) {
        long interval = Math.max(connect[1], connected[0]) * HEARTBEAT_MULTIPLIER;
        con.onReadInactivity(new ReadInactivityTask(), interval);
    }
}