Example usage for javax.jms Connection stop

List of usage examples for javax.jms Connection stop

Introduction

In this page you can find the example usage for javax.jms Connection stop.

Prototype


void stop() throws JMSException;

Source Link

Document

Temporarily stops a connection's delivery of incoming messages.

Usage

From source file:org.springframework.jms.connection.ConnectionFactoryUtils.java

/**
 * Release the given Connection, stopping it (if necessary) and eventually closing it.
 * <p>Checks {@link SmartConnectionFactory#shouldStop}, if available.
 * This is essentially a more sophisticated version of
 * {@link org.springframework.jms.support.JmsUtils#closeConnection}.
 * @param con the Connection to release//from www  .  j  av a  2  s  .  c om
 * (if this is {@code null}, the call will be ignored)
 * @param cf the ConnectionFactory that the Connection was obtained from
 * (may be {@code null})
 * @param started whether the Connection might have been started by the application
 * @see SmartConnectionFactory#shouldStop
 * @see org.springframework.jms.support.JmsUtils#closeConnection
 */
public static void releaseConnection(@Nullable Connection con, @Nullable ConnectionFactory cf,
        boolean started) {
    if (con == null) {
        return;
    }
    if (started && cf instanceof SmartConnectionFactory && ((SmartConnectionFactory) cf).shouldStop(con)) {
        try {
            con.stop();
        } catch (Throwable ex) {
            logger.debug("Could not stop JMS Connection before closing it", ex);
        }
    }
    try {
        con.close();
    } catch (Throwable ex) {
        logger.debug("Could not close JMS Connection", ex);
    }
}

From source file:org.springframework.jms.connection.SingleConnectionFactory.java

/**
 * Close the given Connection.// w w  w .  ja  va 2 s. co m
 * @param con the Connection to close
 */
protected void closeConnection(Connection con) {
    if (logger.isDebugEnabled()) {
        logger.debug("Closing shared JMS Connection: " + con);
    }
    try {
        try {
            if (this.startedCount > 0) {
                con.stop();
            }
        } finally {
            con.close();
        }
    } catch (javax.jms.IllegalStateException ex) {
        logger.debug("Ignoring Connection state exception - assuming already closed: " + ex);
    } catch (Throwable ex) {
        logger.debug("Could not close shared JMS Connection", ex);
    }
}

From source file:org.springframework.jms.support.JmsUtils.java

/**
 * Close the given JMS Connection and ignore any thrown exception.
 * This is useful for typical {@code finally} blocks in manual JMS code.
 * @param con the JMS Connection to close (may be {@code null})
 * @param stop whether to call {@code stop()} before closing
 *//*from   w ww . j a v a2 s  .  c o  m*/
public static void closeConnection(@Nullable Connection con, boolean stop) {
    if (con != null) {
        try {
            if (stop) {
                try {
                    con.stop();
                } finally {
                    con.close();
                }
            } else {
                con.close();
            }
        } catch (javax.jms.IllegalStateException ex) {
            logger.debug("Ignoring Connection state exception - assuming already closed: " + ex);
        } catch (JMSException ex) {
            logger.debug("Could not close JMS Connection", ex);
        } catch (Throwable ex) {
            // We don't trust the JMS provider: It might throw RuntimeException or Error.
            logger.debug("Unexpected exception on closing JMS Connection", ex);
        }
    }
}

From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.factory.JMSConnectionFactory.java

public void stop(Connection connection) {
    try {//from w  w w  .j a v  a 2  s .  com
        connection.stop();
    } catch (JMSException e) {
        logger.error("JMS Exception while stopping connection for factory '" + this.connectionFactoryString
                + "' " + e.getMessage(), e);
    }
}