@Override public Bindings getBindingsForRoutingAddress(final SimpleString address) throws Exception { Bindings bindings = super.getBindingsForRoutingAddress(address); // this should only happen if we're routing to an address that has no mappings when we're running checkAllowable if (bindings == null && !wildCardAddresses.isEmpty()) { Address add = addAndUpdateAddressMap(address); if (!add.containsWildCard()) { for (Address destAdd : add.getLinkedAddresses()) { Bindings b = super.getBindingsForRoutingAddress(destAdd.getAddress()); if (b != null) { Collection<Binding> theBindings = b.getBindings(); for (Binding theBinding : theBindings) { super.addMappingInternal(address, theBinding); } super.getBindingsForRoutingAddress(address).setMessageLoadBalancingType(b.getMessageLoadBalancingType()); } } } bindings = super.getBindingsForRoutingAddress(address); } return bindings; }
@Override public void clear() { super.clear(); addresses.clear(); wildCardAddresses.clear(); }
@Override public AddressInfo removeAddressInfo(SimpleString address) throws Exception { final AddressInfo removed = super.removeAddressInfo(address); if (removed != null) { //Remove from mappings so removeAndUpdateAddressMap processes and cleanup mappings.remove(address); removeAndUpdateAddressMap(new AddressImpl(removed.getName(), wildcardConfiguration)); } return removed; }
/** * If the address to add the binding to contains a wildcard then a copy of the binding (with the same underlying queue) * will be added to the actual mappings. Otherwise the binding is added as normal. * * @param binding the binding to add * @return true if the address was a new mapping */ @Override public boolean addBinding(final Binding binding) throws Exception { boolean exists = super.addBinding(binding); if (!exists) { Address add = addAndUpdateAddressMap(binding.getAddress()); if (add.containsWildCard()) { for (Address destAdd : add.getLinkedAddresses()) { super.addMappingInternal(destAdd.getAddress(), binding); } } else { for (Address destAdd : add.getLinkedAddresses()) { Bindings bindings = super.getBindingsForRoutingAddress(destAdd.getAddress()); if (bindings != null) { for (Binding b : bindings.getBindings()) { super.addMappingInternal(binding.getAddress(), b); } } } } } return exists; }
/** * If the address is a wild card then the binding will be removed from the actual mappings for any linked address. * otherwise it will be removed as normal. * * @param uniqueName the name of the binding to remove * @return true if this was the last mapping for a specific address */ @Override public Binding removeBinding(final SimpleString uniqueName, Transaction tx) throws Exception { Binding binding = super.removeBinding(uniqueName, tx); if (binding != null) { Address add = getAddress(binding.getAddress()); if (add.containsWildCard()) { for (Address theAddress : add.getLinkedAddresses()) { super.removeBindingInternal(theAddress.getAddress(), uniqueName); } } removeAndUpdateAddressMap(add); } return binding; }
if (routingTypes == null || isEquals(routingTypes, info.getRoutingTypes())) { validateRoutingTypes(realAddressName, routingTypes); final EnumSet<RoutingType> updatedRoutingTypes = EnumSet.copyOf(routingTypes); info.setRoutingTypes(updatedRoutingTypes);
@Override public void updateMessageLoadBalancingTypeForAddress(SimpleString address, MessageLoadBalancingType messageLoadBalancingType) throws Exception { getBindingsForRoutingAddress(CompositeAddress.extractAddressName(address)).setMessageLoadBalancingType(messageLoadBalancingType); } }
@Override public SimpleString getMatchingQueue(final SimpleString address, final SimpleString queueName, RoutingType routingType) throws Exception { SimpleString realAddress = CompositeAddress.extractAddressName(address); Binding binding = getBinding(queueName); if (binding != null && !binding.getAddress().equals(realAddress) && !realAddress.toString().isEmpty()) { throw new IllegalStateException("queue belongs to address" + binding.getAddress()); } return binding != null ? binding.getUniqueName() : null; }
@Override public boolean addBinding(final Binding binding) throws Exception { if (nameMap.putIfAbsent(binding.getUniqueName(), binding) != null) { throw ActiveMQMessageBundle.BUNDLE.bindingAlreadyExists(binding); } if (logger.isTraceEnabled()) { logger.trace("Adding binding " + binding + " with address = " + binding.getUniqueName(), new Exception("trace")); } return addMappingInternal(binding.getAddress(), binding); }
public PostOfficeImpl(final ActiveMQServer server, final StorageManager storageManager, final PagingManager pagingManager, final QueueFactory bindableFactory, final ManagementService managementService, final long expiryReaperPeriod, final long addressQueueReaperPeriod, final WildcardConfiguration wildcardConfiguration, final int idCacheSize, final boolean persistIDCache, final HierarchicalRepository<AddressSettings> addressSettingsRepository) { this.storageManager = storageManager; queueFactory = bindableFactory; this.managementService = managementService; this.pagingManager = pagingManager; this.expiryReaperPeriod = expiryReaperPeriod; this.addressQueueReaperPeriod = addressQueueReaperPeriod; if (wildcardConfiguration.isRoutingEnabled()) { addressManager = new WildcardAddressManager(this, wildcardConfiguration, storageManager); } else { addressManager = new SimpleAddressManager(this, wildcardConfiguration, storageManager); } this.idCacheSize = idCacheSize; this.persistIDCache = persistIDCache; this.addressSettingsRepository = addressSettingsRepository; this.server = server; }
@Override public boolean addAddressInfo(AddressInfo addressInfo) throws Exception { boolean added = reloadAddressInfo(addressInfo); if (added && storageManager != null) { long txID = storageManager.generateID(); try { storageManager.addAddressBinding(txID, addressInfo); storageManager.commitBindings(txID); } catch (Exception e) { try { storageManager.rollbackBindings(txID); } catch (Exception ignored) { } throw e; } } return added; }
private synchronized void removeAndUpdateAddressMap(final Address address) throws Exception { // we only remove if there are no bindings left Bindings bindings = super.getBindingsForRoutingAddress(address.getAddress()); if (bindings == null || bindings.getBindings().size() == 0) { List<Address> addresses = address.getLinkedAddresses(); for (Address address1 : addresses) { address1.removeLinkedAddress(address); Bindings linkedBindings = super.getBindingsForRoutingAddress(address1.getAddress()); if (linkedBindings == null || linkedBindings.getBindings().size() == 0) { removeAddress(address1); } } removeAddress(address); } }
@Override public SimpleString getMatchingQueue(final SimpleString address, RoutingType routingType) throws Exception { SimpleString realAddress = CompositeAddress.extractAddressName(address); Binding binding = getBinding(realAddress); if (binding == null || !(binding instanceof LocalQueueBinding) || !binding.getAddress().equals(realAddress)) { Bindings bindings = mappings.get(realAddress); if (bindings != null) { for (Binding theBinding : bindings.getBindings()) { if (theBinding instanceof LocalQueueBinding) { binding = theBinding; break; } } } } return binding != null ? binding.getUniqueName() : null; }
@Override public void updateMessageLoadBalancingTypeForAddress(SimpleString address, MessageLoadBalancingType messageLoadBalancingType) throws Exception { Address add = addAndUpdateAddressMap(address); Bindings bindingsForRoutingAddress = super.getBindingsForRoutingAddress(address); if (bindingsForRoutingAddress != null) { bindingsForRoutingAddress.setMessageLoadBalancingType(messageLoadBalancingType); } if (add.containsWildCard()) { for (Address destAdd : add.getLinkedAddresses()) { getBindingsForRoutingAddress(destAdd.getAddress()).setMessageLoadBalancingType(messageLoadBalancingType); } } else { for (Address destAdd : add.getLinkedAddresses()) { super.getBindingsForRoutingAddress(destAdd.getAddress()).setMessageLoadBalancingType(messageLoadBalancingType); } } }