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();
}
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();
}
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");
}
}
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);
}
});
}
}
}
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;
}
}
Aggregations