/** * Get the XAResource for the connection. * * @return The XAResource for the connection. * @throws ResourceException XA transaction not supported */ @Override public XAResource getXAResource() throws ResourceException { if (logger.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("getXAResource()"); } // // Spec says a mc must always return the same XA resource, // so we cache it. // if (xaResource == null) { ClientSessionInternal csi = (ClientSessionInternal) xaSession.getXAResource(); ActiveMQRAXAResource activeMQRAXAResource = new ActiveMQRAXAResource(this, xaSession.getXAResource()); Map<String, Object> xaResourceProperties = new HashMap<>(); xaResourceProperties.put(ActiveMQXAResourceWrapper.ACTIVEMQ_JNDI_NAME, ra.getJndiName()); xaResourceProperties.put(ActiveMQXAResourceWrapper.ACTIVEMQ_NODE_ID, csi.getNodeId()); xaResourceProperties.put(ActiveMQXAResourceWrapper.ACTIVEMQ_PRODUCT_NAME, ActiveMQResourceAdapter.PRODUCT_NAME); xaResourceProperties.put(ActiveMQXAResourceWrapper.ACTIVEMQ_PRODUCT_VERSION, VersionLoader.getVersion().getFullVersion()); xaResource = ServiceUtils.wrapXAResource(activeMQRAXAResource, xaResourceProperties); } if (logger.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("XAResource=" + xaResource); } return xaResource; }
/** * Get the XAResource for the connection. * * @return The XAResource for the connection. * @throws ResourceException XA transaction not supported */ @Override public XAResource getXAResource() throws ResourceException { if (logger.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("getXAResource()"); } // // Spec says a mc must always return the same XA resource, // so we cache it. // if (xaResource == null) { ClientSessionInternal csi = (ClientSessionInternal) xaSession.getXAResource(); ActiveMQRAXAResource activeMQRAXAResource = new ActiveMQRAXAResource(this, xaSession.getXAResource()); Map<String, Object> xaResourceProperties = new HashMap<>(); xaResourceProperties.put(ActiveMQXAResourceWrapper.ACTIVEMQ_JNDI_NAME, ra.getJndiName()); xaResourceProperties.put(ActiveMQXAResourceWrapper.ACTIVEMQ_NODE_ID, csi.getNodeId()); xaResourceProperties.put(ActiveMQXAResourceWrapper.ACTIVEMQ_PRODUCT_NAME, ActiveMQResourceAdapter.PRODUCT_NAME); xaResourceProperties.put(ActiveMQXAResourceWrapper.ACTIVEMQ_PRODUCT_VERSION, VersionLoader.getVersion().getFullVersion()); xaResource = ServiceUtils.wrapXAResource(activeMQRAXAResource, xaResourceProperties); } if (logger.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("XAResource=" + xaResource); } return xaResource; }
@Test public void testIsSameRM() throws Exception { try (ServerLocator locator = createNettyNonHALocator(); ServerLocator locator2 = createNettyNonHALocator()) { ClientSessionFactory nettyFactory = createSessionFactory(locator); ClientSessionFactory nettyFactory2 = createSessionFactory(locator2); ClientSession session1 = nettyFactory.createSession(true, false, false); ClientSession session2 = nettyFactory2.createSession(true, false, false); assertTrue(session1.isSameRM(session2)); ActiveMQRAXAResource activeMQRAXAResource = new ActiveMQRAXAResource(null, session2); assertTrue(session1.isSameRM(activeMQRAXAResource)); } }