Search in sources :

Example 1 with ActiveMQInterruptedException

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;
            }
        }
    }
}
Also used : ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)

Example 2 with ActiveMQInterruptedException

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);
        }
    }
}
Also used : ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 3 with ActiveMQInterruptedException

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;
}
Also used : ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) Lock(java.util.concurrent.locks.Lock)

Example 4 with ActiveMQInterruptedException

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;
        }
    }
}
Also used : ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)

Example 5 with ActiveMQInterruptedException

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;
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQExceptionMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ActiveMQExceptionMessage) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Aggregations

ActiveMQInterruptedException (org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)17 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)7 CountDownLatch (java.util.concurrent.CountDownLatch)3 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)2 IOException (java.io.IOException)1 ObjectStreamException (java.io.ObjectStreamException)1 Lock (java.util.concurrent.locks.Lock)1 BytesMessage (javax.jms.BytesMessage)1 IllegalStateException (javax.jms.IllegalStateException)1 InvalidDestinationException (javax.jms.InvalidDestinationException)1 JMSException (javax.jms.JMSException)1 MapMessage (javax.jms.MapMessage)1 ObjectMessage (javax.jms.ObjectMessage)1 StreamMessage (javax.jms.StreamMessage)1 TextMessage (javax.jms.TextMessage)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)1