Example usage for org.springframework.messaging.simp.stomp StompSession setAutoReceipt

List of usage examples for org.springframework.messaging.simp.stomp StompSession setAutoReceipt

Introduction

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

Prototype

void setAutoReceipt(boolean enabled);

Source Link

Document

When enabled, a receipt header is automatically added to future send and subscribe operations on this session, which causes the server to return a RECEIPT.

Usage

From source file:org.springframework.integration.stomp.AbstractStompSessionManager.java

private synchronized void connect() {
    if (this.connecting || this.connected) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("Aborting connect; another thread is connecting.");
        }// w  ww .  ja va2  s.c  o m
        return;
    }
    final int epoch = this.epoch.get();
    this.connecting = true;
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Connecting " + this);
    }
    try {
        this.stompSessionListenableFuture = doConnect(this.compositeStompSessionHandler);
    } catch (Exception e) {
        if (epoch == this.epoch.get()) {
            scheduleReconnect(e);
        } else {
            this.logger.error("STOMP doConnect() error for " + this, e);
        }
        return;
    }
    final CountDownLatch latch = new CountDownLatch(1);
    this.stompSessionListenableFuture.addCallback(new ListenableFutureCallback<StompSession>() {

        @Override
        public void onFailure(Throwable e) {
            if (AbstractStompSessionManager.this.logger.isDebugEnabled()) {
                AbstractStompSessionManager.this.logger.debug("onFailure", e);
            }
            latch.countDown();
            if (epoch == AbstractStompSessionManager.this.epoch.get()) {
                scheduleReconnect(e);
            }
        }

        @Override
        public void onSuccess(StompSession stompSession) {
            if (AbstractStompSessionManager.this.logger.isDebugEnabled()) {
                AbstractStompSessionManager.this.logger.debug("onSuccess");
            }
            AbstractStompSessionManager.this.connected = true;
            AbstractStompSessionManager.this.connecting = false;
            stompSession.setAutoReceipt(isAutoReceiptEnabled());
            if (AbstractStompSessionManager.this.applicationEventPublisher != null) {
                AbstractStompSessionManager.this.applicationEventPublisher
                        .publishEvent(new StompSessionConnectedEvent(this));
            }
            AbstractStompSessionManager.this.reconnectFuture = null;
            latch.countDown();
        }

    });
    try {
        if (!latch.await(10, TimeUnit.SECONDS)) {
            this.logger.error("No response to connection attempt");
            if (epoch == this.epoch.get()) {
                scheduleReconnect(null);
            }
        }
    } catch (InterruptedException e1) {
        this.logger.error("Interrupted while waiting for connection attempt");
        Thread.currentThread().interrupt();
    }
}