public JmsXAResourceRecoveryHelper(XAConnectionFactory xaConnectionFactory, String user, String pass) { this(new ConnectionManager(xaConnectionFactory, user, pass)); }
/** * 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); }
/** * Delegates XAResource#recover call to the connected JMS resource. If provided argument is XAResource.TMENDRSCAN, then JMS * connection will be closed at the end of the call. * * @param flag * @throws XAException */ @Override public Xid[] recover(int flag) throws XAException { try { return connectionManager.connectAndApply(delegate -> delegate.recover(flag)); } finally { if (flag == XAResource.TMENDRSCAN) { connectionManager.disconnect(); } } }
/** * Invoke {@link XAResourceConsumer} accept method before making sure that JMS connection is available. Current * connection is used if one is available. If connection is not available, new connection is created before the * accept call and closed after it. * * @param consumer {@link XAResourceConsumer} to be executed. * @throws XAException if JMS connection cannot be created. */ public void connectAndAccept(XAResourceConsumer consumer) throws XAException { if (isConnected()) { consumer.accept(session.getXAResource()); return; } connect(); try { consumer.accept(session.getXAResource()); } finally { disconnect(); } }
/** * 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)); }
/** * Create JMS connection. * * @throws XAException if JMS connection cannot be created. */ public void connect() throws XAException { if (isConnected()) { return; } try { connection = createXAConnection(); session = connection.createXASession(); } catch (JMSException e) { if (connection != null) { try { connection.close(); } catch (JMSException ignore) { } } jtaLogger.i18NLogger.warn_failed_to_create_jms_connection(e); throw new XAException(XAException.XAER_RMFAIL); } }
/** * Close current JMS connection. */ public void disconnect() { if (!isConnected()) { return; } try { connection.close(); } catch (JMSException e) { jtaLogger.i18NLogger.warn_failed_to_close_jms_connection(connection.toString(), e); } finally { connection = null; session = null; } }
/** * Invoke {@link XAResourceConsumer} accept method before making sure that JMS connection is available. Current * connection is used if one is available. If connection is not available, new connection is created before the * accept call and closed after it. * * @param consumer {@link XAResourceConsumer} to be executed. * @throws XAException if JMS connection cannot be created. */ public void connectAndAccept(XAResourceConsumer consumer) throws XAException { if (isConnected()) { consumer.accept(session.getXAResource()); return; } connect(); try { consumer.accept(session.getXAResource()); } finally { disconnect(); } }
/** * Delegates XAResource#end call to the connected JMS resource. * * @param xid * @param flag * @throws XAException */ @Override public void end(Xid xid, int flag) throws XAException { connectionManager.connectAndAccept(delegate -> delegate.end(xid, flag)); }
/** * Delegates XAResource#recover call to the connected JMS resource. If provided argument is XAResource.TMENDRSCAN, then JMS * connection will be closed at the end of the call. * * @param flag * @throws XAException */ @Override public Xid[] recover(int flag) throws XAException { try { return connectionManager.connectAndApply(delegate -> delegate.recover(flag)); } finally { if (flag == XAResource.TMENDRSCAN) { connectionManager.disconnect(); } } }
/** * Create JMS connection. * * @throws XAException if JMS connection cannot be created. */ public void connect() throws XAException { if (isConnected()) { return; } try { connection = createXAConnection(); session = connection.createXASession(); } catch (JMSException e) { if (connection != null) { try { connection.close(); } catch (JMSException ignore) { } } jtaLogger.i18NLogger.warn_failed_to_create_jms_connection(e); throw new XAException(XAException.XAER_RMFAIL); } }
/** * Close current JMS connection. */ public void disconnect() { if (!isConnected()) { return; } try { connection.close(); } catch (JMSException e) { jtaLogger.i18NLogger.warn_failed_to_close_jms_connection(connection.toString(), e); } finally { connection = null; session = null; } }
/** * Invoke {@link XAResourceConsumer} accept method before making sure that JMS connection is available. Current * connection is used if one is available. If connection is not available, new connection is created before the * accept call and closed after it. * * @param consumer {@link XAResourceConsumer} to be executed. * @throws XAException if JMS connection cannot be created. */ public void connectAndAccept(XAResourceConsumer consumer) throws XAException { if (isConnected()) { consumer.accept(session.getXAResource()); return; } connect(); try { consumer.accept(session.getXAResource()); } finally { disconnect(); } }
/** * 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)); }
/** * 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); }
/** * Delegates XAResource#recover call to the connected JMS resource. If provided argument is XAResource.TMENDRSCAN, then JMS * connection will be closed at the end of the call. * * @param flag * @throws XAException */ @Override public Xid[] recover(int flag) throws XAException { try { return connectionManager.connectAndApply(delegate -> delegate.recover(flag)); } finally { if (flag == XAResource.TMENDRSCAN) { connectionManager.disconnect(); } } }
/** * 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 }; }
/** * Create JMS connection. * * @throws XAException if JMS connection cannot be created. */ public void connect() throws XAException { if (isConnected()) { return; } try { connection = createXAConnection(); session = connection.createXASession(); } catch (JMSException e) { if (connection != null) { try { connection.close(); } catch (JMSException ignore) { } } jtaLogger.i18NLogger.warn_failed_to_create_jms_connection(e); throw new XAException(XAException.XAER_RMFAIL); } }
public JmsXAResourceRecoveryHelper(XAConnectionFactory xaConnectionFactory, String user, String pass) { this(new ConnectionManager(xaConnectionFactory, user, pass)); }