private void startHornetQServer() throws Exception { jmsServer = new EmbeddedJMS(); jmsServer.start(); logger.debug("Started Embedded JMS Server"); XAConnectionFactory connectionFactory = (XAConnectionFactory) jmsServer.lookup("ConnectionFactory"); new InitialContext().rebind("java:comp/UserTransaction", com.arjuna.ats.jta.UserTransaction.userTransaction()); new InitialContext().rebind("java:comp/TransactionManager", com.arjuna.ats.jta.TransactionManager.transactionManager()); new InitialContext().rebind("java:comp/TransactionSynchronizationRegistry", new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple()); factory = new ConnectionFactoryProxy(connectionFactory, new TransactionHelperImpl(com.arjuna.ats.jta.TransactionManager.transactionManager())); queue = (Queue) jmsServer.lookup("/queue/exampleQueue"); }
/** * Delegates XAResource#getTransactionTimeout call to the connected JMS resource. * * @return Transaction timeout value. * @throws XAException */ @Override public int getTransactionTimeout() throws XAException { return connectionManager.connectAndApply(XAResource::getTransactionTimeout); }
public JmsXAResourceRecoveryHelper(XAConnectionFactory xaConnectionFactory, String user, String pass) { this(new ConnectionManager(xaConnectionFactory, user, pass)); }
/** * Simply create a session with an XA connection if there is no active transaction. Or create a proxied session and register * it with an active transaction. * * @see SessionProxy * @see Connection#createSession(boolean, int) */ @Override public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException { if (transactionHelper.isTransactionAvailable()) { return createAndRegisterSession(); } return xaConnection.createSession(transacted, acknowledgeMode); }
/** * If JMS connection was created successfully, returns an array with one instance of JmsXAResourceRecoveryHelper. Otherwise, * returns an empty array. * * @return Array with one instance of JmsXAResourceRecoveryHelper or an empty array */ @Override public XAResource[] getXAResources() { if (!connectionManager.isConnected()) { try { connectionManager.connect(); } catch (XAException ignored) { return new XAResource[0]; } } return new XAResource[] { this }; }
/** * Delegates XAResource#start call to the connected JMS resource. * * @param xid * @param flag * @throws XAException */ @Override public void start(Xid xid, int flag) throws XAException { connectionManager.connectAndAccept(delegate -> delegate.start(xid, flag)); }
/** * Simply create a session with an XA connection if there is no active transaction. Or create a proxied session and register * it with an active transaction. * * @see SessionProxy * @see Connection#createSession(boolean, int) */ @Override public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException { if (transactionHelper.isTransactionAvailable()) { return createAndRegisterSession(); } return xaConnection.createSession(transacted, acknowledgeMode); }
/** * If JMS connection was created successfully, returns an array with one instance of JmsXAResourceRecoveryHelper. Otherwise, * returns an empty array. * * @return Array with one instance of JmsXAResourceRecoveryHelper or an empty array */ @Override public XAResource[] getXAResources() { if (!connectionManager.isConnected()) { try { connectionManager.connect(); } catch (XAException ignored) { return new XAResource[0]; } } return new XAResource[] { this }; }
/** * Delegates XAResource#getTransactionTimeout call to the connected JMS resource. * * @return Transaction timeout value. * @throws XAException */ @Override public int getTransactionTimeout() throws XAException { return connectionManager.connectAndApply(XAResource::getTransactionTimeout); }
public JmsXAResourceRecoveryHelper(XAConnectionFactory xaConnectionFactory, String user, String pass) { this(new ConnectionManager(xaConnectionFactory, user, pass)); }
/** * Delegates XAResource#commit call to the connected JMS resource. * * @param xid * @param onePhase * @throws XAException */ @Override public void commit(Xid xid, boolean onePhase) throws XAException { connectionManager.connectAndAccept(delegate -> delegate.commit(xid, onePhase)); }
/** * Simply create a session with an XA connection if there is no active transaction. Or create a proxied session and register * it with an active transaction. * * @see SessionProxy * @see Connection#createSession(boolean, int) */ @Override public Session createSession(boolean transacted, int acknowledgeMode) throws JMSException { if (transactionHelper.isTransactionAvailable()) { return createAndRegisterSession(); } return xaConnection.createSession(transacted, acknowledgeMode); }
/** * If JMS connection was created successfully, returns an array with one instance of JmsXAResourceRecoveryHelper. Otherwise, * returns an empty array. * * @return Array with one instance of JmsXAResourceRecoveryHelper or an empty array */ @Override public XAResource[] getXAResources() { if (!connectionManager.isConnected()) { try { connectionManager.connect(); } catch (XAException ignored) { return new XAResource[0]; } } return new XAResource[] { this }; }
/** * Delegates XAResource#getTransactionTimeout call to the connected JMS resource. * * @return Transaction timeout value. * @throws XAException */ @Override public int getTransactionTimeout() throws XAException { return connectionManager.connectAndApply(XAResource::getTransactionTimeout); }
public JmsXAResourceRecoveryHelper(XAConnectionFactory xaConnectionFactory, String user, String pass) { this(new ConnectionManager(xaConnectionFactory, user, pass)); }
/** * Delegates XAResource#forget call to the connected JMS resource. * * @param xid * @throws XAException */ @Override public void forget(Xid xid) throws XAException { connectionManager.connectAndAccept(delegate -> delegate.forget(xid)); }
/** * Delegates XAResource#prepare call to the connected JMS resource. * * @param xid * @return Prepare outcome * @throws XAException */ @Override public int prepare(Xid xid) throws XAException { return connectionManager.connectAndApply(delegate -> delegate.prepare(xid)); }
/** * Delegates XAResource#prepare call to the connected JMS resource. * * @param xid * @return Prepare outcome * @throws XAException */ @Override public int prepare(Xid xid) throws XAException { return connectionManager.connectAndApply(delegate -> delegate.prepare(xid)); }
/** * Delegates XAResource#isSameRM call to the connected JMS resource. * * @param xaResource * @return True if is same resource manager or false if not. * @throws XAException */ @Override public boolean isSameRM(XAResource xaResource) throws XAException { return connectionManager.connectAndApply(delegate -> delegate.isSameRM(xaResource)); }
/** * Delegates XAResource#setTransactionTimeout call to the connected JMS resource. * * @param seconds * @return True if transaction timeout was set, or false if wasn't. * @throws XAException */ @Override public boolean setTransactionTimeout(int seconds) throws XAException { return connectionManager.connectAndApply(delegate -> delegate.setTransactionTimeout(seconds)); }