Example usage for org.springframework.integration.stomp.event StompSessionConnectedEvent StompSessionConnectedEvent

List of usage examples for org.springframework.integration.stomp.event StompSessionConnectedEvent StompSessionConnectedEvent

Introduction

In this page you can find the example usage for org.springframework.integration.stomp.event StompSessionConnectedEvent StompSessionConnectedEvent.

Prototype

public StompSessionConnectedEvent(Object source) 

Source Link

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.");
        }//from   w  w w  .  j  av  a 2s.c om
        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();
    }
}