本文整理汇总了Java中org.springframework.jms.support.JmsUtils.closeConnection方法的典型用法代码示例。如果您正苦于以下问题:Java JmsUtils.closeConnection方法的具体用法?Java JmsUtils.closeConnection怎么用?Java JmsUtils.closeConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.jms.support.JmsUtils
的用法示例。
在下文中一共展示了JmsUtils.closeConnection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConnectionOnStartup
import org.springframework.jms.support.JmsUtils; //导入方法依赖的package包/类
/**
* Pre tests the connection before starting the listening.
* <p/>
* In case of connection failure the exception is thrown which prevents Camel from starting.
*
* @throws FailedToCreateProducerException is thrown if testing the connection failed
*/
protected void testConnectionOnStartup() throws FailedToCreateProducerException {
try {
CamelJmsTemplate template = (CamelJmsTemplate) getInOnlyTemplate();
if (log.isDebugEnabled()) {
log.debug("Testing JMS Connection on startup for destination: " + template.getDefaultDestinationName());
}
Connection conn = template.getConnectionFactory().createConnection();
JmsUtils.closeConnection(conn);
log.debug("Successfully tested JMS Connection on startup for destination: " + template.getDefaultDestinationName());
} catch (Exception e) {
throw new FailedToCreateProducerException(getEndpoint(), e);
}
}
示例2: createSharedConnection
import org.springframework.jms.support.JmsUtils; //导入方法依赖的package包/类
/**
* Create a shared Connection for this container.
* <p>The default implementation creates a standard Connection
* and prepares it through {@link #prepareSharedConnection}.
* @return the prepared Connection
* @throws JMSException if the creation failed
*/
protected Connection createSharedConnection() throws JMSException {
Connection con = createConnection();
try {
prepareSharedConnection(con);
return con;
}
catch (JMSException ex) {
JmsUtils.closeConnection(con);
throw ex;
}
}
示例3: doInvokeListener
import org.springframework.jms.support.JmsUtils; //导入方法依赖的package包/类
/**
* Invoke the specified listener as Spring SessionAwareMessageListener,
* exposing a new JMS Session (potentially with its own transaction)
* to the listener if demanded.
* @param listener the Spring SessionAwareMessageListener to invoke
* @param session the JMS Session to operate on
* @param message the received JMS Message
* @throws JMSException if thrown by JMS API methods
* @see SessionAwareMessageListener
* @see #setExposeListenerSession
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void doInvokeListener(SessionAwareMessageListener listener, Session session, Message message)
throws JMSException {
Connection conToClose = null;
Session sessionToClose = null;
try {
Session sessionToUse = session;
if (!isExposeListenerSession()) {
// We need to expose a separate Session.
conToClose = createConnection();
sessionToClose = createSession(conToClose);
sessionToUse = sessionToClose;
}
// Actually invoke the message listener...
listener.onMessage(message, sessionToUse);
// Clean up specially exposed Session, if any.
if (sessionToUse != session) {
if (sessionToUse.getTransacted() && isSessionLocallyTransacted(sessionToUse)) {
// Transacted session created by this container -> commit.
JmsUtils.commitIfNecessary(sessionToUse);
}
}
}
finally {
JmsUtils.closeSession(sessionToClose);
JmsUtils.closeConnection(conToClose);
}
}
示例4: testConnectionOnStartup
import org.springframework.jms.support.JmsUtils; //导入方法依赖的package包/类
/**
* Pre tests the connection before starting the listening.
* <p/>
* In case of connection failure the exception is thrown which prevents Camel from starting.
*
* @throws FailedToCreateConsumerException is thrown if testing the connection failed
*/
protected void testConnectionOnStartup() throws FailedToCreateConsumerException {
try {
log.debug("Testing JMS Connection on startup for destination: {}", getDestinationName());
Connection con = listenerContainer.getConnectionFactory().createConnection();
JmsUtils.closeConnection(con);
log.debug("Successfully tested JMS Connection on startup for destination: {}", getDestinationName());
} catch (Exception e) {
String msg = "Cannot get JMS Connection on startup for destination " + getDestinationName();
throw new FailedToCreateConsumerException(getEndpoint(), msg, e);
}
}
示例5: closeJms
import org.springframework.jms.support.JmsUtils; //导入方法依赖的package包/类
private void closeJms() {
if (_connection != null) {
//[PLAT-1809] Need to close all of these
JmsUtils.closeMessageProducer(_producer);
JmsUtils.closeSession(_session);
JmsUtils.closeConnection(_connection);
_connection = null;
_session = null;
_producer = null;
}
}
示例6: refreshConnectionUntilSuccessful
import org.springframework.jms.support.JmsUtils; //导入方法依赖的package包/类
/**
* Refresh the underlying Connection, not returning before an attempt has been
* successful. Called in case of a shared Connection as well as without shared
* Connection, so either needs to operate on the shared Connection or on a
* temporary Connection that just gets established for validation purposes.
* <p>The default implementation retries until it successfully established a
* Connection, for as long as this message listener container is running.
* Applies the specified recovery interval between retries.
* @see #setRecoveryInterval
* @see #start()
* @see #stop()
*/
protected void refreshConnectionUntilSuccessful() {
while (isRunning()) {
try {
if (sharedConnectionEnabled()) {
refreshSharedConnection();
}
else {
Connection con = createConnection();
JmsUtils.closeConnection(con);
}
logger.info("Successfully refreshed JMS Connection");
break;
}
catch (Exception ex) {
if (ex instanceof JMSException) {
invokeExceptionListener((JMSException) ex);
}
StringBuilder msg = new StringBuilder();
msg.append("Could not refresh JMS Connection for destination '");
msg.append(getDestinationDescription()).append("' - retrying in ");
msg.append(this.recoveryInterval).append(" ms. Cause: ");
msg.append(ex instanceof JMSException ? JmsUtils.buildExceptionMessage((JMSException) ex) : ex.getMessage());
if (logger.isDebugEnabled()) {
logger.error(msg, ex);
}
else {
logger.error(msg);
}
}
sleepInbetweenRecoveryAttempts();
}
}