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:org.fusesource.stompjms.JmsTestSupport.java

protected void sendMessages(Destination destination, int count) throws Exception {
    ConnectionFactory factory = createConnectionFactory();
    Connection connection = factory.createConnection();
    connection.start();/*from   w w w  .  j a  v a  2s. com*/
    sendMessages(connection, destination, count);
    connection.close();
}

From source file:org.wso2.carbon.transport.jms.factory.PooledJMSConnectionFactory.java

/**
 * This is called when an connection object is invalidated.
 *
 * @param key                    The connection key
 * @param pooledConnectionObject The invalidated wrapped connection object.
 * @throws Exception Any exception thrown when closing a JMS connection will be thrown
 *///from  w  ww  .  j ava 2  s .  c  o  m
@Override
public void destroyObject(PooledConnectionKey key, PooledObject<Connection> pooledConnectionObject)
        throws Exception {
    Connection connection = pooledConnectionObject.getObject();

    connectionKeyMap.remove(connection);
    connection.close();
}

From source file:org.firstopen.singularity.util.JMSUtil.java

public static void deliverMessageToQueue(String host, String queueName, String xml) {
    log.debug("IntegrationMod.deliverMessageToQueue queueName = " + queueName + " and doc = " + xml);
    MessageProducer m_sender = null;//from  w  ww  .  j a  v a  2 s.  co  m
    Session m_session = null;
    Connection connection = null;

    char test = queueName.charAt(0);

    if (test == '/')
        queueName = queueName.substring(1);

    try {

        InitialContext context = JNDIUtil.getInitialContext(host);

        ConnectionFactory qcf = (ConnectionFactory) context.lookup("ConnectionFactory");

        Queue queue = (Queue) context.lookup("queue/" + queueName);

        connection = qcf.createConnection();

        m_session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        m_sender = m_session.createProducer(queue);

        TextMessage message = m_session.createTextMessage();

        log.debug("message value is -> " + xml);

        message.setText(xml);

        m_sender.send(message);

    } catch (Exception e) {
        log.error("IntegrationMod.deliverMessageToQueue() Exception = ", e);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                log.error("unable ot close JMS Connection", e);
            }
        }
    }
}

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

public boolean closeConnection(Connection connection, boolean forcefully) {
    try {//from  w w w  . j  ava  2  s .c o m
        if (this.cacheLevel < JMSConstants.CACHE_CONNECTION || forcefully) {
            connection.close();
        }
    } catch (JMSException e) {
        logger.error("JMS Exception while closing the connection.");
    }
    return false;
}

From source file:com.nesscomputing.jms.activemq.ServiceDiscoveryTransportFactoryTest.java

@Test
public void testDiscoveryUri() throws Exception {
    final ServiceInformation vmbrokerInfo = new ServiceInformation("vmbroker", null, UUID.randomUUID(),
            ImmutableMap.of("uri", "vm://disco-test-broker-" + uniqueId));

    final Config config = Config
            .getFixedConfig(ImmutableMap.of("ness.jms.connection-url", "srvc://vmbroker?discoveryId=%s"));

    Guice.createInjector(new AbstractModule() {
        @Override/*  w w  w.  ja  v a2  s  .  c  om*/
        protected void configure() {
            binder().requireExplicitBindings();
            binder().disableCircularProxies();

            install(new ConfigModule(config));
            install(new JmsModule(config, "test"));
            install(new DiscoveryJmsModule(config));

            bind(ReadOnlyDiscoveryClient.class).toInstance(
                    MockedReadOnlyDiscoveryClient.builder().addServiceInformation(vmbrokerInfo).build());
        }
    }).injectMembers(this);

    final ConnectionFactory directFactory = new ActiveMQConnectionFactory(
            "vm://disco-test-broker-" + uniqueId + "?broker.persistent=false");

    final Connection directConnection = directFactory.createConnection();
    directConnection.start();
    try {
        sendTestMessage(directConnection);
        consumeTestMessage();
    } finally {
        directConnection.stop();
        directConnection.close();
    }
}

From source file:sk.seges.test.jms.activemq.SimpleActiveMQQueueReceiveFailTest.java

@Test
public void testReceive() throws Exception {
    Connection connection = activeMQConnectionFactory.createConnection();
    connection.start();/*from  w  w w .  jav a 2  s  . co  m*/
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(activeMQTestQueueA);

    Message rawMessage = consumer.receive(1000);
    assertNull(rawMessage);
    connection.close();
}

From source file:org.wso2.carbon.event.output.adapter.jms.JMSEventAdapter.java

@Override
public void testConnect() throws TestConnectionNotSupportedException {

    try {/*from w  w w .j a  va 2 s.c o  m*/
        Hashtable<String, String> adaptorProperties = new Hashtable<String, String>();
        adaptorProperties.putAll(eventAdapterConfiguration.getStaticProperties());
        JMSConnectionFactory jmsConnectionFactory = new JMSConnectionFactory(adaptorProperties,
                eventAdapterConfiguration.getName(),
                adaptorProperties.get(JMSEventAdapterConstants.ADAPTER_JMS_DESTINATION), 1);
        Connection connection = jmsConnectionFactory.createConnection();
        connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        connection.close();
        jmsConnectionFactory.close();
    } catch (Exception e) {
        throw new OutputEventAdapterRuntimeException(e);
    }
}

From source file:org.apache.activemq.usecases.ConcurrentProducerDurableConsumerTest.java

private void startInactiveConsumers(ConnectionFactory factory, Destination destination) throws Exception {
    // create off line consumers
    startConsumers(factory, destination);
    for (Connection connection : connections) {
        connection.close();
    }//from   w  w  w  .ja  v  a2 s.c  om
    connections.clear();
    consumers.clear();
}

From source file:sk.seges.test.jms.multiple.QueueSendReceiveTest.java

@Test
public void testSend() throws Exception {
    Connection connection = testConnectionFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(testQueueA);
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
    TextMessage message = session.createTextMessage("test text");
    producer.send(message);//  ww w  . j a  v  a 2s . c  o  m
    connection.close();
}

From source file:org.apache.activemq.usecases.ConcurrentProducerDurableConsumerTest.java

@Override
protected void tearDown() throws Exception {
    for (Iterator<Connection> iter = connections.iterator(); iter.hasNext();) {
        Connection conn = iter.next();
        try {//from w ww . j  av a  2s . c  o m
            conn.close();
        } catch (Throwable e) {
        }
    }
    allMessagesList.flushMessages();
    consumers.clear();
    super.tearDown();
}