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);
}
}
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class ClientSessionFactoryImpl method connectionDestroyed.
@Override
public void connectionDestroyed(final Object connectionID) {
// The exception has to be created in the same thread where it's being called
// as to avoid a different stack trace cause
final ActiveMQException ex = ActiveMQClientMessageBundle.BUNDLE.channelDisconnected();
// It has to use the same executor as the disconnect message is being sent through
closeExecutor.execute(new Runnable() {
@Override
public void run() {
handleConnectionFailure(connectionID, ex);
}
});
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class ClientSessionImpl method prepare.
@Override
public int prepare(final Xid xid) throws XAException {
checkXA();
if (logger.isTraceEnabled()) {
logger.trace("Calling prepare:: " + convert(xid));
}
if (rollbackOnly) {
throw new XAException(XAException.XAER_RMFAIL);
}
// Note - don't need to flush acks since the previous end would have
// done this
startCall();
try {
return sessionContext.xaPrepare(xid);
} catch (XAException xae) {
throw xae;
} catch (ActiveMQException e) {
if (e.getType() == ActiveMQExceptionType.UNBLOCKED || e.getType() == ActiveMQExceptionType.CONNECTION_TIMEDOUT) {
// Unblocked on failover
try {
// will retry once after failover & unblock
return sessionContext.xaPrepare(xid);
} catch (Throwable t) {
// ignore and rollback
}
ActiveMQClientLogger.LOGGER.failoverDuringPrepareRollingBack();
try {
rollback(false);
} catch (Throwable t) {
// This could occur if the TM interrupts the thread
XAException xaException = new XAException(XAException.XAER_RMFAIL);
xaException.initCause(t);
throw xaException;
}
ActiveMQClientLogger.LOGGER.errorDuringPrepare(e);
throw new XAException(XAException.XAER_RMFAIL);
}
ActiveMQClientLogger.LOGGER.errorDuringPrepare(e);
// This should never occur
XAException xaException = new XAException(XAException.XAER_RMFAIL);
xaException.initCause(e);
throw xaException;
} catch (Throwable t) {
ActiveMQClientLogger.LOGGER.errorDuringPrepare(t);
// This could occur if the TM interrupts the thread
XAException xaException = new XAException(XAException.XAER_RMFAIL);
xaException.initCause(t);
throw xaException;
} finally {
endCall();
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class LargeMessageControllerImpl method checkException.
/**
* @throws ActiveMQException
*/
private void checkException() throws ActiveMQException {
// once the exception is set, the controller is pretty much useless
if (handledException != null) {
if (handledException instanceof ActiveMQException) {
ActiveMQException nestedException;
// instead to just where it was canceled.
if (handledException instanceof ActiveMQLargeMessageInterruptedException) {
nestedException = new ActiveMQLargeMessageInterruptedException(handledException.getMessage());
} else {
nestedException = new ActiveMQException(((ActiveMQException) handledException).getType(), handledException.getMessage());
}
nestedException.initCause(handledException);
throw nestedException;
} else {
throw new ActiveMQException(ActiveMQExceptionType.LARGE_MESSAGE_ERROR_BODY, "Error on saving LargeMessageBufferImpl", handledException);
}
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class ServerLocatorImpl method initialise.
private synchronized void initialise() throws ActiveMQException {
if (state == STATE.INITIALIZED)
return;
synchronized (stateGuard) {
if (state == STATE.CLOSING)
throw new ActiveMQIllegalStateException();
try {
state = STATE.INITIALIZED;
latch = new CountDownLatch(1);
setThreadPools();
instantiateLoadBalancingPolicy();
if (discoveryGroupConfiguration != null) {
discoveryGroup = createDiscoveryGroup(nodeID, discoveryGroupConfiguration);
discoveryGroup.registerListener(this);
discoveryGroup.start();
}
} catch (Exception e) {
state = null;
throw ActiveMQClientMessageBundle.BUNDLE.failedToInitialiseSessionFactory(e);
}
}
}
Aggregations