Example usage for javax.jms QueueConnectionFactory createConnection

List of usage examples for javax.jms QueueConnectionFactory createConnection

Introduction

In this page you can find the example usage for javax.jms QueueConnectionFactory createConnection.

Prototype


Connection createConnection(String userName, String password) throws JMSException;

Source Link

Document

Creates a connection with the specified user identity.

Usage

From source file:org.apache.synapse.message.store.impl.jms.JmsStore.java

/**
 * Creates a new JMS Connection.//from ww  w .j a  va  2 s. c  o  m
 *
 * @return A connection to the JMS Queue used as the store of this message store.
 * @throws JMSException
 */
public Connection newConnection() throws JMSException {
    Connection connection;
    if (connectionFactory == null) {
        logger.error(nameString() + ". Could not create a new connection to the broker."
                + " Initial Context Factory:[" + parameters.get(NAMING_FACTORY_INITIAL) + "]; Provider URL:["
                + parameters.get(PROVIDER_URL) + "]; Connection Factory:[null].");
        return null;
    }
    if (isVersion11) {
        if (userName != null && password != null) {
            connection = connectionFactory.createConnection(userName, password);
        } else {
            connection = connectionFactory.createConnection();
        }
    } else {
        QueueConnectionFactory connectionFactory;
        connectionFactory = (QueueConnectionFactory) this.connectionFactory;
        if (userName != null && password != null) {
            connection = connectionFactory.createQueueConnection(userName, password);
        } else {
            connection = connectionFactory.createQueueConnection();
        }
    }
    connection.start();
    if (logger.isDebugEnabled()) {
        logger.debug(nameString() + ". Created JMS Connection.");
    }
    return connection;
}