Search in sources :

Example 31 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class SubscriptionsResource method subscriptionExists.

private boolean subscriptionExists(String subscriptionId) {
    ClientSession session = null;
    try {
        session = sessionFactory.createSession();
        ClientSession.QueueQuery query = session.queueQuery(new SimpleString(subscriptionId));
        return query.isExists();
    } catch (ActiveMQException e) {
        throw new RuntimeException(e);
    } finally {
        if (session != null) {
            try {
                session.close();
            } catch (ActiveMQException e) {
            }
        }
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 32 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class XmlDataExporter method printLargeMessageBody.

private void printLargeMessageBody(LargeServerMessage message) throws XMLStreamException {
    xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_IS_LARGE, Boolean.TRUE.toString());
    LargeBodyEncoder encoder = null;
    try {
        encoder = message.toCore().getBodyEncoder();
        encoder.open();
        long totalBytesWritten = 0;
        Long bufferSize;
        long bodySize = encoder.getLargeBodySize();
        for (long i = 0; i < bodySize; i += LARGE_MESSAGE_CHUNK_SIZE) {
            Long remainder = bodySize - totalBytesWritten;
            if (remainder >= LARGE_MESSAGE_CHUNK_SIZE) {
                bufferSize = LARGE_MESSAGE_CHUNK_SIZE;
            } else {
                bufferSize = remainder;
            }
            ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(bufferSize.intValue());
            encoder.encode(buffer, bufferSize.intValue());
            xmlWriter.writeCData(XmlDataExporterUtil.encode(buffer.toByteBuffer().array()));
            totalBytesWritten += bufferSize;
        }
        encoder.close();
    } catch (ActiveMQException e) {
        e.printStackTrace();
    } finally {
        if (encoder != null) {
            try {
                encoder.close();
            } catch (ActiveMQException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) LargeBodyEncoder(org.apache.activemq.artemis.core.message.LargeBodyEncoder) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 33 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class ActiveMQRAXAResource method start.

/**
 * 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 (ActiveMQRAXAResource.trace) {
        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();
    }
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) XAException(javax.transaction.xa.XAException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Example 34 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class ActiveMQResourceAdapter method start.

/**
 * Start
 *
 * @param ctx The bootstrap context
 * @throws ResourceAdapterInternalException Thrown if an error occurs
 */
@Override
public void start(final BootstrapContext ctx) throws ResourceAdapterInternalException {
    if (logger.isTraceEnabled()) {
        logger.trace("start(" + ctx + ")");
    }
    tm = ServiceUtils.getTransactionManager();
    recoveryManager.start(useAutoRecovery);
    this.ctx = ctx;
    if (!configured.getAndSet(true)) {
        try {
            setup();
        } catch (ActiveMQException e) {
            throw new ResourceAdapterInternalException("Unable to create activation", e);
        }
    }
    ActiveMQRALogger.LOGGER.resourceAdaptorStarted();
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException)

Example 35 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class ActiveMQMessageHandler method onMessage.

@Override
public void onMessage(final ClientMessage message) {
    if (logger.isTraceEnabled()) {
        logger.trace("onMessage(" + message + ")");
    }
    ActiveMQMessage msg = ActiveMQMessage.createMessage(message, session, options);
    boolean beforeDelivery = false;
    try {
        if (activation.getActivationSpec().getTransactionTimeout() > 0 && tm != null) {
            tm.setTransactionTimeout(activation.getActivationSpec().getTransactionTimeout());
        }
        if (logger.isTraceEnabled()) {
            logger.trace("HornetQMessageHandler::calling beforeDelivery on message " + message);
        }
        endpoint.beforeDelivery(ActiveMQActivation.ONMESSAGE);
        beforeDelivery = true;
        msg.doBeforeReceive();
        if (transacted) {
            message.individualAcknowledge();
        }
        ((MessageListener) endpoint).onMessage(msg);
        if (!transacted) {
            message.individualAcknowledge();
        }
        if (logger.isTraceEnabled()) {
            logger.trace("HornetQMessageHandler::calling afterDelivery on message " + message);
        }
        try {
            endpoint.afterDelivery();
        } catch (ResourceException e) {
            ActiveMQRALogger.LOGGER.unableToCallAfterDelivery(e);
            // If we get here, The TX was already rolled back
            // However we must do some stuff now to make sure the client message buffer is cleared
            // so we mark this as rollbackonly
            session.markRollbackOnly();
            return;
        }
        if (useLocalTx) {
            session.commit();
        }
        if (logger.isTraceEnabled()) {
            logger.trace("finished onMessage on " + message);
        }
    } catch (Throwable e) {
        ActiveMQRALogger.LOGGER.errorDeliveringMessage(e);
        // we need to call before/afterDelivery as a pair
        if (beforeDelivery) {
            if (useXA && tm != null) {
                // this is to avoid a scenario where afterDelivery would kick in
                try {
                    Transaction tx = tm.getTransaction();
                    if (tx != null) {
                        tx.setRollbackOnly();
                    }
                } catch (Exception e1) {
                    ActiveMQRALogger.LOGGER.unableToClearTheTransaction(e1);
                }
            }
            MessageEndpoint endToUse = endpoint;
            try {
                // to avoid a NPE that would happen while the RA is in tearDown
                if (endToUse != null) {
                    endToUse.afterDelivery();
                }
            } catch (ResourceException e1) {
                ActiveMQRALogger.LOGGER.unableToCallAfterDelivery(e1);
            }
        }
        if (useLocalTx || !activation.isDeliveryTransacted()) {
            try {
                session.rollback(true);
            } catch (ActiveMQException e1) {
                ActiveMQRALogger.LOGGER.unableToRollbackTX();
            }
        }
        // This is to make sure we will issue a rollback after failures
        // so that would cleanup consumer buffers among other things
        session.markRollbackOnly();
    } finally {
        try {
            session.resetIfNeeded();
        } catch (ActiveMQException e) {
            ActiveMQRALogger.LOGGER.unableToResetSession(activation.toString(), e);
            activation.startReconnectThread("Reset MessageHandler after Failure Thread");
        }
    }
}
Also used : MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) Transaction(javax.transaction.Transaction) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) MessageListener(javax.jms.MessageListener) ResourceException(javax.resource.ResourceException) ResourceException(javax.resource.ResourceException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQMessage(org.apache.activemq.artemis.jms.client.ActiveMQMessage)

Aggregations

ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)254 Test (org.junit.Test)139 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)121 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)84 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)79 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)78 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)59 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)54 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)45 CountDownLatch (java.util.concurrent.CountDownLatch)40 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)36 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)31 HashSet (java.util.HashSet)29 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)27 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)23 Role (org.apache.activemq.artemis.core.security.Role)22 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)20 Set (java.util.Set)16 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)16 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)15