Search in sources :

Example 16 with ActiveMQInterruptedException

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

the class TimedBuffer method stop.

public void stop() {
    enterCritical(CRITICAL_PATH_STOP);
    Thread localTimer = null;
    try {
        // add critical analyzer here.... <<<<
        synchronized (this) {
            try {
                if (!started) {
                    return;
                }
                flush();
                bufferObserver = null;
                timerRunnable.close();
                spinLimiter.release();
                if (logRates) {
                    logRatesTimerTask.cancel();
                }
                localTimer = timerThread;
                timerThread = null;
            } finally {
                started = false;
            }
        }
        if (localTimer != null) {
            while (localTimer.isAlive()) {
                try {
                    localTimer.join(1000);
                    if (localTimer.isAlive()) {
                        localTimer.interrupt();
                    }
                } catch (InterruptedException e) {
                    throw new ActiveMQInterruptedException(e);
                }
            }
        }
    } finally {
        leaveCritical(CRITICAL_PATH_STOP);
    }
}
Also used : ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)

Example 17 with ActiveMQInterruptedException

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

the class ActiveMQMessageConsumer method getMessage.

private ActiveMQMessage getMessage(final long timeout, final boolean noWait) throws JMSException {
    try {
        ClientMessage coreMessage;
        if (noWait) {
            coreMessage = consumer.receiveImmediate();
        } else {
            coreMessage = consumer.receive(timeout);
        }
        ActiveMQMessage jmsMsg = null;
        if (coreMessage != null) {
            ClientSession coreSession = session.getCoreSession();
            boolean needSession = ackMode == Session.CLIENT_ACKNOWLEDGE || ackMode == ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE || coreMessage.getType() == ActiveMQObjectMessage.TYPE;
            jmsMsg = ActiveMQMessage.createMessage(coreMessage, needSession ? coreSession : null, options);
            try {
                jmsMsg.doBeforeReceive();
            } catch (IndexOutOfBoundsException ioob) {
                ((ClientSessionInternal) session.getCoreSession()).markRollbackOnly();
                // In case this exception happen you will need to know where it happened.
                // it has been a bug here in the past, and this was used to debug it.
                // nothing better than keep it for future investigations in case it happened again
                IndexOutOfBoundsException newIOOB = new IndexOutOfBoundsException(ioob.getMessage() + "@" + jmsMsg.getCoreMessage());
                newIOOB.initCause(ioob);
                ActiveMQClientLogger.LOGGER.unableToGetMessage(newIOOB);
                throw ioob;
            }
            // https://issues.jboss.org/browse/JBPAPP-6110
            if (session.getAcknowledgeMode() == ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE) {
                jmsMsg.setIndividualAcknowledge();
            } else if (session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE) {
                jmsMsg.setClientAcknowledge();
                coreMessage.acknowledge();
            } else {
                coreMessage.acknowledge();
            }
        }
        return jmsMsg;
    } catch (ActiveMQException e) {
        ((ClientSessionInternal) session.getCoreSession()).markRollbackOnly();
        throw JMSExceptionHelper.convertFromActiveMQException(e);
    } catch (ActiveMQInterruptedException e) {
        ((ClientSessionInternal) session.getCoreSession()).markRollbackOnly();
        throw JMSExceptionHelper.convertFromActiveMQException(e);
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage)

Aggregations

ActiveMQInterruptedException (org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)17 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)7 CountDownLatch (java.util.concurrent.CountDownLatch)3 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 IOException (java.io.IOException)1 ObjectStreamException (java.io.ObjectStreamException)1 Lock (java.util.concurrent.locks.Lock)1 BytesMessage (javax.jms.BytesMessage)1 IllegalStateException (javax.jms.IllegalStateException)1 InvalidDestinationException (javax.jms.InvalidDestinationException)1 JMSException (javax.jms.JMSException)1 MapMessage (javax.jms.MapMessage)1 ObjectMessage (javax.jms.ObjectMessage)1 StreamMessage (javax.jms.StreamMessage)1 TextMessage (javax.jms.TextMessage)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)1