Search in sources :

Example 6 with ActiveMQInterruptedException

use of org.apache.activemq.artemis.api.core.ActiveMQInterruptedException in project activemq-artemis by apache.

the class TimedBuffer method start.

public void start() {
    enterCritical(CRITICAL_PATH_START);
    try {
        synchronized (this) {
            if (started) {
                return;
            }
            // Need to start with the spin limiter acquired
            try {
                spinLimiter.acquire();
            } catch (InterruptedException e) {
                throw new ActiveMQInterruptedException(e);
            }
            timerRunnable = new CheckTimer();
            timerThread = new Thread(timerRunnable, "activemq-buffer-timeout");
            timerThread.start();
            if (logRates) {
                logRatesTimerTask = new LogRatesTimerTask();
                logRatesTimer.scheduleAtFixedRate(logRatesTimerTask, 2000, 2000);
            }
            started = true;
        }
    } finally {
        leaveCritical(CRITICAL_PATH_START);
    }
}
Also used : ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)

Example 7 with ActiveMQInterruptedException

use of org.apache.activemq.artemis.api.core.ActiveMQInterruptedException in project activemq-artemis by apache.

the class ActiveMQMessageProducer method doSendx.

private void doSendx(ActiveMQDestination destination, final Message jmsMessage, final int deliveryMode, final int priority, final long timeToLive, CompletionListener completionListener) throws JMSException {
    jmsMessage.setJMSDeliveryMode(deliveryMode);
    jmsMessage.setJMSPriority(priority);
    if (timeToLive == 0) {
        jmsMessage.setJMSExpiration(0);
    } else {
        jmsMessage.setJMSExpiration(System.currentTimeMillis() + timeToLive);
    }
    if (!disableMessageTimestamp) {
        jmsMessage.setJMSTimestamp(System.currentTimeMillis());
    } else {
        jmsMessage.setJMSTimestamp(0);
    }
    SimpleString address = null;
    if (destination == null) {
        if (defaultDestination == null) {
            throw new UnsupportedOperationException("Destination must be specified on send with an anonymous producer");
        }
        destination = defaultDestination;
    } else {
        if (defaultDestination != null) {
            if (!destination.equals(defaultDestination)) {
                throw new UnsupportedOperationException("Where a default destination is specified " + "for the sender and a destination is " + "specified in the arguments to the send, " + "these destinations must be equal");
            }
        }
        address = destination.getSimpleAddress();
        if (!connection.containsKnownDestination(address)) {
            try {
                ClientSession.AddressQuery query = clientSession.addressQuery(address);
                if (!query.isExists()) {
                    if (destination.isQueue() && query.isAutoCreateQueues()) {
                        clientSession.createAddress(address, RoutingType.ANYCAST, true);
                        if (destination.isTemporary()) {
                            // TODO is it right to use the address for the queue name here?
                            clientSession.createTemporaryQueue(address, RoutingType.ANYCAST, address);
                        } else {
                            createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query.getDefaultMaxConsumers(), query.isDefaultPurgeOnNoConsumers(), query.isDefaultExclusive(), query.isDefaultLastValueQueue());
                        }
                    } else if (!destination.isQueue() && query.isAutoCreateAddresses()) {
                        clientSession.createAddress(address, RoutingType.MULTICAST, true);
                    } else if ((destination.isQueue() && !query.isAutoCreateQueues()) || (!destination.isQueue() && !query.isAutoCreateAddresses())) {
                        throw new InvalidDestinationException("Destination " + address + " does not exist");
                    }
                } else {
                    ClientSession.QueueQuery queueQuery = clientSession.queueQuery(address);
                    if (queueQuery.isExists()) {
                        connection.addKnownDestination(address);
                    } else if (destination.isQueue() && query.isAutoCreateQueues()) {
                        if (destination.isTemporary()) {
                            clientSession.createTemporaryQueue(address, RoutingType.ANYCAST, address);
                        } else {
                            createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query.getDefaultMaxConsumers(), query.isDefaultPurgeOnNoConsumers(), query.isDefaultExclusive(), query.isDefaultLastValueQueue());
                        }
                    }
                }
            } catch (ActiveMQQueueExistsException e) {
            // The queue was created by another client/admin between the query check and send create queue packet
            } catch (ActiveMQException e) {
                throw JMSExceptionHelper.convertFromActiveMQException(e);
            }
        }
    }
    ActiveMQMessage activeMQJmsMessage;
    boolean foreign = false;
    // First convert from foreign message if appropriate
    if (!(jmsMessage instanceof ActiveMQMessage)) {
        if (jmsMessage instanceof BytesMessage) {
            activeMQJmsMessage = new ActiveMQBytesMessage((BytesMessage) jmsMessage, clientSession);
        } else if (jmsMessage instanceof MapMessage) {
            activeMQJmsMessage = new ActiveMQMapMessage((MapMessage) jmsMessage, clientSession);
        } else if (jmsMessage instanceof ObjectMessage) {
            activeMQJmsMessage = new ActiveMQObjectMessage((ObjectMessage) jmsMessage, clientSession, options);
        } else if (jmsMessage instanceof StreamMessage) {
            activeMQJmsMessage = new ActiveMQStreamMessage((StreamMessage) jmsMessage, clientSession);
        } else if (jmsMessage instanceof TextMessage) {
            activeMQJmsMessage = new ActiveMQTextMessage((TextMessage) jmsMessage, clientSession);
        } else {
            activeMQJmsMessage = new ActiveMQMessage(jmsMessage, clientSession);
        }
        // Set the destination on the original message
        jmsMessage.setJMSDestination(destination);
        foreign = true;
    } else {
        activeMQJmsMessage = (ActiveMQMessage) jmsMessage;
    }
    if (!disableMessageID) {
        // Generate a JMS id
        UUID uid = UUIDGenerator.getInstance().generateUUID();
        activeMQJmsMessage.getCoreMessage().setUserID(uid);
        activeMQJmsMessage.resetMessageID(null);
    }
    if (foreign) {
        jmsMessage.setJMSMessageID(activeMQJmsMessage.getJMSMessageID());
    }
    activeMQJmsMessage.setJMSDestination(destination);
    try {
        activeMQJmsMessage.doBeforeSend();
    } catch (Exception e) {
        JMSException je = new JMSException(e.getMessage());
        je.initCause(e);
        throw je;
    }
    if (defaultDeliveryDelay > 0) {
        activeMQJmsMessage.setJMSDeliveryTime(System.currentTimeMillis() + defaultDeliveryDelay);
    }
    ClientMessage coreMessage = activeMQJmsMessage.getCoreMessage();
    coreMessage.putStringProperty(ActiveMQConnection.CONNECTION_ID_PROPERTY_NAME, connID);
    coreMessage.setRoutingType(destination.isQueue() ? RoutingType.ANYCAST : RoutingType.MULTICAST);
    try {
        /**
         * Using a completionListener requires wrapping using a {@link CompletionListenerWrapper},
         * so we avoid it if we can.
         */
        if (completionListener != null) {
            clientProducer.send(address, coreMessage, new CompletionListenerWrapper(completionListener, jmsMessage, this));
        } else {
            clientProducer.send(address, coreMessage);
        }
    } catch (ActiveMQInterruptedException e) {
        JMSException jmsException = new JMSException(e.getMessage());
        jmsException.initCause(e);
        throw jmsException;
    } catch (ActiveMQException e) {
        throw JMSExceptionHelper.convertFromActiveMQException(e);
    } catch (java.lang.IllegalStateException e) {
        JMSException je = new IllegalStateException(e.getMessage());
        je.setStackTrace(e.getStackTrace());
        je.initCause(e);
        throw je;
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) MapMessage(javax.jms.MapMessage) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) BytesMessage(javax.jms.BytesMessage) JMSException(javax.jms.JMSException) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ObjectMessage(javax.jms.ObjectMessage) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) UUID(org.apache.activemq.artemis.utils.UUID) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InvalidDestinationException(javax.jms.InvalidDestinationException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) InvalidDestinationException(javax.jms.InvalidDestinationException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) IllegalStateException(javax.jms.IllegalStateException) JMSException(javax.jms.JMSException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) StreamMessage(javax.jms.StreamMessage) TextMessage(javax.jms.TextMessage)

Example 8 with ActiveMQInterruptedException

use of org.apache.activemq.artemis.api.core.ActiveMQInterruptedException in project activemq-artemis by apache.

the class LargeMessageControllerImpl method waitCompletion.

/**
 * @param timeWait Milliseconds to Wait. 0 means forever
 * @throws ActiveMQException
 */
@Override
public synchronized boolean waitCompletion(final long timeWait) throws ActiveMQException {
    if (outStream == null) {
        // There is no stream.. it will never achieve the end of streaming
        return false;
    }
    long timeOut;
    // And we will check if no packets have arrived within readTimeout milliseconds
    if (timeWait != 0) {
        timeOut = System.currentTimeMillis() + timeWait;
    } else {
        timeOut = System.currentTimeMillis() + readTimeout;
    }
    while (!streamEnded && handledException == null) {
        try {
            this.wait(timeWait == 0 ? readTimeout : timeWait);
        } catch (InterruptedException e) {
            throw new ActiveMQInterruptedException(e);
        }
        if (!streamEnded && handledException == null) {
            if (timeWait != 0 && System.currentTimeMillis() > timeOut) {
                throw ActiveMQClientMessageBundle.BUNDLE.timeoutOnLargeMessage();
            } else if (System.currentTimeMillis() > timeOut && !packetAdded) {
                throw ActiveMQClientMessageBundle.BUNDLE.timeoutOnLargeMessage();
            }
        }
    }
    checkException();
    return streamEnded;
}
Also used : ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQLargeMessageInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQLargeMessageInterruptedException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)

Example 9 with ActiveMQInterruptedException

use of org.apache.activemq.artemis.api.core.ActiveMQInterruptedException in project activemq-artemis by apache.

the class ServerLocatorImpl method doClose.

private void doClose(final boolean sendClose) {
    synchronized (stateGuard) {
        if (state == STATE.CLOSED) {
            if (logger.isDebugEnabled()) {
                logger.debug(this + " is already closed when calling closed");
            }
            return;
        }
        state = STATE.CLOSING;
    }
    if (latch != null)
        latch.countDown();
    synchronized (connectingFactories) {
        for (ClientSessionFactoryInternal csf : connectingFactories) {
            csf.causeExit();
        }
    }
    if (discoveryGroup != null) {
        synchronized (this) {
            try {
                discoveryGroup.stop();
            } catch (Exception e) {
                ActiveMQClientLogger.LOGGER.failedToStopDiscovery(e);
            }
        }
    } else {
        staticConnector.disconnect();
    }
    synchronized (connectingFactories) {
        for (ClientSessionFactoryInternal csf : connectingFactories) {
            csf.causeExit();
        }
        for (ClientSessionFactoryInternal csf : connectingFactories) {
            csf.close();
        }
        connectingFactories.clear();
    }
    Set<ClientSessionFactoryInternal> clonedFactory;
    synchronized (factories) {
        clonedFactory = new HashSet<>(factories);
        factories.clear();
    }
    for (ClientSessionFactoryInternal factory : clonedFactory) {
        factory.causeExit();
    }
    for (ClientSessionFactory factory : clonedFactory) {
        if (sendClose) {
            try {
                factory.close();
            } catch (Throwable e) {
                logger.debug(e.getMessage(), e);
                factory.cleanup();
            }
        } else {
            factory.cleanup();
        }
    }
    if (shutdownPool) {
        if (threadPool != null) {
            threadPool.shutdown();
            try {
                if (!threadPool.awaitTermination(10000, TimeUnit.MILLISECONDS)) {
                    ActiveMQClientLogger.LOGGER.timedOutWaitingForTermination();
                }
            } catch (InterruptedException e) {
                throw new ActiveMQInterruptedException(e);
            }
        }
        if (scheduledThreadPool != null) {
            scheduledThreadPool.shutdown();
            try {
                if (!scheduledThreadPool.awaitTermination(10000, TimeUnit.MILLISECONDS)) {
                    ActiveMQClientLogger.LOGGER.timedOutWaitingForScheduledPoolTermination();
                }
            } catch (InterruptedException e) {
                throw new ActiveMQInterruptedException(e);
            }
        }
    }
    synchronized (stateGuard) {
        state = STATE.CLOSED;
    }
}
Also used : ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ObjectStreamException(java.io.ObjectStreamException)

Example 10 with ActiveMQInterruptedException

use of org.apache.activemq.artemis.api.core.ActiveMQInterruptedException in project activemq-artemis by apache.

the class DiscoveryGroup method waitForBroadcast.

public boolean waitForBroadcast(final long timeout) {
    synchronized (waitLock) {
        long start = System.currentTimeMillis();
        long toWait = timeout;
        while (started && !received && (toWait > 0 || timeout == 0)) {
            try {
                waitLock.wait(toWait);
            } catch (InterruptedException e) {
                throw new ActiveMQInterruptedException(e);
            }
            if (timeout != 0) {
                long now = System.currentTimeMillis();
                toWait -= now - start;
                start = now;
            }
        }
        boolean ret = received;
        received = false;
        return ret;
    }
}
Also used : ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException)

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