Java 类javax.jms.TransactionInProgressException 实例源码

项目:daq-eclipse    文件:TransactionContext.java   
/**
 * Start a local transaction.
 * @throws javax.jms.JMSException on internal error
 */
public void begin() throws JMSException {

    if (isInXATransaction()) {
        throw new TransactionInProgressException("Cannot start local transaction.  XA transaction is already in progress.");
    }

    if (transactionId == null) {
        synchronizations = null;
        beforeEndIndex = 0;
        this.transactionId = new LocalTransactionId(connectionId, localTransactionIdGenerator.getNextSequenceId());
        TransactionInfo info = new TransactionInfo(getConnectionId(), transactionId, TransactionInfo.BEGIN);
        this.connection.ensureConnectionInfoSent();
        this.connection.asyncSendPacket(info);

        // Notify the listener that the tx was started.
        if (localTransactionEventListener != null) {
            localTransactionEventListener.beginEvent();
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Begin:" + transactionId);
        }
    }

}
项目:activemq-artemis    文件:ActiveMQRASession.java   
/**
 * Commit
 *
 * @throws JMSException Failed to close session.
 */
@Override
public void commit() throws JMSException {
   if (cri.getType() == ActiveMQRAConnectionFactory.XA_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_QUEUE_CONNECTION ||
      cri.getType() == ActiveMQRAConnectionFactory.XA_TOPIC_CONNECTION) {
      throw new TransactionInProgressException("XA connection");
   }

   lock();
   try {
      Session session = getSessionInternal();

      if (cri.isTransacted() == false) {
         throw new IllegalStateException("Session is not transacted");
      }

      if (ActiveMQRASession.trace) {
         ActiveMQRALogger.LOGGER.trace("Commit session " + this);
      }

      session.commit();
   } finally {
      unlock();
   }
}
项目:activemq-artemis    文件:ActiveMQRASession.java   
/**
 * Rollback
 *
 * @throws JMSException Failed to close session.
 */
@Override
public void rollback() throws JMSException {
   if (cri.getType() == ActiveMQRAConnectionFactory.XA_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_QUEUE_CONNECTION ||
      cri.getType() == ActiveMQRAConnectionFactory.XA_TOPIC_CONNECTION) {
      throw new TransactionInProgressException("XA connection");
   }

   lock();
   try {
      Session session = getSessionInternal();

      if (cri.isTransacted() == false) {
         throw new IllegalStateException("Session is not transacted");
      }

      if (ActiveMQRASession.trace) {
         ActiveMQRALogger.LOGGER.trace("Rollback session " + this);
      }

      session.rollback();
   } finally {
      unlock();
   }
}
项目:org.ops4j.pax.transx    文件:Utils.java   
public static JMSRuntimeException convertToRuntimeException(JMSException e) {
    if (e instanceof javax.jms.IllegalStateException) {
        return new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof InvalidClientIDException) {
        return new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof InvalidDestinationException) {
        return new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof InvalidSelectorException) {
        return new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof JMSSecurityException) {
        return new JMSSecurityRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof MessageFormatException) {
        return new MessageFormatRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof MessageNotWriteableException) {
        return new MessageNotWriteableRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof ResourceAllocationException) {
        return new ResourceAllocationRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof TransactionInProgressException) {
        return new TransactionInProgressRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof TransactionRolledBackException) {
        return new TransactionRolledBackRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    return new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
项目:spring4-understanding    文件:TransactionAwareConnectionFactoryProxy.java   
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    // Invocation on SessionProxy interface coming in...

    if (method.getName().equals("equals")) {
        // Only consider equal when proxies are identical.
        return (proxy == args[0]);
    }
    else if (method.getName().equals("hashCode")) {
        // Use hashCode of Connection proxy.
        return System.identityHashCode(proxy);
    }
    else if (method.getName().equals("commit")) {
        throw new TransactionInProgressException("Commit call not allowed within a managed transaction");
    }
    else if (method.getName().equals("rollback")) {
        throw new TransactionInProgressException("Rollback call not allowed within a managed transaction");
    }
    else if (method.getName().equals("close")) {
        // Handle close method: not to be closed within a transaction.
        return null;
    }
    else if (method.getName().equals("getTargetSession")) {
        // Handle getTargetSession method: return underlying Session.
        return this.target;
    }

    // Invoke method on target Session.
    try {
        return method.invoke(this.target, args);
    }
    catch (InvocationTargetException ex) {
        throw ex.getTargetException();
    }
}
项目:daq-eclipse    文件:TransactionContext.java   
/**
 * Rolls back any work done in this transaction and releases any locks
 * currently held.
 *
 * @throws JMSException if the JMS provider fails to roll back the
 *                 transaction due to some internal error.
 * @throws javax.jms.IllegalStateException if the method is not called by a
 *                 transacted session.
 */
public void rollback() throws JMSException {
    if (isInXATransaction()) {
        throw new TransactionInProgressException("Cannot rollback() if an XA transaction is already in progress ");
    }

    try {
        beforeEnd();
    } catch (TransactionRolledBackException canOcurrOnFailover) {
        LOG.warn("rollback processing error", canOcurrOnFailover);
    }
    if (transactionId != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Rollback: "  + transactionId
            + " syncCount: "
            + (synchronizations != null ? synchronizations.size() : 0));
        }

        TransactionInfo info = new TransactionInfo(getConnectionId(), transactionId, TransactionInfo.ROLLBACK);
        this.transactionId = null;
        //make this synchronous - see https://issues.apache.org/activemq/browse/AMQ-2364
        this.connection.syncSendPacket(info);
        // Notify the listener that the tx was rolled back
        if (localTransactionEventListener != null) {
            localTransactionEventListener.rollbackEvent();
        }
    }

    afterRollback();
}
项目:activemq-artemis    文件:JmsExceptionUtils.java   
/**
 * Converts instances of sub-classes of {@link JMSException} into the corresponding sub-class of
 * {@link JMSRuntimeException}.
 *
 * @param e
 * @return
 */
public static JMSRuntimeException convertToRuntimeException(JMSException e) {
   if (e instanceof javax.jms.IllegalStateException) {
      return new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof InvalidClientIDException) {
      return new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof InvalidDestinationException) {
      return new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof InvalidSelectorException) {
      return new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof JMSSecurityException) {
      return new JMSSecurityRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof MessageFormatException) {
      return new MessageFormatRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof MessageNotWriteableException) {
      return new MessageNotWriteableRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof ResourceAllocationException) {
      return new ResourceAllocationRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof TransactionInProgressException) {
      return new TransactionInProgressRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof TransactionRolledBackException) {
      return new TransactionRolledBackRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   return new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
项目:activemq-artemis    文件:ActiveMQSession.java   
@Override
public void commit() throws JMSException {
   if (!transacted) {
      throw new IllegalStateException("Cannot commit a non-transacted session");
   }
   if (xa) {
      throw new TransactionInProgressException("Cannot call commit on an XA session");
   }
   try {
      session.commit();
   } catch (ActiveMQException e) {
      throw JMSExceptionHelper.convertFromActiveMQException(e);
   }
}
项目:activemq-artemis    文件:ActiveMQSession.java   
@Override
public void rollback() throws JMSException {
   if (!transacted) {
      throw new IllegalStateException("Cannot rollback a non-transacted session");
   }
   if (xa) {
      throw new TransactionInProgressException("Cannot call rollback on an XA session");
   }

   try {
      session.rollback();
   } catch (ActiveMQException e) {
      throw JMSExceptionHelper.convertFromActiveMQException(e);
   }
}
项目:class-guard    文件:TransactionAwareConnectionFactoryProxy.java   
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    // Invocation on SessionProxy interface coming in...

    if (method.getName().equals("equals")) {
        // Only consider equal when proxies are identical.
        return (proxy == args[0]);
    }
    else if (method.getName().equals("hashCode")) {
        // Use hashCode of Connection proxy.
        return System.identityHashCode(proxy);
    }
    else if (method.getName().equals("commit")) {
        throw new TransactionInProgressException("Commit call not allowed within a managed transaction");
    }
    else if (method.getName().equals("rollback")) {
        throw new TransactionInProgressException("Rollback call not allowed within a managed transaction");
    }
    else if (method.getName().equals("close")) {
        // Handle close method: not to be closed within a transaction.
        return null;
    }
    else if (method.getName().equals("getTargetSession")) {
        // Handle getTargetSession method: return underlying Session.
        return this.target;
    }

    // Invoke method on target Session.
    try {
        return method.invoke(this.target, args);
    }
    catch (InvocationTargetException ex) {
        throw ex.getTargetException();
    }
}
项目:tomee    文件:JMS2.java   
public static JMSRuntimeException toRuntimeException(final JMSException e) {
    if (e instanceof javax.jms.IllegalStateException) {
        return new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof InvalidClientIDException) {
        return new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof InvalidDestinationException) {
        return new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof InvalidSelectorException) {
        return new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof JMSSecurityException) {
        return new JMSSecurityRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof MessageFormatException) {
        return new MessageFormatRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof MessageNotWriteableException) {
        return new MessageNotWriteableRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof ResourceAllocationException) {
        return new ResourceAllocationRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof TransactionInProgressException) {
        return new TransactionInProgressRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    if (e instanceof TransactionRolledBackException) {
        return new TransactionRolledBackRuntimeException(e.getMessage(), e.getErrorCode(), e);
    }
    return new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
项目:btm    文件:DualSessionWrapper.java   
@Override
public void commit() throws JMSException {
    if (isParticipatingInActiveGlobalTransaction())
        throw new TransactionInProgressException("cannot commit a resource enlisted in a global transaction");

    getSession().commit();
}
项目:btm    文件:DualSessionWrapper.java   
@Override
public void rollback() throws JMSException {
    if (isParticipatingInActiveGlobalTransaction())
        throw new TransactionInProgressException("cannot rollback a resource enlisted in a global transaction");

    getSession().rollback();
}
项目:btm    文件:DualSessionWrapper.java   
@Override
public void recover() throws JMSException {
    if (isParticipatingInActiveGlobalTransaction())
        throw new TransactionInProgressException("cannot recover a resource enlisted in a global transaction");

    getSession().recover();
}
项目:pooled-jms    文件:JMSExceptionSupportTest.java   
@Test(expected = TransactionInProgressRuntimeException.class)
public void testConvertsTransactionInProgressExceptionToTransactionInProgressRuntimeException() {
    throw JMSExceptionSupport.createRuntimeException(new TransactionInProgressException("error"));
}
项目:daq-eclipse    文件:ActiveMQXASession.java   
public void rollback() throws JMSException {
    checkClosed();
    throw new TransactionInProgressException("Cannot rollback() inside an XASession");
}
项目:daq-eclipse    文件:ActiveMQXASession.java   
public void commit() throws JMSException {
    checkClosed();
    throw new TransactionInProgressException("Cannot commit() inside an XASession");
}
项目:daq-eclipse    文件:TransactionContext.java   
/**
 * Commits all work done in this transaction and releases any locks
 * currently held.
 *
 * @throws JMSException if the JMS provider fails to commit the transaction
 *                 due to some internal error.
 * @throws javax.jms.IllegalStateException if the method is not called by a
 *                 transacted session.
 */
public void commit() throws JMSException {
    if (isInXATransaction()) {
        throw new TransactionInProgressException("Cannot commit() if an XA transaction is already in progress ");
    }

    try {
        beforeEnd();
    } catch (JMSException e) {
        rollback();
        throw e;
    }

    // Only send commit if the transaction was started.
    if (transactionId != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Commit: "  + transactionId
                    + " syncCount: "
                    + (synchronizations != null ? synchronizations.size() : 0));
        }

        TransactionInfo info = new TransactionInfo(getConnectionId(), transactionId, TransactionInfo.COMMIT_ONE_PHASE);
        this.transactionId = null;
        // Notify the listener that the tx was committed back
        try {
            syncSendPacketWithInterruptionHandling(info);
            if (localTransactionEventListener != null) {
                localTransactionEventListener.commitEvent();
            }
            afterCommit();
        } catch (JMSException cause) {
            LOG.info("commit failed for transaction " + info.getTransactionId(), cause);
            if (localTransactionEventListener != null) {
                localTransactionEventListener.rollbackEvent();
            }
            afterRollback();
            throw cause;
        }

    }
}
项目:qpid-jms    文件:JmsExceptionSupportTest.java   
@Test(expected = TransactionInProgressRuntimeException.class)
public void testConvertsTransactionInProgressExceptionToTransactionInProgressRuntimeException() {
    throw JmsExceptionSupport.createRuntimeException(new TransactionInProgressException("error"));
}
项目:andes    文件:XASession_9_1.java   
/**
 * Throws a {@link TransactionInProgressException}, since it should
 * not be called for an XASession object.
 *
 * @throws TransactionInProgressException always.
 */
public void commit() throws JMSException
{
    throw new TransactionInProgressException(
            "XASession:  A direct invocation of the commit operation is prohibited!");
}
项目:andes    文件:XASession_9_1.java   
/**
 * Throws a {@link TransactionInProgressException}, since it should
 * not be called for an XASession object.
 *
 * @throws TransactionInProgressException always.
 */
public void rollback() throws JMSException
{
    throw new TransactionInProgressException(
            "XASession: A direct invocation of the rollback operation is prohibited!");
}
项目:andes    文件:XASession_9_1.java   
/**
 * Throws a {@link TransactionInProgressException}, since it should
 * not be called for an XASession object.
 *
 * @throws TransactionInProgressException always.
 */
public void recover() throws JMSException
{
    throw new TransactionInProgressException(
            "XASession: A direct invocation of the recover operation is prohibited!");
}