Search in sources :

Example 41 with IllegalStateException

use of javax.jms.IllegalStateException in project activemq-artemis by apache.

the class AmqpTransactionCoordinator method declare.

public void declare(AmqpTransactionId txId, AsyncResult request) throws Exception {
    if (txId.getRemoteTxId() != null) {
        throw new IllegalStateException("Declare called while a TX is still Active.");
    }
    if (isClosed()) {
        request.onFailure(new JMSException("Cannot start new transaction: Coordinator remotely closed"));
        return;
    }
    Message message = Message.Factory.create();
    Declare declare = new Declare();
    message.setBody(new AmqpValue(declare));
    Delivery pendingDelivery = getEndpoint().delivery(tagGenerator.getNextTag());
    pendingDelivery.setContext(txId);
    // Store away for completion
    pendingDeliveries.add(pendingDelivery);
    pendingRequests.put(txId, request);
    sendTxCommand(message);
}
Also used : IllegalStateException(javax.jms.IllegalStateException) Message(org.apache.qpid.proton.message.Message) JMSException(javax.jms.JMSException) Delivery(org.apache.qpid.proton.engine.Delivery) Declare(org.apache.qpid.proton.amqp.transaction.Declare) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue)

Example 42 with IllegalStateException

use of javax.jms.IllegalStateException in project activemq-artemis by apache.

the class AmqpTransactionCoordinator method processDeliveryUpdates.

@Override
public void processDeliveryUpdates(AmqpConnection connection, Delivery delivery) throws IOException {
    try {
        Iterator<Delivery> deliveries = pendingDeliveries.iterator();
        while (deliveries.hasNext()) {
            Delivery pendingDelivery = deliveries.next();
            if (!pendingDelivery.remotelySettled()) {
                continue;
            }
            DeliveryState state = pendingDelivery.getRemoteState();
            AmqpTransactionId txId = (AmqpTransactionId) pendingDelivery.getContext();
            AsyncResult pendingRequest = pendingRequests.get(txId);
            if (pendingRequest == null) {
                throw new IllegalStateException("Pending tx operation with no pending request");
            }
            if (state instanceof Declared) {
                LOG.debug("New TX started: {}", txId.getTxId());
                Declared declared = (Declared) state;
                txId.setRemoteTxId(declared.getTxnId());
                pendingRequest.onSuccess();
            } else if (state instanceof Rejected) {
                LOG.debug("Last TX request failed: {}", txId.getTxId());
                Rejected rejected = (Rejected) state;
                Exception cause = AmqpSupport.convertToException(rejected.getError());
                JMSException failureCause = null;
                if (txId.isCommit()) {
                    failureCause = new TransactionRolledBackException(cause.getMessage());
                } else {
                    failureCause = new JMSException(cause.getMessage());
                }
                pendingRequest.onFailure(failureCause);
            } else {
                LOG.debug("Last TX request succeeded: {}", txId.getTxId());
                pendingRequest.onSuccess();
            }
            // Clear state data
            pendingDelivery.settle();
            pendingRequests.remove(txId);
            deliveries.remove();
        }
        super.processDeliveryUpdates(connection, delivery);
    } catch (Exception e) {
        throw IOExceptionSupport.create(e);
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState) JMSException(javax.jms.JMSException) TransactionRolledBackException(javax.jms.TransactionRolledBackException) Delivery(org.apache.qpid.proton.engine.Delivery) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) AsyncResult(org.apache.activemq.transport.amqp.client.util.AsyncResult) Declared(org.apache.qpid.proton.amqp.transaction.Declared) BufferOverflowException(java.nio.BufferOverflowException) IOException(java.io.IOException) IllegalStateException(javax.jms.IllegalStateException) JMSException(javax.jms.JMSException) TransactionRolledBackException(javax.jms.TransactionRolledBackException)

Example 43 with IllegalStateException

use of javax.jms.IllegalStateException in project BroadleafCommerce by BroadleafCommerce.

the class SolrHelperServiceImpl method swapActiveCores.

/**
 * This should only ever be called when using the Solr reindex service to do a full reindex.
 * @throws SecurityException
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 */
@Override
public synchronized void swapActiveCores(SolrConfiguration solrConfiguration) throws ServiceException {
    if (!isSolrConfigured) {
        return;
    }
    if (CloudSolrClient.class.isAssignableFrom(solrConfiguration.getServer().getClass()) && CloudSolrClient.class.isAssignableFrom(solrConfiguration.getReindexServer().getClass())) {
        CloudSolrClient primaryCloudClient = (CloudSolrClient) solrConfiguration.getServer();
        CloudSolrClient reindexCloudClient = (CloudSolrClient) solrConfiguration.getReindexServer();
        try {
            primaryCloudClient.connect();
            Aliases aliases = primaryCloudClient.getZkStateReader().getAliases();
            Map<String, String> aliasCollectionMap = aliases.getCollectionAliasMap();
            if (aliasCollectionMap == null || !aliasCollectionMap.containsKey(primaryCloudClient.getDefaultCollection()) || !aliasCollectionMap.containsKey(reindexCloudClient.getDefaultCollection())) {
                throw new IllegalStateException("Could not determine the PRIMARY or REINDEX " + "collection or collections from the Solr aliases.");
            }
            String primaryCollectionName = aliasCollectionMap.get(primaryCloudClient.getDefaultCollection());
            // Do this just in case primary is aliased to more than one collection
            primaryCollectionName = primaryCollectionName.split(",")[0];
            String reindexCollectionName = aliasCollectionMap.get(reindexCloudClient.getDefaultCollection());
            // Do this just in case primary is aliased to more than one collection
            reindexCollectionName = reindexCollectionName.split(",")[0];
            // Essentially "swap cores" here by reassigning the aliases
            new CollectionAdminRequest.CreateAlias().setAliasName(primaryCloudClient.getDefaultCollection()).setAliasedCollections(reindexCollectionName).process(primaryCloudClient);
            new CollectionAdminRequest.CreateAlias().setAliasName(reindexCloudClient.getDefaultCollection()).setAliasedCollections(primaryCollectionName).process(reindexCloudClient);
        } catch (Exception e) {
            LOG.error("An exception occured swapping cores.", e);
            throw new ServiceException("Unable to swap SolrCloud collections after a full reindex.", e);
        }
    } else {
        if (solrConfiguration.getReindexServer() == null || solrConfiguration.getServer() == solrConfiguration.getReindexServer()) {
            LOG.debug("In single core mode. There are no cores to swap.");
        } else {
            LOG.debug("Swapping active cores");
            String primaryCoreName = solrConfiguration.getPrimaryName();
            String reindexCoreName = solrConfiguration.getReindexName();
            if (!StringUtils.isEmpty(primaryCoreName) && !StringUtils.isEmpty(reindexCoreName)) {
                CoreAdminRequest car = new CoreAdminRequest();
                car.setCoreName(primaryCoreName);
                car.setOtherCoreName(reindexCoreName);
                car.setAction(CoreAdminAction.SWAP);
                try {
                    solrConfiguration.getAdminServer().request(car);
                } catch (Exception e) {
                    LOG.error(e);
                    throw new ServiceException("Unable to swap cores", e);
                }
            } else {
                LOG.error("Could not determine core names for the Solr Clients provided");
                throw new ServiceException("Unable to swap cores");
            }
        }
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) ServiceException(org.broadleafcommerce.common.exception.ServiceException) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) CoreAdminRequest(org.apache.solr.client.solrj.request.CoreAdminRequest) Aliases(org.apache.solr.common.cloud.Aliases) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ServiceException(org.broadleafcommerce.common.exception.ServiceException) IllegalStateException(javax.jms.IllegalStateException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 44 with IllegalStateException

use of javax.jms.IllegalStateException in project aries by apache.

the class ConnectionPool method createSession.

public Session createSession(boolean transacted, int ackMode) throws JMSException {
    SessionKey key = new SessionKey(transacted, ackMode);
    PooledSession session;
    try {
        session = sessionPool.borrowObject(key);
    } catch (Exception e) {
        javax.jms.IllegalStateException illegalStateException = new IllegalStateException(e.toString());
        illegalStateException.initCause(e);
        throw illegalStateException;
    }
    return session;
}
Also used : IllegalStateException(javax.jms.IllegalStateException) IllegalStateException(javax.jms.IllegalStateException) JMSException(javax.jms.JMSException)

Aggregations

IllegalStateException (javax.jms.IllegalStateException)44 Session (javax.jms.Session)19 Connection (javax.jms.Connection)12 QueueSession (javax.jms.QueueSession)12 Test (org.junit.Test)12 TopicSession (javax.jms.TopicSession)11 XAQueueSession (javax.jms.XAQueueSession)11 XATopicSession (javax.jms.XATopicSession)11 ActiveMQSession (org.apache.activemq.artemis.jms.client.ActiveMQSession)11 JMSException (javax.jms.JMSException)10 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 InvalidDestinationException (javax.jms.InvalidDestinationException)5 IOException (java.io.IOException)4 Queue (javax.jms.Queue)3 QueueBrowser (javax.jms.QueueBrowser)3 TopicSubscriber (javax.jms.TopicSubscriber)3 QueueQuery (org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery)3 RMQJMSException (com.rabbitmq.jms.util.RMQJMSException)2 TemporaryQueue (javax.jms.TemporaryQueue)2