Search in sources :

Example 16 with ServerConsumer

use of org.apache.activemq.artemis.core.server.ServerConsumer in project activemq-artemis by apache.

the class MQTTSubscriptionManager method removeSubscription.

// FIXME: Do we need this synchronzied?
private synchronized void removeSubscription(String address) throws Exception {
    String internalAddress = MQTTUtil.convertMQTTAddressFilterToCore(address, session.getWildcardConfiguration());
    SimpleString internalQueueName = getQueueNameForTopic(internalAddress);
    session.getSessionState().removeSubscription(address);
    ServerConsumer consumer = consumers.get(address);
    consumers.remove(address);
    if (consumer != null) {
        consumer.close(false);
        consumerQoSLevels.remove(consumer.getID());
    }
    if (session.getServerSession().executeQueueQuery(internalQueueName).isExists()) {
        session.getServerSession().deleteQueue(internalQueueName);
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer)

Example 17 with ServerConsumer

use of org.apache.activemq.artemis.core.server.ServerConsumer in project activemq-artemis by apache.

the class MQTTSubscriptionManager method createConsumerForSubscriptionQueue.

/**
 * Creates a new consumer for the queue associated with a subscription
 */
private void createConsumerForSubscriptionQueue(Queue queue, String topic, int qos) throws Exception {
    long cid = session.getServer().getStorageManager().generateID();
    ServerConsumer consumer = session.getServerSession().createConsumer(cid, queue.getName(), null, false, false, -1);
    consumer.setStarted(true);
    consumers.put(topic, consumer);
    consumerQoSLevels.put(cid, qos);
}
Also used : ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer)

Example 18 with ServerConsumer

use of org.apache.activemq.artemis.core.server.ServerConsumer in project activemq-artemis by apache.

the class ServerSessionImpl method receiveConsumerCredits.

@Override
public void receiveConsumerCredits(final long consumerID, final int credits) throws Exception {
    ServerConsumer consumer = locateConsumer(consumerID);
    if (consumer == null) {
        logger.debug("There is no consumer with id " + consumerID);
        return;
    }
    consumer.receiveCredits(credits);
}
Also used : ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer)

Example 19 with ServerConsumer

use of org.apache.activemq.artemis.core.server.ServerConsumer in project activemq-artemis by apache.

the class ServerSessionImpl method doClose.

protected void doClose(final boolean failed) throws Exception {
    if (callback != null) {
        callback.close(failed);
    }
    synchronized (this) {
        if (!closed) {
            if (server.hasBrokerPlugins()) {
                server.callBrokerPlugins(plugin -> plugin.beforeCloseSession(this, failed));
            }
        }
        this.setStarted(false);
        if (closed)
            return;
        if (tx != null && tx.getXid() == null) {
            try {
                rollback(failed, false);
            } catch (Exception e) {
                ActiveMQServerLogger.LOGGER.unableToRollbackOnClose(e);
            }
        }
    }
    // putting closing of consumers outside the sync block
    // https://issues.jboss.org/browse/HORNETQ-1141
    Set<ServerConsumer> consumersClone = new HashSet<>(consumers.values());
    for (ServerConsumer consumer : consumersClone) {
        try {
            consumer.close(failed);
        } catch (Throwable e) {
            ActiveMQServerLogger.LOGGER.unableToCloseConsumer(e);
            try {
                consumer.removeItself();
            } catch (Throwable e2) {
                ActiveMQServerLogger.LOGGER.unableToRemoveConsumer(e2);
            }
        }
    }
    consumers.clear();
    producers.clear();
    if (closeables != null) {
        for (Closeable closeable : closeables) {
            closeable.close(failed);
        }
    }
    synchronized (this) {
        server.removeSession(name);
        remotingConnection.removeFailureListener(this);
        if (callback != null) {
            callback.closed();
        }
        closed = true;
        if (server.hasBrokerPlugins()) {
            server.callBrokerPlugins(plugin -> plugin.afterCloseSession(this, failed));
        }
    }
}
Also used : Closeable(org.apache.activemq.artemis.Closeable) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) ActiveMQXAException(org.apache.activemq.artemis.core.exception.ActiveMQXAException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) XAException(javax.transaction.xa.XAException) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) HashSet(java.util.HashSet)

Example 20 with ServerConsumer

use of org.apache.activemq.artemis.core.server.ServerConsumer in project activemq-artemis by apache.

the class ServerSessionImpl method doRollback.

private void doRollback(final boolean clientFailed, final boolean lastMessageAsDelived, final Transaction theTx) throws Exception {
    boolean wasStarted = started;
    List<MessageReference> toCancel = new ArrayList<>();
    for (ServerConsumer consumer : consumers.values()) {
        if (wasStarted) {
            consumer.setStarted(false);
        }
        toCancel.addAll(consumer.cancelRefs(clientFailed, lastMessageAsDelived, theTx));
    }
    // we add them to a new tx and roll them back as the calling client will assume that this has happened.
    if (theTx.getState() == State.ROLLEDBACK) {
        Transaction newTX = newTransaction();
        cancelAndRollback(clientFailed, newTX, wasStarted, toCancel);
    } else {
        cancelAndRollback(clientFailed, theTx, wasStarted, toCancel);
    }
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) ArrayList(java.util.ArrayList) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer)

Aggregations

ServerConsumer (org.apache.activemq.artemis.core.server.ServerConsumer)26 ServerSession (org.apache.activemq.artemis.core.server.ServerSession)7 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)6 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)4 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)4 HashSet (java.util.HashSet)3 JsonArrayBuilder (javax.json.JsonArrayBuilder)3 XAException (javax.transaction.xa.XAException)3 ActiveMQIOErrorException (org.apache.activemq.artemis.api.core.ActiveMQIOErrorException)3 ActiveMQNonExistentQueueException (org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException)3 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)3 ActiveMQXAException (org.apache.activemq.artemis.core.exception.ActiveMQXAException)3 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)3 Test (org.junit.Test)3 JsonObject (javax.json.JsonObject)2 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)2 Binding (org.apache.activemq.artemis.core.postoffice.Binding)2