List of usage examples for javax.jms Session close
void close() throws JMSException;
From source file:org.apache.flume.source.jms.TestIntegrationActiveMQ.java
private void putTopic(List<String> events) throws Exception { ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME, PASSWORD, BROKER_BIND_URL); Connection connection = factory.createConnection(); connection.start();/* w w w . java 2 s. c o m*/ Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createTopic(DESTINATION_NAME); MessageProducer producer = session.createProducer(destination); for (String event : events) { TextMessage message = session.createTextMessage(); message.setText(event); producer.send(message); } session.commit(); session.close(); connection.close(); }
From source file:org.apache.james.queue.jms.JMSMailQueue.java
protected static void closeSession(Session session) { if (session != null) { try {/*from w w w . ja v a2s . c om*/ session.close(); } catch (JMSException e) { // Ignore. See JAMES-2509 } } }
From source file:org.apache.servicemix.samples.bridge.BridgeTest.java
public void testSimpleCall() throws Exception { ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Destination outQueue = new ActiveMQQueue("bridge.output"); Connection connection = factory.createConnection(); connection.start();/*from ww w. ja v a 2 s. co m*/ Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); MessageConsumer createConsumer = session.createConsumer(outQueue); createConsumer.setMessageListener(new MessageListener() { public void onMessage(Message arg0) { BridgeTest.recieved = true; ActiveMQTextMessage msg = (ActiveMQTextMessage) arg0; assertNotNull(msg); } }); HttpClient client = new HttpClient(); PostMethod post = new PostMethod(url); post.setRequestBody(new FileInputStream("src/test/resources/request.xml")); int executeMethod = client.executeMethod(post); assertEquals(202, executeMethod); int maxTry = 100; while (!recieved || maxTry == 0) { Thread.sleep(200); maxTry--; } session.close(); connection.close(); }
From source file:org.apache.servicemix.wsn.jms.JmsPublisher.java
@Override public void notify(NotificationMessageHolderType messageHolder, String mes) { Session session = null; try {/*ww w .j a v a2s. c om*/ Topic topic = topicConverter.toActiveMQTopic(messageHolder.getTopic()); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(topic); Message message = session.createTextMessage(mes); producer.send(message); } catch (JMSException e) { log.warn("Error dispatching message", e); } catch (InvalidTopicException e) { log.warn("Error dispatching message", e); } finally { if (session != null) { try { session.close(); } catch (JMSException e) { log.debug("Error closing session", e); } } } }
From source file:org.apache.synapse.message.store.impl.jms.JmsStore.java
/** * Cleans up the JMS Connection and Session associated with a JMS client. * * @param connection JMS Connection// w ww. ja va 2s .c o m * @param session JMS Session associated with the given connection * @param error is this method called upon an error * @return {@code true} if the cleanup is successful. {@code false} otherwise. */ public boolean cleanup(Connection connection, Session session, boolean error) { if (connection == null && error) { return true; } try { if (session != null) { session.close(); } } catch (JMSException e) { return false; } try { if (connection != null && error) { connection.close(); } } catch (JMSException e) { return false; } return true; }
From source file:org.apache.synapse.transport.jms.JMSConnectionFactory.java
/** * Listen on the given destination from this connection factory. Used to * start listening on a destination associated with a newly deployed service * * @param destinationJNDIname the JMS destination to listen on *//*from w ww.j a v a 2 s . co m*/ public void startListeningOnDestination(String destinationJNDIname, String destinationType) { Session session = (Session) jmsSessions.get(destinationJNDIname); // if we already had a session open, close it first if (session != null) { try { session.close(); } catch (JMSException ignore) { } } try { session = JMSUtils.createSession(connection, false, Session.AUTO_ACKNOWLEDGE, destinationType); Destination destination = null; try { destination = (Destination) context.lookup(destinationJNDIname); } catch (NameNotFoundException e) { log.warn("Cannot find destination : " + destinationJNDIname + ". Creating a Queue"); destination = JMSUtils.createDestination(session, destinationJNDIname, destinationType); } MessageConsumer consumer = JMSUtils.createConsumer(session, destination); consumer.setMessageListener(jmsMessageReceiver); jmsSessions.put(destinationJNDIname, session); // catches NameNotFound and JMSExceptions and marks service as faulty } catch (Exception e) { if (session != null) { try { session.close(); } catch (JMSException ignore) { } } BaseUtils.markServiceAsFaulty((String) serviceJNDINameMapping.get(destinationJNDIname), "Error looking up JMS destination : " + destinationJNDIname, cfgCtx.getAxisConfiguration()); } }
From source file:org.apache.synapse.transport.jms.JMSConnectionFactory.java
/** * Stop listening on the given destination - for undeployment or stopping of services * closes the underlying Session opened to subscribe to the destination * * @param destinationJNDIname the JNDI name of the JMS destination *///w ww . j a v a 2 s .co m private void stoplisteningOnDestination(String destinationJNDIname) { Session session = (Session) jmsSessions.get(destinationJNDIname); if (session != null) { try { session.close(); } catch (JMSException ignore) { } } }
From source file:org.dhatim.routing.jms.activemq.ActiveMQProvider.java
private final void close(Connection conn, Session session) { try {/* w w w. j av a 2 s. c o m*/ if (conn != null) { conn.stop(); logger.debug("Stopping JMS Connection for connected session."); } } catch (Throwable e) { logger.debug("Failed to stop JMS connection.", e); conn = null; } try { if (session != null) { session.close(); logger.debug("Closing JMS Session."); } } catch (Throwable e) { logger.debug("Failed to close JMS session.", e); } finally { session = null; } try { if (conn != null) { conn.close(); logger.debug("Closing JMS Connection for connected session."); } } catch (Throwable e) { logger.debug("Failed to close JMS connection.", e); } finally { conn = null; } }
From source file:org.dhatim.routing.jms.JMSRouter.java
protected void close(final Session session) { if (session != null) { try {/*from w ww . jav a2 s .c o m*/ session.close(); } catch (JMSException e) { final String errorMsg = "JMSException while trying to close session"; logger.debug(errorMsg, e); } } }
From source file:org.eclipse.smila.connectivity.queue.worker.internal.task.impl.Send.java
/** * close session if not null, catching and logging possible exceptions. * /*from w ww .j a v a2 s .co m*/ * @param session * a JMS session */ private void closeQuietly(final Session session) { if (session != null) { try { session.close(); } catch (final Throwable e1) { _log.error("Unable to close session", e1); } } }