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