
org.jboss.narayana.jta.jms.SessionClosingSynchronization Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of narayana-jta Show documentation
Show all versions of narayana-jta Show documentation
Narayana: ArjunaJTA narayana-jta (jta uber jar)
/*
Copyright The Narayana Authors
SPDX-License-Identifier: Apache-2.0
*/
package org.jboss.narayana.jta.jms;
import com.arjuna.ats.jta.logging.jtaLogger;
import jakarta.jms.JMSException;
import jakarta.jms.Session;
import jakarta.transaction.Synchronization;
/**
* Synchronization to close JMS session at the end of the transaction.
*
* @author Gytis Trikleris
*/
public class SessionClosingSynchronization implements Synchronization {
private final AutoCloseable session;
/**
* @param session session to be closed.
*/
public SessionClosingSynchronization(AutoCloseable session) {
this.session = session;
}
@Override
public void beforeCompletion() {
// Nothing to do
}
/**
* Close the session no matter what the status of the transaction is.
*
* @param status the status of the completed transaction
*/
@Override
public void afterCompletion(int status) {
if (jtaLogger.logger.isTraceEnabled()) {
jtaLogger.logger.trace("Closing session " + session);
}
try {
session.close();
} catch (Exception e) {
jtaLogger.i18NLogger.warn_failed_to_close_jms_session(session.toString(), e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy