Search in sources :

Example 6 with ActiveMQIllegalStateException

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

the class ConsumerTest method testNoReceiveWithListener.

@Test
public void testNoReceiveWithListener() throws Exception {
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    ClientConsumer consumer = session.createConsumer(QUEUE);
    consumer.setMessageHandler(new MessageHandler() {

        @Override
        public void onMessage(final ClientMessage msg) {
        }
    });
    try {
        consumer.receiveImmediate();
        Assert.fail("Should throw exception");
    } catch (ActiveMQIllegalStateException ise) {
    // ok
    } catch (ActiveMQException me) {
        Assert.fail("Wrong exception code");
    }
    session.close();
}
Also used : MessageHandler(org.apache.activemq.artemis.api.core.client.MessageHandler) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Test(org.junit.Test)

Example 7 with ActiveMQIllegalStateException

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

the class ReceiveTest method testReceiveThrowsExceptionWhenHandlerSet.

@Test
public void testReceiveThrowsExceptionWhenHandlerSet() throws Exception {
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession(false, true, true);
    session.createQueue(addressA, queueA, false);
    ClientConsumer cc = session.createConsumer(queueA);
    session.start();
    cc.setMessageHandler(new MessageHandler() {

        @Override
        public void onMessage(final ClientMessage message) {
        }
    });
    try {
        cc.receive();
        Assert.fail("should throw exception");
    } catch (ActiveMQIllegalStateException ise) {
    // ok
    } catch (ActiveMQException e) {
        Assert.fail("Invalid Exception type:" + e.getType());
    }
    session.close();
}
Also used : MessageHandler(org.apache.activemq.artemis.api.core.client.MessageHandler) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Test(org.junit.Test)

Example 8 with ActiveMQIllegalStateException

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

the class MQTTPublishManager method handlePubRec.

void handlePubRec(int messageId) throws Exception {
    try {
        Pair<Long, Long> ref = outboundStore.publishReceived(messageId);
        if (ref != null) {
            Message m = MQTTUtil.createPubRelMessage(session, getManagementAddress(), messageId);
            session.getServerSession().send(m, true);
            session.getServerSession().individualAcknowledge(ref.getB(), ref.getA());
        } else {
            session.getProtocolHandler().sendPubRel(messageId);
        }
    } catch (ActiveMQIllegalStateException e) {
        log.warn("MQTT Client(" + session.getSessionState().getClientId() + ") attempted to Ack already Ack'd message");
    }
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Message(org.apache.activemq.artemis.api.core.Message) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)

Example 9 with ActiveMQIllegalStateException

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

the class TransactionImpl method commit.

@Override
public void commit(final boolean onePhase) throws Exception {
    if (logger.isTraceEnabled()) {
        logger.trace("TransactionImpl::commit::" + this);
    }
    synchronized (timeoutLock) {
        if (state == State.COMMITTED) {
            // I don't think this could happen, but just in case
            logger.debug("TransactionImpl::commit::" + this + " is being ignored");
            return;
        }
        if (state == State.ROLLBACK_ONLY) {
            internalRollback();
            if (exception != null) {
                throw exception;
            } else {
                // Do nothing
                return;
            }
        }
        if (xid != null) {
            if (onePhase && state != State.ACTIVE || !onePhase && state != State.PREPARED) {
                throw new ActiveMQIllegalStateException("Transaction is in invalid state " + state);
            }
        } else {
            if (state != State.ACTIVE) {
                throw new ActiveMQIllegalStateException("Transaction is in invalid state " + state);
            }
        }
        beforeCommit();
        doCommit();
        // We want to make sure that nothing else gets done after the commit is issued
        // this will eliminate any possibility or races
        final List<TransactionOperation> operationsToComplete = this.operations;
        this.operations = null;
        // We use the Callback even for non persistence
        // If we are using non-persistence with replication, the replication manager will have
        // to execute this runnable in the correct order
        // This also will only use a different thread if there are any IO pending.
        // If the IO finished early by the time we got here, we won't need an executor
        storageManager.afterCompleteOperations(new IOCallback() {

            @Override
            public void onError(final int errorCode, final String errorMessage) {
                ActiveMQServerLogger.LOGGER.ioErrorOnTX(errorCode, errorMessage);
            }

            @Override
            public void done() {
                afterCommit(operationsToComplete);
            }
        });
        final List<TransactionOperation> storeOperationsToComplete = this.storeOperations;
        this.storeOperations = null;
        if (storeOperationsToComplete != null) {
            storageManager.afterStoreOperations(new IOCallback() {

                @Override
                public void onError(final int errorCode, final String errorMessage) {
                    ActiveMQServerLogger.LOGGER.ioErrorOnTX(errorCode, errorMessage);
                }

                @Override
                public void done() {
                    afterCommit(storeOperationsToComplete);
                }
            });
        }
    }
}
Also used : TransactionOperation(org.apache.activemq.artemis.core.transaction.TransactionOperation) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) IOCallback(org.apache.activemq.artemis.core.io.IOCallback)

Example 10 with ActiveMQIllegalStateException

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

the class ServerConsumerImpl method individualAcknowledge.

@Override
public synchronized void individualAcknowledge(Transaction tx, final long messageID) throws Exception {
    if (browseOnly) {
        return;
    }
    boolean startedTransaction = false;
    if (logger.isTraceEnabled()) {
        logger.trace("individualACK messageID=" + messageID);
    }
    if (tx == null) {
        if (logger.isTraceEnabled()) {
            logger.trace("individualACK starting new TX");
        }
        startedTransaction = true;
        tx = new TransactionImpl(storageManager);
    }
    try {
        MessageReference ref;
        ref = removeReferenceByID(messageID);
        if (logger.isTraceEnabled()) {
            logger.trace("ACKing ref " + ref + " on tx= " + tx + ", consumer=" + this);
        }
        if (ref == null) {
            ActiveMQIllegalStateException ils = new ActiveMQIllegalStateException("Cannot find ref to ack " + messageID);
            tx.markAsRollbackOnly(ils);
            throw ils;
        }
        ref.acknowledge(tx);
        acks++;
        if (startedTransaction) {
            tx.commit();
        }
    } catch (ActiveMQException e) {
        if (startedTransaction) {
            tx.rollback();
        } else {
            tx.markAsRollbackOnly(e);
        }
        throw e;
    } catch (Throwable e) {
        ActiveMQServerLogger.LOGGER.errorAckingMessage((Exception) e);
        ActiveMQIllegalStateException hqex = new ActiveMQIllegalStateException(e.getMessage());
        if (startedTransaction) {
            tx.rollback();
        } else {
            tx.markAsRollbackOnly(hqex);
        }
        throw hqex;
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)

Aggregations

ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)12 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)8 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 ActiveMQAlreadyReplicatingException (org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException)2 ActiveMQDisconnectedException (org.apache.activemq.artemis.api.core.ActiveMQDisconnectedException)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)2 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 MessageHandler (org.apache.activemq.artemis.api.core.client.MessageHandler)2 MessageReference (org.apache.activemq.artemis.core.server.MessageReference)2 TransactionImpl (org.apache.activemq.artemis.core.transaction.impl.TransactionImpl)2 Test (org.junit.Test)2 ObjectStreamException (java.io.ObjectStreamException)1 ByteBuffer (java.nio.ByteBuffer)1 Collection (java.util.Collection)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ActiveMQInternalErrorException (org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)1 ActiveMQInterruptedException (org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)1