/** * 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 }; }
/** * 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 }; }
/** * 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 }; }
/** * 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(); } }
/** * Invoke {@link XAResourceFunction} apply 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 * apply call and closed after it. * * @param function {@link XAResourceFunction} to be executed. * @param <T> Return type of the {@link XAResourceFunction}. * @return The result of {@link XAResourceFunction}. * @throws XAException if JMS connection cannot be created. */ public <T> T connectAndApply(XAResourceFunction<T> function) throws XAException { if (isConnected()) { return function.apply(session.getXAResource()); } connect(); try { return function.apply(session.getXAResource()); } finally { 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(); } }
/** * Invoke {@link XAResourceFunction} apply 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 * apply call and closed after it. * * @param function {@link XAResourceFunction} to be executed. * @param <T> Return type of the {@link XAResourceFunction}. * @return The result of {@link XAResourceFunction}. * @throws XAException if JMS connection cannot be created. */ public <T> T connectAndApply(XAResourceFunction<T> function) throws XAException { if (isConnected()) { return function.apply(session.getXAResource()); } connect(); try { return function.apply(session.getXAResource()); } finally { 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(); } }
/** * Invoke {@link XAResourceFunction} apply 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 * apply call and closed after it. * * @param function {@link XAResourceFunction} to be executed. * @param <T> Return type of the {@link XAResourceFunction}. * @return The result of {@link XAResourceFunction}. * @throws XAException if JMS connection cannot be created. */ public <T> T connectAndApply(XAResourceFunction<T> function) throws XAException { if (isConnected()) { return function.apply(session.getXAResource()); } connect(); try { return function.apply(session.getXAResource()); } finally { disconnect(); } }