public static ManagedConnection create( final Connection connection ) { if ( (connection instanceof XAQueueConnection) && (connection instanceof XATopicConnection)) { return new ManagedXAQueueTopicConnection(connection); } else if (connection instanceof XAQueueConnection) { return new ManagedXAQueueConnection((XAQueueConnection) connection); } else if (connection instanceof XATopicConnection) { return new ManagedXATopicConnection((XATopicConnection) connection); } else if ( (connection instanceof QueueConnection) && (connection instanceof TopicConnection)) { return new ManagedQueueTopicConnection(connection); } else if (connection instanceof QueueConnection) { return new ManagedQueueConnection((QueueConnection) connection); } else if (connection instanceof TopicConnection) { return new ManagedTopicConnection((TopicConnection) connection); } else { return new ManagedConnection(connection); } }
/** * Create JMS {@link XASession} instance on top of the provided {@link Connection} instance. * * @param xAConnection JMS Connection. * @return Session instance. * @throws JMSConnectorException Error when creating the XASession. */ public XASession createXASession(XAConnection xAConnection) throws JMSConnectorException { try { if (logger.isDebugEnabled()) { logger.debug("Creating a new JMS XASession on: " + this.connectionFactoryString); } if (JMSConstants.JMS_SPEC_VERSION_1_1.equals(jmsSpec) || JMSConstants.JMS_SPEC_VERSION_2_0 .equals(jmsSpec)) { return xAConnection.createXASession(); } else if (JMSConstants.JMSDestinationType.QUEUE.equals(this.destinationType)) { return ((XAQueueConnection) (xAConnection)).createXAQueueSession(); } else { return ((XATopicConnection) (xAConnection)).createXATopicSession(); } } catch (JMSException e) { throw new JMSConnectorException( "JMS Exception while obtaining session for factory " + connectionFactoryString, e); } }
private void assertConnectionType(Connection conn, String type) { if ("generic".equals(type) || "queue".equals(type) || "topic".equals(type)) { //generic Assert.assertFalse(conn instanceof XAConnection); Assert.assertTrue(conn instanceof QueueConnection); Assert.assertFalse(conn instanceof XAQueueConnection); Assert.assertTrue(conn instanceof TopicConnection); Assert.assertFalse(conn instanceof XATopicConnection); } else if ("xa".equals(type) || "xa-queue".equals(type) || "xa-topic".equals(type)) { Assert.assertTrue(conn instanceof XAConnection); Assert.assertTrue(conn instanceof QueueConnection); Assert.assertTrue(conn instanceof XAQueueConnection); Assert.assertTrue(conn instanceof TopicConnection); Assert.assertTrue(conn instanceof XATopicConnection); } else { Assert.fail("Unknown connection type: " + type); } }
/** * Create a XA queue connection * * @param userName The user name * @param password The password * @return The connection * @throws JMSException Thrown if the operation fails */ @Override public XAQueueConnection createXAQueueConnection(final String userName, final String password) throws JMSException { if (ActiveMQRAConnectionFactoryImpl.trace) { ActiveMQRALogger.LOGGER.trace("createXAQueueConnection(" + userName + ", ****)"); } ActiveMQRASessionFactoryImpl s = new ActiveMQRASessionFactoryImpl(mcf, cm, getResourceAdapter().getTM(), ActiveMQRAConnectionFactory.XA_QUEUE_CONNECTION); s.setUserName(userName); s.setPassword(password); validateUser(s); if (ActiveMQRAConnectionFactoryImpl.trace) { ActiveMQRALogger.LOGGER.trace("Created queue connection: " + s); } return s; }
@Test public void testSimpleMessageSendAndReceiveXA() throws Exception { Xid xid = new XidImpl("xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes()); XAQueueConnection queueConnection = qraConnectionFactory.createXAQueueConnection(); XASession s = queueConnection.createXASession(); XAResource resource = s.getXAResource(); resource.start(xid, XAResource.TMNOFLAGS); Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE); MessageProducer mp = s.createProducer(q); MessageConsumer consumer = s.createConsumer(q); Message message = s.createTextMessage("test"); mp.send(message); queueConnection.start(); TextMessage textMessage = (TextMessage) consumer.receiveNoWait(); assertNull(textMessage); resource.end(xid, XAResource.TMSUCCESS); resource.commit(xid, true); resource.start(xid, XAResource.TMNOFLAGS); textMessage = (TextMessage) consumer.receiveNoWait(); resource.end(xid, XAResource.TMSUCCESS); resource.commit(xid, true); assertNotNull(textMessage); assertEquals(textMessage.getText(), "test"); // When I wrote this call, this method was doing an infinite loop. // this is just to avoid such thing again textMessage.getJMSDeliveryTime(); }
@Test public void testOutgoingXAResourceWrapper() throws Exception { XAQueueConnection queueConnection = qraConnectionFactory.createXAQueueConnection(); XASession s = queueConnection.createXASession(); XAResource resource = s.getXAResource(); assertTrue(resource instanceof ActiveMQXAResourceWrapper); ActiveMQXAResourceWrapperImpl xaResourceWrapper = (ActiveMQXAResourceWrapperImpl) resource; assertTrue(xaResourceWrapper.getJndiName().equals("java://jmsXA NodeId:" + server.getNodeID())); assertTrue(xaResourceWrapper.getProductVersion().equals(VersionLoader.getVersion().getFullVersion())); assertTrue(xaResourceWrapper.getProductName().equals(ActiveMQResourceAdapter.PRODUCT_NAME)); }
/** * Create a XA queue connection * * @return The connection * @throws JMSException Thrown if the operation fails */ @Override public XAQueueConnection createXAQueueConnection() throws JMSException { if (ActiveMQRAConnectionFactoryImpl.trace) { ActiveMQRALogger.LOGGER.trace("createXAQueueConnection()"); } ActiveMQRASessionFactoryImpl s = new ActiveMQRASessionFactoryImpl(mcf, cm, getResourceAdapter().getTM(), ActiveMQRAConnectionFactory.XA_QUEUE_CONNECTION); if (ActiveMQRAConnectionFactoryImpl.trace) { ActiveMQRALogger.LOGGER.trace("Created queue connection: " + s); } return s; }
public ManagedXAQueueConnection( XAQueueConnection connection ) { super(connection); this.xaConnection = connection; }
@Override public XAQueueSession createXAQueueSession() throws JMSException { return addSession( ((XAQueueConnection) connection).createXAQueueSession()); }
public XAQueueConnection createXAQueueConnection() throws JMSException { return (XAQueueConnection) createActiveMQConnection(); }
public XAQueueConnection createXAQueueConnection(String userName, String password) throws JMSException { return (XAQueueConnection) createActiveMQConnection(userName, password); }
private void assertXAConnection(Connection connection) { assertTrue("Should be an XAConnection", connection instanceof XAConnection); assertTrue("Should be an XATopicConnection", connection instanceof XATopicConnection); assertTrue("Should be an XAQueueConnection", connection instanceof XAQueueConnection); }
@Test public void testConnectionTypes() throws Exception { deployConnectionFactory(0, JMSFactoryType.CF, "ConnectionFactory", "/ConnectionFactory"); deployConnectionFactory(0, JMSFactoryType.QUEUE_XA_CF, "CF_QUEUE_XA_TRUE", "/CF_QUEUE_XA_TRUE"); deployConnectionFactory(0, JMSFactoryType.XA_CF, "CF_XA_TRUE", "/CF_XA_TRUE"); deployConnectionFactory(0, JMSFactoryType.QUEUE_CF, "CF_QUEUE", "/CF_QUEUE"); deployConnectionFactory(0, JMSFactoryType.TOPIC_CF, "CF_TOPIC", "/CF_TOPIC"); deployConnectionFactory(0, JMSFactoryType.TOPIC_XA_CF, "CF_TOPIC_XA_TRUE", "/CF_TOPIC_XA_TRUE"); Connection genericConnection = null; XAConnection xaConnection = null; QueueConnection queueConnection = null; TopicConnection topicConnection = null; XAQueueConnection xaQueueConnection = null; XATopicConnection xaTopicConnection = null; ConnectionFactory genericFactory = (ConnectionFactory) ic.lookup("/ConnectionFactory"); genericConnection = genericFactory.createConnection(); assertConnectionType(genericConnection, "generic"); XAConnectionFactory xaFactory = (XAConnectionFactory) ic.lookup("/CF_XA_TRUE"); xaConnection = xaFactory.createXAConnection(); assertConnectionType(xaConnection, "xa"); QueueConnectionFactory queueCF = (QueueConnectionFactory) ic.lookup("/CF_QUEUE"); queueConnection = queueCF.createQueueConnection(); assertConnectionType(queueConnection, "queue"); TopicConnectionFactory topicCF = (TopicConnectionFactory) ic.lookup("/CF_TOPIC"); topicConnection = topicCF.createTopicConnection(); assertConnectionType(topicConnection, "topic"); XAQueueConnectionFactory xaQueueCF = (XAQueueConnectionFactory) ic.lookup("/CF_QUEUE_XA_TRUE"); xaQueueConnection = xaQueueCF.createXAQueueConnection(); assertConnectionType(xaQueueConnection, "xa-queue"); XATopicConnectionFactory xaTopicCF = (XATopicConnectionFactory) ic.lookup("/CF_TOPIC_XA_TRUE"); xaTopicConnection = xaTopicCF.createXATopicConnection(); assertConnectionType(xaTopicConnection, "xa-topic"); genericConnection.close(); xaConnection.close(); queueConnection.close(); topicConnection.close(); xaQueueConnection.close(); xaTopicConnection.close(); undeployConnectionFactory("ConnectionFactory"); undeployConnectionFactory("CF_QUEUE_XA_TRUE"); undeployConnectionFactory("CF_XA_TRUE"); undeployConnectionFactory("CF_QUEUE"); undeployConnectionFactory("CF_TOPIC"); undeployConnectionFactory("CF_TOPIC_XA_TRUE"); }
public XAQueueConnection createXAQueueConnection() throws JMSException { return createXAQueueConnection(user, password); }
public XAQueueConnection createXAQueueConnection(final String username, final String password) throws JMSException { return (XAQueueConnection) createConnectionInternal(username, password, true, ActiveMQConnection.TYPE_QUEUE_CONNECTION); }
/** * Creates a XAQueueConnection with the default user identity. * <p> The XAQueueConnection is created in stopped mode. No messages * will be delivered until the <code>Connection.start</code> method * is explicitly called. * * @return A newly created XAQueueConnection * @throws JMSException If creating the XAQueueConnection fails due to some internal error. * @throws JMSSecurityException If client authentication fails due to an invalid user name or password. */ public XAQueueConnection createXAQueueConnection() throws JMSException { return (XAQueueConnection) createXAConnection(); }
/** * Creates a XAQueueConnection with the specified user identity. * <p> The XAQueueConnection is created in stopped mode. No messages * will be delivered until the <code>Connection.start</code> method * is explicitly called. * * @param username the caller's user name * @param password the caller's password * @return A newly created XAQueueConnection. * @throws JMSException If creating the XAQueueConnection fails due to some internal error. * @throws JMSSecurityException If client authentication fails due to an invalid user name or password. */ public XAQueueConnection createXAQueueConnection(String username, String password) throws JMSException { return (XAQueueConnection) createXAConnection(username, password); }