Example usage for org.springframework.messaging.simp.stomp StompHeaders getHeartbeat

List of usage examples for org.springframework.messaging.simp.stomp StompHeaders getHeartbeat

Introduction

In this page you can find the example usage for org.springframework.messaging.simp.stomp StompHeaders getHeartbeat.

Prototype

@Nullable
public long[] getHeartbeat() 

Source Link

Document

Get the heartbeat header.

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;// w  ww . ja  v a  2s  .c  o  m
    }
    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);
    }
}

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

/**
 * Further initialize the StompHeaders, for example setting the heart-beat
 * header if necessary.//from  ww w  . j  a va 2  s  .  c o  m
 * @param connectHeaders the headers to modify
 * @return the modified headers
 */
protected StompHeaders processConnectHeaders(StompHeaders connectHeaders) {
    connectHeaders = (connectHeaders != null ? connectHeaders : new StompHeaders());
    if (connectHeaders.getHeartbeat() == null) {
        connectHeaders.setHeartbeat(getDefaultHeartbeat());
    }
    return connectHeaders;
}