Skip to content

Commit

Permalink
Merge pull request #184 from graben/jms
Browse files Browse the repository at this point in the history
Wrap XAResource to NamedXAResource retrieved from JMSContext
  • Loading branch information
geoand authored Jan 13, 2025
2 parents f5c700b + ab2a98d commit bda7da7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import jakarta.jms.Connection;

import org.messaginghub.pooled.jms.JmsPoolConnection;
import org.messaginghub.pooled.jms.JmsPoolXAConnectionFactory;
import org.messaginghub.pooled.jms.JmsPoolXAJMSContext;

public class JmsPoolNarayanaConnectionFactory extends JmsPoolXAConnectionFactory {

Expand All @@ -41,4 +43,9 @@ public void setName(String name) {
protected PooledNarayanaConnection createPooledConnection(Connection connection) {
return new PooledNarayanaConnection(connection, getTransactionManager(), getName());
}

@Override
protected JmsPoolXAJMSContext newPooledConnectionContext(JmsPoolConnection connection, int sessionMode) {
return new JmsPoolNaryanaJmsContext(connection, sessionMode, getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2020 Red Hat, Inc, and individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.snowdrop.boot.narayana.core.jms.pool;

import javax.transaction.xa.XAResource;

import org.messaginghub.pooled.jms.JmsPoolConnection;
import org.messaginghub.pooled.jms.JmsPoolXAJMSContext;

public class JmsPoolNaryanaJmsContext extends JmsPoolXAJMSContext {

private final String name;

public JmsPoolNaryanaJmsContext(JmsPoolConnection connection, int sessionMode, String name) {
super(connection, sessionMode);
this.name = name;
}

@Override
public XAResource getXAResource() {
XAResource xares = super.getXAResource();
if (this.name != null) {
xares = new NamedXAResource(xares, this.name);
}
return xares;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import jakarta.jms.Connection;
import jakarta.jms.JMSException;
import jakarta.jms.XASession;
import jakarta.transaction.TransactionManager;

import org.messaginghub.pooled.jms.JmsPoolSession;
Expand All @@ -37,7 +36,7 @@ public PooledNarayanaConnection(Connection connection, TransactionManager transa

@Override
protected XAResource createXaResource(JmsPoolSession session) throws JMSException {
XAResource xares = ((XASession) session.getInternalSession()).getXAResource();
XAResource xares = super.createXaResource(session);
if (this.name != null) {
xares = new NamedXAResource(xares, this.name);
}
Expand Down

0 comments on commit bda7da7

Please sign in to comment.