@Override public AddressInfo createAddress(final SimpleString address, RoutingType routingType, final boolean autoCreated) throws Exception { return createAddress(new AddressInfo(address, routingType), autoCreated); }
@Override public ServerConsumer createConsumer(final long consumerID, final SimpleString queueName, final SimpleString filterString, final boolean browseOnly, final boolean supportLargeMessage, final Integer credits) throws Exception { return this.createConsumer(consumerID, queueName, filterString, ActiveMQDefaultConfiguration.getDefaultConsumerPriority(), browseOnly, supportLargeMessage, credits); }
@Override public Queue createQueue(final SimpleString address, final SimpleString name, final RoutingType routingType, final SimpleString filterString, final boolean temporary, final boolean durable, final int maxConsumers, final boolean purgeOnNoConsumers, final Boolean exclusive, final Boolean lastValue, final boolean autoCreated) throws Exception { return createQueue(address, name, routingType, filterString, temporary, durable, maxConsumers, purgeOnNoConsumers, exclusive, lastValue, null, null, null, null, autoCreated); }
@Override public RoutingStatus send(final Message message, final boolean direct, boolean noAutoCreateQueue) throws Exception { return send(getCurrentTransaction(), message, direct, noAutoCreateQueue); }
/** * @param clientFailed If the client has failed, we can't decrease the delivery-counts, and the close may issue a rollback * @param considerLastMessageAsDelivered * @throws Exception */ private synchronized void rollback(final boolean clientFailed, final boolean considerLastMessageAsDelivered) throws Exception { if (tx == null) { // Might be null if XA tx = newTransaction(); } doRollback(clientFailed, considerLastMessageAsDelivered, tx); if (xa) { tx = null; } else { tx = newTransaction(); } }
@Override public void addProducer(ServerProducer serverProducer) { serverProducer.setSessionID(getName()); serverProducer.setConnectionID(getConnectionID().toString()); producers.put(serverProducer.getID(), serverProducer); }
final long delayBeforeDispatch, final boolean autoCreated) throws Exception { final SimpleString unPrefixedName = removePrefix(name); AddressInfo art = getAddressAndRoutingType(addressInfo); securityCheck(addressInfo.getName(), name, CheckType.CREATE_DURABLE_QUEUE, this); } else { securityCheck(addressInfo.getName(), name, CheckType.CREATE_NON_DURABLE_QUEUE, this); securityCheck(addressInfo.getName(), name, CheckType.CREATE_ADDRESS, this); server.checkQueueCreationLimit(getUsername()); Queue queue = server.createQueue(art, unPrefixedName, filterString, SimpleString.toSimpleString(getUsername()), durable, temporary, autoCreated, maxConsumers, purgeOnNoConsumers, exclusive, lastValue, lastValueKey, nonDestructive, consumersBeforeDispatch, delayBeforeDispatch, as.isAutoCreateAddresses());
try { if (!this.getRemotingConnection().isSupportsFlowControl() && pagingManager.isDiskFull()) { ActiveMQIOErrorException exception = ActiveMQMessageBundle.BUNDLE.diskBeyondLimit(); this.getRemotingConnection().fail(exception); throw exception; result = handleManagementMessage(tx, message, direct); } else { result = doSend(tx, message, address, direct, noAutoCreateQueue, routingContext);
/** * Creates a Queue if it doesn't already exist, based on a topic and address. Returning the queue name. */ private Queue createQueueForSubscription(String address, int qos) throws Exception { // Check to see if a subscription queue already exists. SimpleString queue = getQueueNameForTopic(address); Queue q = session.getServer().locateQueue(queue); // The queue does not exist so we need to create it. if (q == null) { SimpleString sAddress = SimpleString.toSimpleString(address); // Check we can auto create queues. BindingQueryResult bindingQueryResult = session.getServerSession().executeBindingQuery(sAddress); if (!bindingQueryResult.isAutoCreateQueues()) { throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(sAddress); } // Check that the address exists, if not we try to auto create it. AddressInfo addressInfo = session.getServerSession().getAddress(sAddress); if (addressInfo == null) { if (!bindingQueryResult.isAutoCreateAddresses()) { throw ActiveMQMessageBundle.BUNDLE.addressDoesNotExist(SimpleString.toSimpleString(address)); } addressInfo = session.getServerSession().createAddress(SimpleString.toSimpleString(address), RoutingType.MULTICAST, true); } return findOrCreateQueue(bindingQueryResult, addressInfo, queue, qos); } return q; }
state.getPubRec().add(messageId); Transaction tx = session.getServerSession().newTransaction(); try { if (internal) { session.getServer().getPostOffice().route(serverMessage, tx, true); } else { session.getServerSession().send(tx, serverMessage, true, false);
@Override public void describeProducersInfo(JsonArrayBuilder array) throws Exception { Map<SimpleString, Pair<Object, AtomicLong>> targetCopy = cloneTargetAddresses(); for (Map.Entry<SimpleString, Pair<Object, AtomicLong>> entry : targetCopy.entrySet()) { String uuid = null; if (entry.getValue().getA() != null) { uuid = entry.getValue().getA().toString(); } JsonObjectBuilder producerInfo = JsonLoader.createObjectBuilder().add("connectionID", this.getConnectionID().toString()).add("sessionID", this.getName()).add("destination", entry.getKey().toString()).add("lastUUIDSent", nullSafe(uuid)).add("msgSent", entry.getValue().getB().longValue()); array.add(producerInfo); } }
synchronized void stop() throws Exception { ServerSessionImpl serversession = session.getServerSession(); if (serversession != null) { serversession.removeProducer(serversession.getName()); } if (managementConsumer != null) { managementConsumer.removeItself(); managementConsumer.setStarted(false); managementConsumer.close(false); } }
void handlePubRec(int messageId) throws Exception { try { Pair<Long, Long> ref = outboundStore.publishReceived(messageId); if (ref != null) { Message m = MQTTUtil.createPubRelMessage(session, getManagementAddress(), messageId); session.getServerSession().send(m, true); session.getServerSession().individualAcknowledge(ref.getB(), ref.getA()); } else { session.getProtocolHandler().sendPubRel(messageId); } } catch (ActiveMQIllegalStateException e) { log.warn("MQTT Client(" + session.getSessionState().getClientId() + ") attempted to Ack already Ack'd message"); } }
@Override public void individualAcknowledge(final long consumerID, final long messageID) throws Exception { ServerConsumer consumer = findConsumer(consumerID); if (tx != null && tx.getState() == State.ROLLEDBACK) { // JBPAPP-8845 - if we let stuff to be acked on a rolled back TX, we will just // have these messages to be stuck on the limbo until the server is restarted // The tx has already timed out, so we need to ack and rollback immediately Transaction newTX = newTransaction(); consumer.individualAcknowledge(tx, messageID); newTX.rollback(); } else { consumer.individualAcknowledge(autoCommitAcks ? null : tx, messageID); } }
synchronized void stop() throws Exception { if (!stopped) { protocolHandler.stop(); subscriptionManager.stop(); mqttPublishManager.stop(); if (serverSession != null) { serverSession.stop(); serverSession.close(false); } if (state != null) { state.setAttached(false); } if (isClean()) { clean(); } } stopped = true; }
void addRetainedMessagesToQueue(Queue queue, String address) throws Exception { // The address filter that matches all retained message queues. String retainAddress = MQTTUtil.convertMQTTAddressFilterToCoreRetain(address, session.getWildcardConfiguration()); BindingQueryResult bindingQueryResult = session.getServerSession().executeBindingQuery(new SimpleString(retainAddress)); // Iterate over all matching retain queues and add the queue Transaction tx = session.getServerSession().newTransaction(); try { synchronized (queue) { for (SimpleString retainedQueueName : bindingQueryResult.getQueueNames()) { Queue retainedQueue = session.getServer().locateQueue(retainedQueueName); try (LinkedListIterator<MessageReference> i = retainedQueue.iterator()) { if (i.hasNext()) { Message message = i.next().getMessage().copy(session.getServer().getStorageManager().generateID()); sendToQueue(message, queue, tx); } } } } } catch (Throwable t) { tx.rollback(); throw t; } tx.commit(); }
@Override public synchronized void commit() throws Exception { if (logger.isTraceEnabled()) { logger.trace("Calling commit"); } try { if (tx != null) { tx.commit(); } } finally { if (xa) { tx = null; } else { tx = newTransaction(); } } }
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 need to check this before we cancel the refs and add them to the tx, any delivering refs will have been delivered //after the last tx was rolled back so we should handle them separately. if not they //will end up added to the tx but never ever handled even tho they were removed from the consumers delivering refs. //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); } }
final boolean autoCreated) throws Exception { AddressSettings as = server.getAddressSettingsRepository().getMatch(address.toString()); return createQueue(new AddressInfo(address, routingType), name, filterString, temporary, durable, maxConsumers, purgeOnNoConsumers, as.isDefaultExclusiveQueue(), as.isDefaultLastValueQueue(), as.getDefaultLastValueKey(), as.isDefaultNonDestructive(), as.getDefaultConsumersBeforeDispatch(), as.getDefaultDelayBeforeDispatch(), autoCreated); Boolean exclusive, Boolean lastValue) throws Exception { createSharedQueue(address, name, routingType, filterString, durable, maxConsumers, purgeOnNoConsumers, exclusive, lastValue, null, null, null, null);
protected ServerSessionImpl internalCreateSession(String name, String username, String password, String validatedUser, int minLargeMessageSize, RemotingConnection connection, boolean autoCommitSends, boolean autoCommitAcks, boolean preAcknowledge, boolean xa, String defaultAddress, SessionCallback callback, OperationContext context, boolean autoCreateJMSQueues, Map<SimpleString, RoutingType> prefixes) throws Exception { return new ServerSessionImpl(name, username, password, validatedUser, minLargeMessageSize, autoCommitSends, autoCommitAcks, preAcknowledge, configuration.isPersistDeliveryCountBeforeDelivery(), xa, connection, storageManager, postOffice, resourceManager, securityStore, managementService, this, configuration.getManagementAddress(), defaultAddress == null ? null : new SimpleString(defaultAddress), callback, context, pagingManager, prefixes); }