/** * Aqquire a lock on the managed connection within the specified period * * @throws JMSException Thrown if an error occurs */ protected void tryLock() throws JMSException { if (logger.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("tryLock()"); } Integer tryLock = mcf.getUseTryLock(); if (tryLock == null || tryLock.intValue() <= 0) { lock(); return; } try { if (lock.tryLock(tryLock.intValue(), TimeUnit.SECONDS) == false) { throw new ResourceAllocationException("Unable to obtain lock in " + tryLock + " seconds: " + this); } } catch (InterruptedException e) { throw new ResourceAllocationException("Interrupted attempting lock: " + this); } }
/** * Aqquire a lock on the managed connection within the specified period * * @throws JMSException Thrown if an error occurs */ protected void tryLock() throws JMSException { if (logger.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("tryLock()"); } Integer tryLock = mcf.getUseTryLock(); if (tryLock == null || tryLock.intValue() <= 0) { lock(); return; } try { if (lock.tryLock(tryLock.intValue(), TimeUnit.SECONDS) == false) { throw new ResourceAllocationException("Unable to obtain lock in " + tryLock + " seconds: " + this); } } catch (InterruptedException e) { throw new ResourceAllocationException("Interrupted attempting lock: " + this); } }
/** * End * * @param xid A global transaction identifier * @param flags One of TMSUCCESS, TMFAIL, or TMSUSPEND. * @throws XAException An error has occurred */ @Override public void end(final Xid xid, final int flags) throws XAException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("end(" + xid + ", " + flags + ")"); } managedConnection.lock(); try { xaResource.end(xid, flags); } finally { managedConnection.setInManagedTx(false); managedConnection.unlock(); } }
/** * End * * @param xid A global transaction identifier * @param flags One of TMSUCCESS, TMFAIL, or TMSUSPEND. * @throws XAException An error has occurred */ @Override public void end(final Xid xid, final int flags) throws XAException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("end(" + xid + ", " + flags + ")"); } managedConnection.lock(); try { xaResource.end(xid, flags); } finally { managedConnection.setInManagedTx(false); managedConnection.unlock(); } }
/** * Forget * * @param xid A global transaction identifier * @throws XAException An error has occurred */ @Override public void forget(final Xid xid) throws XAException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("forget(" + xid + ")"); } managedConnection.lock(); try { xaResource.forget(xid); } finally { managedConnection.setInManagedTx(true); managedConnection.setInManagedTx(false); managedConnection.unlock(); } }
/** * Forget * * @param xid A global transaction identifier * @throws XAException An error has occurred */ @Override public void forget(final Xid xid) throws XAException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("forget(" + xid + ")"); } managedConnection.lock(); try { xaResource.forget(xid); } finally { managedConnection.setInManagedTx(true); managedConnection.setInManagedTx(false); managedConnection.unlock(); } }
/** * Commit * * @throws ResourceException Thrown if the operation fails */ @Override public void commit() throws ResourceException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("commit()"); } mc.lock(); try { if (mc.getSession().getTransacted()) { mc.getSession().commit(); } } catch (JMSException e) { throw new ResourceException("Could not commit LocalTransaction", e); } finally { //mc.setInManagedTx(false); mc.unlock(); } }
/** * Rollback * * @throws ResourceException Thrown if the operation fails */ @Override public void rollback() throws ResourceException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("rollback()"); } mc.lock(); try { if (mc.getSession().getTransacted()) { mc.getSession().rollback(); } } catch (JMSException ex) { throw new ResourceException("Could not rollback LocalTransaction", ex); } finally { //mc.setInManagedTx(false); mc.unlock(); } } }
/** * Commit * * @throws ResourceException Thrown if the operation fails */ @Override public void commit() throws ResourceException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("commit()"); } mc.lock(); try { if (mc.getSession().getTransacted()) { mc.getSession().commit(); } } catch (JMSException e) { throw new ResourceException("Could not commit LocalTransaction", e); } finally { //mc.setInManagedTx(false); mc.unlock(); } }
/** * Rollback * * @throws ResourceException Thrown if the operation fails */ @Override public void rollback() throws ResourceException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("rollback()"); } mc.lock(); try { if (mc.getSession().getTransacted()) { mc.getSession().rollback(); } } catch (JMSException ex) { throw new ResourceException("Could not rollback LocalTransaction", ex); } finally { //mc.setInManagedTx(false); mc.unlock(); } } }
/** * Start * * @param xid A global transaction identifier * @param flags One of TMNOFLAGS, TMJOIN, or TMRESUME * @throws XAException An error has occurred */ @Override public void start(final Xid xid, final int flags) throws XAException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("start(" + xid + ", " + flags + ")"); } managedConnection.lock(); ClientSessionInternal sessionInternal = (ClientSessionInternal) xaResource; try { try { //this resets any tx stuff, we assume here that the tm and jca layer are well behaved when it comes to this sessionInternal.resetIfNeeded(); } catch (ActiveMQException e) { ActiveMQRALogger.LOGGER.problemResettingXASession(e); XAException xaException = new XAException(XAException.XAER_RMFAIL); xaException.initCause(e); throw xaException; } xaResource.start(xid, flags); } finally { managedConnection.setInManagedTx(true); managedConnection.unlock(); } }
/** * Start * * @param xid A global transaction identifier * @param flags One of TMNOFLAGS, TMJOIN, or TMRESUME * @throws XAException An error has occurred */ @Override public void start(final Xid xid, final int flags) throws XAException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("start(" + xid + ", " + flags + ")"); } managedConnection.lock(); ClientSessionInternal sessionInternal = (ClientSessionInternal) xaResource; try { try { //this resets any tx stuff, we assume here that the tm and jca layer are well behaved when it comes to this sessionInternal.resetIfNeeded(); } catch (ActiveMQException e) { ActiveMQRALogger.LOGGER.problemResettingXASession(e); XAException xaException = new XAException(XAException.XAER_RMFAIL); xaException.initCause(e); throw xaException; } xaResource.start(xid, flags); } finally { managedConnection.setInManagedTx(true); managedConnection.unlock(); } }