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);
}
}
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);
}
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);
}
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));
}
}
}
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);
}
}
Aggregations