Example usage for javax.jms Connection close

List of usage examples for javax.jms Connection close

Introduction

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

Prototype


void close() throws JMSException;

Source Link

Document

Closes the connection.

Usage

From source file:nl.nn.adapterframework.extensions.tibco.TibcoUtils.java

public static long getQueueMessageCount(String provUrl, String authAlias, String userName, String password,
        String queueName, String messageSelector) throws JMSException {
    Connection connection = null;
    Session jSession = null;//from   ww  w.  j  a  v  a  2s  .c  o  m
    try {
        connection = getConnection(provUrl, authAlias, userName, password);
        jSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
        return getQueueMessageCount(jSession, queueName, messageSelector);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                log.warn("Exception on closing connection", e);
            }
        }
    }
}

From source file:nl.nn.adapterframework.extensions.tibco.TibcoUtils.java

/**
 * return -1: no message found//from   w w  w  . j a  v  a  2  s .  co  m
 * return -2: message found, but not of type Message.
 */
public static long getQueueFirstMessageAge(String provUrl, String authAlias, String userName, String password,
        String queueName, String messageSelector) throws JMSException {
    Connection connection = null;
    Session jSession = null;
    try {
        connection = getConnection(provUrl, authAlias, userName, password);
        jSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
        return getQueueFirstMessageAge(jSession, queueName, messageSelector);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                log.warn("Exception on closing connection", e);
            }
        }
    }
}

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   w w  w .j  ava  2  s.c o m
 * (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.fusesource.stompjms.JmsTestSupport.java

protected void safeClose(Connection c) {
    try {
        c.close();
    } catch (Throwable e) {
    }
}

From source file:org.apache.synapse.transport.jms.JMSUtils.java

/**
 * Create a JMS Queue using the given connection with the JNDI destination name, and return the
 * JMS Destination name of the created queue
 *
 * @param con the JMS Connection to be used
 * @param destinationJNDIName the JNDI name of the Queue to be created
 * @return the JMS Destination name of the created Queue
 * @throws JMSException on error/*from  w  w  w.  ja v a  2  s  . c  o  m*/
 */
public static String createJMSQueue(Connection con, String destinationJNDIName) throws JMSException {
    try {
        QueueSession session = ((QueueConnection) con).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue(destinationJNDIName);
        log.info("JMS Queue with JNDI name : " + destinationJNDIName + " created");
        return queue.getQueueName();

    } finally {
        try {
            con.close();
        } catch (JMSException ignore) {
        }
    }
}

From source file:org.apache.synapse.transport.jms.JMSUtils.java

/**
 * Create a JMS Topic using the given connection with the JNDI destination name, and return the
 * JMS Destination name of the created queue
 *
 * @param con the JMS Connection to be used
 * @param destinationJNDIName the JNDI name of the Topic to be created
 * @return the JMS Destination name of the created Topic
 * @throws JMSException on error//from ww w  . ja  v  a 2s  . co  m
 */
public static String createJMSTopic(Connection con, String destinationJNDIName) throws JMSException {
    try {
        TopicSession session = ((TopicConnection) con).createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(destinationJNDIName);
        log.info("JMS Topic with JNDI name : " + destinationJNDIName + " created");
        return topic.getTopicName();

    } finally {
        try {
            con.close();
        } catch (JMSException ignore) {
        }
    }
}

From source file:org.fusesource.stompjms.JmsTestSupport.java

protected void tearDown() throws Exception {
    for (Iterator iter = connections.iterator(); iter.hasNext();) {
        Connection conn = (Connection) iter.next();
        try {//from  w  w w  . ja  v a  2 s. com
            conn.close();
        } catch (Throwable e) {
        }
        iter.remove();
    }
    ServiceControl.stop(broker, "Stopped Apollo Broker");
    broker.stop();
    super.tearDown();
}

From source file:se.inera.intyg.intygstjanst.web.service.impl.HealthCheckServiceImpl.java

private boolean checkJmsConnection() {
    Connection connection = null;
    try {/*from   ww w  .j  a v  a2s.  c om*/
        connection = connectionFactory.createConnection();
        connection.close();
    } catch (JMSException e) {
        LOGGER.error("checkJMS failed with exception: " + e.getMessage());
        return false;
    }
    return true;
}

From source file:org.apache.camel.component.sjms.jms.ConnectionFactoryResource.java

@Override
public void destroyObject(Connection connection) throws Exception {
    if (connection != null) {
        connection.stop();/*from w  w w. j  a va2  s.c  om*/
        connection.close();
    }

}

From source file:se.inera.intyg.rehabstod.service.monitoring.HealthCheckServiceImpl.java

private boolean checkJmsConnection() {
    try {// w  w  w .jav  a 2 s  .c  om
        Connection connection = connectionFactory.createConnection();
        connection.close();
    } catch (JMSException e) {
        LOG.error("checkJmsConnection failed with JMSException: {}", e);
        return false;
    } catch (Exception e) {
        LOG.error(String.format("checkJmsConnection failed with exception of class: %s. Message: %s",
                e.getClass().getName(), e.getMessage()), e);
        return false;
    }
    return true;
}