private AddressInfo mergedRoutingTypes(SimpleString address, AddressInfo... addressInfos) { EnumSet<RoutingType> mergedRoutingTypes = EnumSet.noneOf(RoutingType.class); for (AddressInfo addressInfo : addressInfos) { if (addressInfo != null) { mergedRoutingTypes.addAll(addressInfo.getRoutingTypes()); } } return new AddressInfo(address, mergedRoutingTypes); }
private Queue findOrCreateQueue(BindingQueryResult bindingQueryResult, AddressInfo addressInfo, SimpleString queue, int qos) throws Exception { if (addressInfo.getRoutingTypes().contains(RoutingType.MULTICAST)) { return session.getServerSession().createQueue(addressInfo.getName(), queue, RoutingType.MULTICAST, managementFilter, false, MQTTUtil.DURABLE_MESSAGES && qos >= 0, false); } if (addressInfo.getRoutingTypes().contains(RoutingType.ANYCAST)) { if (!bindingQueryResult.getQueueNames().isEmpty()) { SimpleString name = null; for (SimpleString qName : bindingQueryResult.getQueueNames()) { if (name == null) { name = qName; } else if (qName.equals(addressInfo.getName())) { name = qName; } } return session.getServer().locateQueue(name); } else { try { return session.getServerSession().createQueue(addressInfo.getName(), addressInfo.getName(), RoutingType.ANYCAST, managementFilter, false, MQTTUtil.DURABLE_MESSAGES && qos >= 0, false); } catch (ActiveMQQueueExistsException e) { return session.getServer().locateQueue(addressInfo.getName()); } } } Set<RoutingType> routingTypeSet = new HashSet(); routingTypeSet.add(RoutingType.MULTICAST); routingTypeSet.add(RoutingType.ANYCAST); throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeForAddress(addressInfo.getRoutingType(), addressInfo.getName().toString(), routingTypeSet); }
/** * Creates an AddressInfo object with a single RoutingType associated with it. * @param name * @param routingType */ public AddressInfo(SimpleString name, RoutingType routingType) { this.name = CompositeAddress.extractAddressName(name); addRoutingType(routingType); }
public AddressInfo create(SimpleString name, RoutingType routingType) { AddressInfo info = new AddressInfo(name, routingType); info.setInternal(this.internal); return info; }
public AddressInfo getAddressAndRoutingType(Map<SimpleString, RoutingType> prefixes) { for (Map.Entry<SimpleString, RoutingType> entry : prefixes.entrySet()) { if (this.getName().startsWith(entry.getKey())) { AddressInfo newAddressInfo = this.create(PrefixUtil.removePrefix(this.getName(), entry.getKey()), entry.getValue()); return newAddressInfo; } } return this; }
protected void createAddressInfo(final int node, final String address, final RoutingType routingType, final int defaulMaxConsumers, boolean defaultPurgeOnNoConsumers) throws Exception { AddressInfo addressInfo = new AddressInfo(new SimpleString(address)); addressInfo.addRoutingType(routingType); servers[node].addOrUpdateAddressInfo(addressInfo); }
@Override public AddressInfo createAddress(final SimpleString address, RoutingType routingType, final boolean autoCreated) throws Exception { return createAddress(new AddressInfo(address, routingType), autoCreated); }
final SimpleString addressToUse = (addrInfo == null || addrInfo.getName() == null) ? realQueueName : addrInfo.getName(); RoutingType routingType = addrInfo == null ? null : addrInfo.getRoutingType(); RoutingType rt = (routingType == null ? ActiveMQDefaultConfiguration.getDefaultRoutingType() : routingType); if (autoCreateAddress || temporary) { if (info == null) { final AddressInfo addressInfo = new AddressInfo(addressToUse, rt); addressInfo.setAutoCreated(true); addressInfo.setInternal(addrInfo == null ? false : addrInfo.isInternal()); addAddressInfo(addressInfo); } else if (!info.getRoutingTypes().contains(rt)) { EnumSet<RoutingType> routingTypes = EnumSet.copyOf(info.getRoutingTypes()); routingTypes.add(rt); updateAddressInfo(info.getName(), routingTypes); } else if (!info.getRoutingTypes().contains(rt)) { throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeForAddress(rt, info.getName().toString(), info.getRoutingTypes()); if (addrInfo == null || !addrInfo.isInternal()) { managementService.registerQueue(queue, queue.getAddress(), storageManager); final long delayBeforeDispatch, final boolean autoCreateAddress) throws Exception { return createQueue(new AddressInfo(address).addRoutingType(routingType), queueName, filterString, user, durable, temporary, ignoreIfExists, transientQueue, autoCreated, maxConsumers, purgeOnNoConsumers, exclusive, lastValue, lastValueKey, nonDestructive, consumersBeforeDispatch, delayBeforeDispatch, autoCreateAddress, false);
private void deployAddressesFromConfiguration(Configuration configuration) throws Exception { for (CoreAddressConfiguration config : configuration.getAddressConfigurations()) { try { ActiveMQServerLogger.LOGGER.deployAddress(config.getName(), config.getRoutingTypes().toString()); SimpleString address = SimpleString.toSimpleString(config.getName()); AddressInfo tobe = new AddressInfo(address, config.getRoutingTypes()); //During this stage until all queues re-configured we combine the current (if exists) with to-be routing types to allow changes in queues AddressInfo current = getAddressInfo(address); AddressInfo merged = new AddressInfo(address, tobe.getRoutingType()); if (current != null) { merged.getRoutingTypes().addAll(current.getRoutingTypes()); } addOrUpdateAddressInfo(merged); deployQueuesFromListCoreQueueConfiguration(config.getQueueConfigurations()); //Now all queues updated we apply the actual address info expected tobe. addOrUpdateAddressInfo(tobe); } catch (Exception e) { ActiveMQServerLogger.LOGGER.problemDeployingAddress(config.getName(), e.getMessage()); } } }
private RoutingType getRoutingType(String typeHeader, String destination) throws Exception { // null is valid to return here so we know when the user didn't provide any routing info RoutingType routingType; if (typeHeader != null) { routingType = RoutingType.valueOf(typeHeader); } else { routingType = connection.getSession().getCoreSession().getAddressAndRoutingType(new AddressInfo(new SimpleString(destination))).getRoutingType(); } return routingType; }
@Override public Object getField(AddressInfo address, String fieldName) { if (address == null) { return null; } switch (fieldName) { case "id": return address.getId(); case "name": return address.getName(); case "routingTypes": return address.getRoutingTypes(); case "queueCount": try { return server.bindingQuery(address.getName()).getQueueNames().size(); } catch (Exception e) { return 0; } default: throw new IllegalArgumentException("Unsupported field, " + fieldName); } }
private RoutingType getRoutingType(Symbol[] symbols, SimpleString address) { if (symbols != null) { for (Symbol symbol : symbols) { if (AmqpSupport.TEMP_TOPIC_CAPABILITY.equals(symbol) || AmqpSupport.TOPIC_CAPABILITY.equals(symbol)) { return RoutingType.MULTICAST; } else if (AmqpSupport.TEMP_QUEUE_CAPABILITY.equals(symbol) || AmqpSupport.QUEUE_CAPABILITY.equals(symbol)) { return RoutingType.ANYCAST; } } } final AddressInfo addressInfo = sessionSPI.getAddress(address); if (addressInfo != null && !addressInfo.getRoutingTypes().isEmpty()) { if (addressInfo.getRoutingTypes().size() == 1 && addressInfo.getRoutingType() == RoutingType.MULTICAST) { return RoutingType.MULTICAST; } } RoutingType defaultRoutingType = sessionSPI.getDefaultRoutingType(address); defaultRoutingType = defaultRoutingType == null ? ActiveMQDefaultConfiguration.getDefaultRoutingType() : defaultRoutingType; return defaultRoutingType; }
AddressInfo art = getAddressAndRoutingType(new AddressInfo(msg.getAddressSimpleString(), routingType)); securityCheck(art.getName(), CheckType.SEND, this); } catch (ActiveMQException e) { if (!autoCommitSends && tx != null) { routingContext.setAddress(art.getName()); routingContext.setRoutingType(art.getRoutingType());
@Override public void setRoutingType(RoutingType routingType) { if (addressInfo.getRoutingTypes().contains(routingType)) { this.routingType = routingType; } }
AddressInfo infoAdded = new AddressInfo(ADDRESS, RoutingType.ANYCAST); server.updateAddressInfo(ADDRESS, infoAdded.getRoutingTypes()); Assert.assertEquals(infoAdded.getId(), infoAfterRestart.getId()); Assert.assertNotEquals(infoAdded.getId(), infoAfterRestart.getId());
@Override public boolean reloadAddressInfo(AddressInfo addressInfo) throws Exception { return addressInfoMap.putIfAbsent(addressInfo.getName(), addressInfo) == null; }
addressInfo.addRoutingType(RoutingType.MULTICAST); } else { addressInfo = new AddressInfo(address, RoutingType.MULTICAST); addressInfo.setInternal(internalAddress); if (isDurable) { queueName = org.apache.activemq.artemis.jms.client.ActiveMQDestination.createQueueNameForSubscription(true, clientID, subscriptionName);
@Override public AddressQueryResult addressQuery(SimpleString name) throws Exception { if (name == null) { throw ActiveMQMessageBundle.BUNDLE.queueNameIsNull(); } SimpleString realName = CompositeAddress.extractAddressName(name); AddressSettings addressSettings = getAddressSettingsRepository().getMatch(realName.toString()); boolean autoCreateAddresses = addressSettings.isAutoCreateAddresses(); boolean defaultPurgeOnNoConsumers = addressSettings.isDefaultPurgeOnNoConsumers(); int defaultMaxConsumers = addressSettings.getDefaultMaxConsumers(); AddressInfo addressInfo = postOffice.getAddressInfo(realName); AddressQueryResult response; if (addressInfo != null) { response = new AddressQueryResult(addressInfo.getName(), addressInfo.getRoutingTypes(), addressInfo.getId(), addressInfo.isAutoCreated(), true, autoCreateAddresses, defaultPurgeOnNoConsumers, defaultMaxConsumers); } else { response = new AddressQueryResult(realName, null, -1, false, false, autoCreateAddresses, defaultPurgeOnNoConsumers, defaultMaxConsumers); } return response; }
@Override public void addAddressBinding(final long tx, final AddressInfo addressInfo) throws Exception { PersistentAddressBindingEncoding bindingEncoding = new PersistentAddressBindingEncoding(addressInfo.getName(), addressInfo.getRoutingTypes(), addressInfo.isAutoCreated()); readLock(); try { long recordID = idGenerator.generateID(); bindingEncoding.setId(recordID); addressInfo.setId(recordID); bindingsJournal.appendAddRecordTransactional(tx, recordID, JournalRecordIds.ADDRESS_BINDING_RECORD, bindingEncoding); } finally { readUnLock(); } }
@Override public StringBuilder format(AddressInfo addressInfo, StringBuilder output) { output.append("Address [name=").append(addressInfo.getName()); output.append(", routingTypes={"); final EnumSet<RoutingType> routingTypes = addressInfo.getRoutingTypes(); if (!routingTypes.isEmpty()) { for (RoutingType routingType : routingTypes) { output.append(routingType).append(','); } // delete hanging comma output.deleteCharAt(output.length() - 1); } output.append('}'); output.append(", autoCreated=").append(addressInfo.isAutoCreated()); output.append(']'); return output; } };