Search in sources :

Example 26 with ActiveMQException

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

the class ClusterControl method announceReplicatingBackupToLive.

/**
 * XXX HORNETQ-720
 *
 * @param attemptingFailBack if {@code true} then this server wants to trigger a fail-back when
 *                           up-to-date, that is it wants to take over the role of 'live' from the current 'live'
 *                           server.
 * @throws ActiveMQException
 */
public void announceReplicatingBackupToLive(final boolean attemptingFailBack, String replicationClusterName) throws ActiveMQException {
    ClusterConnectionConfiguration config = ConfigurationUtils.getReplicationClusterConfiguration(server.getConfiguration(), replicationClusterName);
    if (config == null) {
        ActiveMQServerLogger.LOGGER.announceBackupNoClusterConnections();
        throw new ActiveMQException("lacking cluster connection");
    }
    TransportConfiguration connector = server.getConfiguration().getConnectorConfigurations().get(config.getConnectorName());
    if (connector == null) {
        ActiveMQServerLogger.LOGGER.announceBackupNoConnector(config.getConnectorName());
        throw new ActiveMQException("lacking cluster connection");
    }
    clusterChannel.send(new BackupRegistrationMessage(connector, clusterUser, clusterPassword, attemptingFailBack));
}
Also used : ClusterConnectionConfiguration(org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration) BackupRegistrationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupRegistrationMessage) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration)

Example 27 with ActiveMQException

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

the class RemotingServiceImpl method connectionCreated.

@Override
public void connectionCreated(final ActiveMQComponent component, final Connection connection, final ProtocolManager protocol) {
    if (server == null) {
        throw new IllegalStateException("Unable to create connection, server hasn't finished starting up");
    }
    ConnectionEntry entry = protocol.createConnectionEntry((Acceptor) component, connection);
    try {
        if (server.hasBrokerPlugins()) {
            server.callBrokerPlugins(plugin -> plugin.afterCreateConnection(entry.connection));
        }
    } catch (ActiveMQException t) {
        logger.warn("Error executing afterCreateConnection plugin method: {}", t.getMessage(), t);
        throw new IllegalStateException(t.getMessage(), t.getCause());
    }
    if (logger.isTraceEnabled()) {
        logger.trace("Connection created " + connection);
    }
    connections.put(connection.getID(), entry);
    connectionCountLatch.countUp();
    totalConnectionCount.incrementAndGet();
}
Also used : ConnectionEntry(org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Example 28 with ActiveMQException

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

the class SubscriptionsResource method recreateTopicConsumer.

private QueueConsumer recreateTopicConsumer(String subscriptionId, boolean autoAck) {
    QueueConsumer consumer;
    if (subscriptionExists(subscriptionId)) {
        QueueConsumer tmp = null;
        try {
            tmp = createConsumer(true, autoAck, subscriptionId, null, consumerTimeoutSeconds * 1000L, false);
        } catch (ActiveMQException e) {
            throw new RuntimeException(e);
        }
        consumer = queueConsumers.putIfAbsent(subscriptionId, tmp);
        if (consumer == null) {
            consumer = tmp;
            serviceManager.getTimeoutTask().add(this, subscriptionId);
        } else {
            tmp.shutdown();
        }
    } else {
        throw new WebApplicationException(Response.status(405).entity("Failed to find subscriber " + subscriptionId + " you will have to reconnect").type("text/plain").build());
    }
    return consumer;
}
Also used : QueueConsumer(org.apache.activemq.artemis.rest.queue.QueueConsumer) AcknowledgedQueueConsumer(org.apache.activemq.artemis.rest.queue.AcknowledgedQueueConsumer) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 29 with ActiveMQException

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

the class SubscriptionsResource method createSubscription.

@POST
public Response createSubscription(@FormParam("durable") @DefaultValue("false") boolean durable, @FormParam("autoAck") @DefaultValue("true") boolean autoAck, @FormParam("name") String subscriptionName, @FormParam("selector") String selector, @FormParam("delete-when-idle") Boolean destroyWhenIdle, @FormParam("idle-timeout") Long timeout, @Context UriInfo uriInfo) {
    ActiveMQRestLogger.LOGGER.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");
    if (timeout == null)
        timeout = Long.valueOf(consumerTimeoutSeconds * 1000);
    // default is true if non-durable
    boolean deleteWhenIdle = !durable;
    if (destroyWhenIdle != null)
        deleteWhenIdle = destroyWhenIdle.booleanValue();
    if (subscriptionName != null) {
        // see if this is a reconnect
        QueueConsumer consumer = queueConsumers.get(subscriptionName);
        if (consumer != null) {
            boolean acked = consumer instanceof AcknowledgedSubscriptionResource;
            acked = !acked;
            if (acked != autoAck) {
                throw new WebApplicationException(Response.status(412).entity("Consumer already exists and ack-modes don't match.").type("text/plain").build());
            }
            Subscription sub = (Subscription) consumer;
            if (sub.isDurable() != durable) {
                throw new WebApplicationException(Response.status(412).entity("Consumer already exists and durability doesn't match.").type("text/plain").build());
            }
            Response.ResponseBuilder builder = Response.noContent();
            String pathToPullSubscriptions = uriInfo.getMatchedURIs().get(0);
            if (autoAck) {
                headAutoAckSubscriptionResponse(uriInfo, consumer, builder, pathToPullSubscriptions);
                consumer.setSessionLink(builder, uriInfo, pathToPullSubscriptions + "/auto-ack/" + consumer.getId());
            } else {
                headAcknowledgedConsumerResponse(uriInfo, (AcknowledgedQueueConsumer) consumer, builder);
                consumer.setSessionLink(builder, uriInfo, pathToPullSubscriptions + "/acknowledged/" + consumer.getId());
            }
            return builder.build();
        }
    } else {
        subscriptionName = generateSubscriptionName();
    }
    ClientSession session = null;
    try {
        // if this is not a reconnect, create the subscription queue
        if (!subscriptionExists(subscriptionName)) {
            session = sessionFactory.createSession();
            if (durable) {
                session.createQueue(destination, subscriptionName, true);
            } else {
                session.createTemporaryQueue(destination, subscriptionName);
            }
        }
        QueueConsumer consumer = createConsumer(durable, autoAck, subscriptionName, selector, timeout, deleteWhenIdle);
        queueConsumers.put(consumer.getId(), consumer);
        serviceManager.getTimeoutTask().add(this, consumer.getId());
        UriBuilder location = uriInfo.getAbsolutePathBuilder();
        if (autoAck)
            location.path("auto-ack");
        else
            location.path("acknowledged");
        location.path(consumer.getId());
        Response.ResponseBuilder builder = Response.created(location.build());
        if (autoAck) {
            QueueConsumer.setConsumeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(0) + "/auto-ack/" + consumer.getId(), "-1");
        } else {
            AcknowledgedQueueConsumer.setAcknowledgeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(0) + "/acknowledged/" + consumer.getId(), "-1");
        }
        return builder.build();
    } catch (ActiveMQException e) {
        throw new RuntimeException(e);
    } finally {
        if (session != null) {
            try {
                session.close();
            } catch (ActiveMQException e) {
            }
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) QueueConsumer(org.apache.activemq.artemis.rest.queue.QueueConsumer) AcknowledgedQueueConsumer(org.apache.activemq.artemis.rest.queue.AcknowledgedQueueConsumer) WebApplicationException(javax.ws.rs.WebApplicationException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) UriBuilder(javax.ws.rs.core.UriBuilder) POST(javax.ws.rs.POST)

Example 30 with ActiveMQException

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

the class SubscriptionsResource method deleteSubscriberQueue.

private void deleteSubscriberQueue(QueueConsumer consumer) {
    String subscriptionName = consumer.getId();
    ClientSession session = null;
    try {
        session = sessionFactory.createSession();
        session.deleteQueue(subscriptionName);
    } catch (ActiveMQException e) {
    } finally {
        if (session != null) {
            try {
                session.close();
            } catch (ActiveMQException e) {
            }
        }
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Aggregations

ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)254 Test (org.junit.Test)139 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)121 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)84 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)79 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)78 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)59 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)54 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)45 CountDownLatch (java.util.concurrent.CountDownLatch)40 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)36 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)31 HashSet (java.util.HashSet)29 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)27 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)23 Role (org.apache.activemq.artemis.core.security.Role)22 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)20 Set (java.util.Set)16 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)16 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)15