use of org.apache.activemq.artemis.api.core.ActiveMQException in project candlepin by candlepin.
the class EventSinkImpl method rollback.
@Override
public void rollback() {
log.warn("Rolling back ActiveMQ transaction.");
try {
ClientSession session = getClientSession();
session.rollback();
} catch (ActiveMQException e) {
log.error("Error rolling back ActiveMQ transaction", e);
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project candlepin by candlepin.
the class EventSource method registerListener.
void registerListener(EventListener listener) {
String queueName = QUEUE_ADDRESS + "." + listener.getClass().getCanonicalName();
log.debug("registering listener for {}", queueName);
try {
try {
// Create a durable queue that will be persisted to disk:
session.createQueue(QUEUE_ADDRESS, queueName, true);
log.debug("created new event queue " + queueName);
} catch (ActiveMQException e) {
// so that's fine.
if (e.getType() != ActiveMQExceptionType.QUEUE_EXISTS) {
throw e;
}
}
ClientConsumer consumer = session.createConsumer(queueName);
consumer.setMessageHandler(new ListenerWrapper(listener, mapper));
} catch (ActiveMQException e) {
log.error("Unable to register listener :" + listener, e);
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project candlepin by candlepin.
the class EventSinkImplTest method eventSinkShouldThrowExceptionWhenSessionCreationFailsInConstructor.
/**
*Set up the {@link ClientSessionFactory} to throw an exception when
* {@link ClientSessionFactory#createSession()} is called.
* Make sure, we throw up our hands saying "I am not dealing with this".
* @throws Exception
*/
@Test(expected = RuntimeException.class)
public void eventSinkShouldThrowExceptionWhenSessionCreationFailsInConstructor() throws Exception {
final ClientSessionFactory csFactory = mock(ClientSessionFactory.class);
doThrow(new ActiveMQException()).when(csFactory.createSession());
createEventSink(csFactory);
fail("Runtime exception should have been thrown.");
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class ClientSessionFactoryImpl method getConnection.
@Override
public RemotingConnection getConnection() {
if (closed)
throw new IllegalStateException("ClientSessionFactory is closed!");
if (!clientProtocolManager.isAlive())
return null;
synchronized (connectionLock) {
if (connection != null) {
// a connection already exists, so returning the same one
return connection;
} else {
RemotingConnection connection = establishNewConnection();
this.connection = connection;
// make sure to reset this.connection == null
if (connection != null && liveNodeID != null) {
try {
if (!clientProtocolManager.checkForFailover(liveNodeID)) {
connection.destroy();
this.connection = null;
return null;
}
} catch (ActiveMQException e) {
connection.destroy();
this.connection = null;
return null;
}
}
if (connection != null && serverLocator.getAfterConnectInternalListener() != null) {
serverLocator.getAfterConnectInternalListener().onConnection(this);
}
if (serverLocator.getTopology() != null) {
if (connection != null) {
if (ClientSessionFactoryImpl.logger.isTraceEnabled()) {
logger.trace(this + "::Subscribing Topology");
}
clientProtocolManager.sendSubscribeTopology(serverLocator.isClusterConnection());
}
} else {
logger.debug("serverLocator@" + System.identityHashCode(serverLocator + " had no topology"));
}
return connection;
}
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class ClientSessionFactoryImpl method failoverOrReconnect.
/**
* TODO: Maybe this belongs to ActiveMQClientProtocolManager
*
* @param connectionID
* @param me
*/
private void failoverOrReconnect(final Object connectionID, final ActiveMQException me, String scaleDownTargetNodeID) {
ActiveMQClientLogger.LOGGER.failoverOrReconnect(connectionID, me);
for (ClientSessionInternal session : sessions) {
SessionContext context = session.getSessionContext();
if (context instanceof ActiveMQSessionContext) {
ActiveMQSessionContext sessionContext = (ActiveMQSessionContext) context;
if (sessionContext.isKilled()) {
setReconnectAttempts(0);
}
}
}
Set<ClientSessionInternal> sessionsToClose = null;
if (!clientProtocolManager.isAlive())
return;
Lock localFailoverLock = lockFailover();
try {
if (connection == null || !connection.getID().equals(connectionID) || !clientProtocolManager.isAlive()) {
return;
}
if (ClientSessionFactoryImpl.logger.isTraceEnabled()) {
logger.trace("Client Connection failed, calling failure listeners and trying to reconnect, reconnectAttempts=" + reconnectAttempts);
}
callFailoverListeners(FailoverEventType.FAILURE_DETECTED);
// We call before reconnection occurs to give the user a chance to do cleanup, like cancel messages
callSessionFailureListeners(me, false, false, scaleDownTargetNodeID);
if (reconnectAttempts != 0) {
if (clientProtocolManager.cleanupBeforeFailover(me)) {
// Now we absolutely know that no threads are executing in or blocked in
// createSession,
// and no
// more will execute it until failover is complete
// So.. do failover / reconnection
RemotingConnection oldConnection = connection;
connection = null;
Connector localConnector = connector;
if (localConnector != null) {
try {
localConnector.close();
} catch (Exception ignore) {
// no-op
}
}
cancelScheduledTasks();
connector = null;
reconnectSessions(oldConnection, reconnectAttempts, me);
if (oldConnection != null) {
oldConnection.destroy();
}
if (connection != null) {
callFailoverListeners(FailoverEventType.FAILOVER_COMPLETED);
}
}
} else {
RemotingConnection connectionToDestory = connection;
if (connectionToDestory != null) {
connectionToDestory.destroy();
}
connection = null;
}
if (connection == null) {
synchronized (sessions) {
sessionsToClose = new HashSet<>(sessions);
}
callFailoverListeners(FailoverEventType.FAILOVER_FAILED);
callSessionFailureListeners(me, true, false, scaleDownTargetNodeID);
}
} finally {
localFailoverLock.unlock();
}
// This needs to be outside the failover lock to prevent deadlock
if (connection != null) {
callSessionFailureListeners(me, true, true);
}
if (sessionsToClose != null) {
for (ClientSessionInternal session : sessionsToClose) {
try {
session.cleanUp(true);
} catch (Exception cause) {
ActiveMQClientLogger.LOGGER.failedToCleanupSession(cause);
}
}
}
}
Aggregations