use of org.apache.activemq.artemis.api.core.ActiveMQInterruptedException in project activemq-artemis by apache.
the class ClientSessionFactoryImpl method getConnectionWithRetry.
private void getConnectionWithRetry(final int reconnectAttempts) {
if (!clientProtocolManager.isAlive())
return;
if (logger.isTraceEnabled()) {
logger.trace("getConnectionWithRetry::" + reconnectAttempts + " with retryInterval = " + retryInterval + " multiplier = " + retryIntervalMultiplier, new Exception("trace"));
}
long interval = retryInterval;
int count = 0;
while (clientProtocolManager.isAlive()) {
if (logger.isDebugEnabled()) {
logger.debug("Trying reconnection attempt " + count + "/" + reconnectAttempts);
}
if (getConnection() != null) {
if (logger.isDebugEnabled()) {
logger.debug("Reconnection successful");
}
return;
} else {
if (reconnectAttempts != 0) {
count++;
if (reconnectAttempts != -1 && count == reconnectAttempts) {
if (reconnectAttempts != 1) {
ActiveMQClientLogger.LOGGER.failedToConnectToServer(reconnectAttempts);
}
return;
}
if (ClientSessionFactoryImpl.logger.isTraceEnabled()) {
ClientSessionFactoryImpl.logger.trace("Waiting " + interval + " milliseconds before next retry. RetryInterval=" + retryInterval + " and multiplier=" + retryIntervalMultiplier);
}
try {
if (clientProtocolManager.waitOnLatch(interval)) {
return;
}
} catch (InterruptedException ignore) {
throw new ActiveMQInterruptedException(createTrace);
}
// Exponential back-off
long newInterval = (long) (interval * retryIntervalMultiplier);
if (newInterval > maxRetryInterval) {
newInterval = maxRetryInterval;
}
interval = newInterval;
} else {
logger.debug("Could not connect to any server. Didn't have reconnection configured on the ClientSessionFactory");
return;
}
}
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQInterruptedException in project activemq-artemis by apache.
the class DiscoveryGroup method stop.
@Override
public void stop() {
synchronized (this) {
if (!started) {
return;
}
started = false;
}
synchronized (waitLock) {
waitLock.notifyAll();
}
try {
endpoint.close(false);
} catch (Exception e1) {
ActiveMQClientLogger.LOGGER.errorStoppingDiscoveryBroadcastEndpoint(endpoint, e1);
}
try {
if (thread != null) {
thread.interrupt();
thread.join(10000);
if (thread.isAlive()) {
ActiveMQClientLogger.LOGGER.timedOutStoppingDiscovery();
}
}
} catch (InterruptedException e) {
throw new ActiveMQInterruptedException(e);
}
thread = null;
if (notificationService != null) {
TypedProperties props = new TypedProperties();
props.putSimpleStringProperty(new SimpleString("name"), new SimpleString(name));
Notification notification = new Notification(nodeID, CoreNotificationType.DISCOVERY_GROUP_STOPPED, props);
try {
notificationService.sendNotification(notification);
} catch (Exception e) {
ActiveMQClientLogger.LOGGER.errorSendingNotifOnDiscoveryStop(e);
}
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQInterruptedException in project activemq-artemis by apache.
the class ActiveMQClientProtocolManager method cleanupBeforeFailover.
@Override
public boolean cleanupBeforeFailover(ActiveMQException cause) {
boolean needToInterrupt;
CountDownLatch exitLockLatch;
Lock lock = lockSessionCreation();
if (lock == null) {
return false;
}
try {
synchronized (inCreateSessionGuard) {
needToInterrupt = inCreateSession;
exitLockLatch = inCreateSessionLatch;
}
} finally {
lock.unlock();
}
if (needToInterrupt) {
forceReturnChannel1(cause);
while (inCreateSession && isAlive()) {
try {
if (exitLockLatch != null) {
exitLockLatch.await(500, TimeUnit.MILLISECONDS);
}
} catch (InterruptedException e1) {
throw new ActiveMQInterruptedException(e1);
}
}
}
return true;
}
use of org.apache.activemq.artemis.api.core.ActiveMQInterruptedException in project activemq-artemis by apache.
the class ActiveMQClient method clearThreadPools.
public static synchronized void clearThreadPools(long time, TimeUnit unit) {
if (injectedPools) {
globalThreadPool = null;
globalScheduledThreadPool = null;
injectedPools = false;
return;
}
if (globalThreadPool != null) {
globalThreadPool.shutdownNow();
try {
if (!globalThreadPool.awaitTermination(time, unit)) {
globalThreadPool.shutdownNow();
ActiveMQClientLogger.LOGGER.unableToProcessGlobalThreadPoolIn10Sec();
}
} catch (InterruptedException e) {
throw new ActiveMQInterruptedException(e);
} finally {
globalThreadPool = null;
}
}
if (globalScheduledThreadPool != null) {
globalScheduledThreadPool.shutdownNow();
try {
if (!globalScheduledThreadPool.awaitTermination(time, unit)) {
globalScheduledThreadPool.shutdownNow();
ActiveMQClientLogger.LOGGER.unableToProcessScheduledlIn10Sec();
}
} catch (InterruptedException e) {
throw new ActiveMQInterruptedException(e);
} finally {
globalScheduledThreadPool = null;
}
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQInterruptedException in project activemq-artemis by apache.
the class ChannelImpl method sendBlocking.
/**
* Due to networking issues or server issues the server may take longer to answer than expected.. the client may timeout the call throwing an exception
* and the client could eventually retry another call, but the server could then answer a previous command issuing a class-cast-exception.
* The expectedPacket will be used to filter out undesirable packets that would belong to previous calls.
*/
@Override
public Packet sendBlocking(final Packet packet, final int reconnectID, byte expectedPacket) throws ActiveMQException {
String interceptionResult = invokeInterceptors(packet, interceptors, connection);
if (interceptionResult != null) {
if (logger.isTraceEnabled()) {
logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " interceptionResult=" + interceptionResult);
}
// if we don't throw an exception here the client might not unblock
throw ActiveMQClientMessageBundle.BUNDLE.interceptorRejectedPacket(interceptionResult);
}
if (closed) {
if (logger.isTraceEnabled()) {
logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " closed.");
}
throw ActiveMQClientMessageBundle.BUNDLE.connectionDestroyed();
}
if (connection.getBlockingCallTimeout() == -1) {
if (logger.isTraceEnabled()) {
logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " Cannot do a blocking call timeout on a server side connection");
}
throw new IllegalStateException("Cannot do a blocking call timeout on a server side connection");
}
// E.g. blocking acknowledge() from inside a message handler at some time as other operation on main thread
synchronized (sendBlockingLock) {
packet.setChannelID(id);
final ActiveMQBuffer buffer = packet.encode(connection);
lock.lock();
try {
if (failingOver) {
waitForFailOver("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " timed-out waiting for fail-over condition on blocking send");
}
response = null;
if (resendCache != null && packet.isRequiresConfirmations()) {
addResendPacket(packet);
}
checkReconnectID(reconnectID);
if (logger.isTraceEnabled()) {
logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " Sending blocking " + packet);
}
connection.getTransportConnection().write(buffer, false, false);
long toWait = connection.getBlockingCallTimeout();
long start = System.currentTimeMillis();
while (!closed && (response == null || (response.getType() != PacketImpl.EXCEPTION && response.getType() != expectedPacket)) && toWait > 0) {
try {
sendCondition.await(toWait, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new ActiveMQInterruptedException(e);
}
if (response != null && response.getType() != PacketImpl.EXCEPTION && response.getType() != expectedPacket) {
ActiveMQClientLogger.LOGGER.packetOutOfOrder(response, new Exception("trace"));
}
if (closed) {
break;
}
final long now = System.currentTimeMillis();
toWait -= now - start;
start = now;
}
if (closed && toWait > 0 && response == null) {
Throwable cause = ActiveMQClientMessageBundle.BUNDLE.connectionDestroyed();
throw ActiveMQClientMessageBundle.BUNDLE.unblockingACall(cause);
}
if (response == null) {
throw ActiveMQClientMessageBundle.BUNDLE.timedOutSendingPacket(connection.getBlockingCallTimeout(), packet.getType());
}
if (response.getType() == PacketImpl.EXCEPTION) {
final ActiveMQExceptionMessage mem = (ActiveMQExceptionMessage) response;
ActiveMQException e = mem.getException();
e.fillInStackTrace();
throw e;
}
} finally {
lock.unlock();
}
return response;
}
}
Aggregations