@Override public void removeBinding(final Binding binding) { try { if (binding.isExclusive()) { exclusiveBindings.remove(binding); } else { SimpleString routingName = binding.getRoutingName(); List<Binding> bindings = routingNameBindingMap.get(routingName); if (bindings != null) { bindings.remove(binding); if (bindings.isEmpty()) { routingNameBindingMap.remove(routingName); } } } bindingsIdMap.remove(binding.getID()); bindingsNameMap.remove(binding.getUniqueName()); if (logger.isTraceEnabled()) { logger.trace("Removing binding " + binding + " from " + this + " bindingTable: " + debugBindings()); } } finally { updated(); } }
@Override public void route(final Message message, final RoutingContext context) throws Exception { route(message, context, true); }
theBinding = binding; pos = incrementPos(pos, length); pos = incrementPos(pos, length); pos = incrementPos(lastLowPriorityBinding, length); if (exclusivelyRemote(bindings)) { theBinding = null; } else { theBinding = getNextBinding(message, routingName, bindings);
Binding theBinding = getNextBinding(message, routingName, bindings); if (theBinding == null) { continue; theBinding = locateBinding(resp.getAlternativeClusterName(), bindings); routeAndCheckNull(message, context, resp, theBinding, groupId, tries); } else { Binding chosen = locateBinding(resp.getChosenClusterName(), bindings); routeAndCheckNull(message, context, resp, chosen, groupId, tries);
routeFromCluster(message, context, ids); } else if (groupingHandler != null && groupRouting && groupId != null) { context.clear().setReusable(false); routeUsingStrictOrdering(message, context, groupingHandler, groupId, 0); } else if (CompositeAddress.isFullyQualified(message.getAddress())) { Binding theBinding = bindingsNameMap.get(CompositeAddress.extractQueueName(message.getAddressSimpleString())); simpleRouting(message, context);
@Override public Bindings createBindings(final SimpleString address) { GroupingHandler groupingHandler = server.getGroupingHandler(); BindingsImpl bindings = new BindingsImpl(CompositeAddress.extractAddressName(address), groupingHandler); if (groupingHandler != null) { groupingHandler.addListener(bindings); } return bindings; }
private void routeAndCheckNull(Message message, RoutingContext context, Response resp, Binding theBinding, SimpleString groupId, int tries) throws Exception { // and let's route it if (theBinding != null) { theBinding.route(message, context); } else { if (resp != null) { groupingHandler.forceRemove(resp.getGroupId(), resp.getClusterName()); } //there may be a chance that the binding has been removed from the post office before it is removed from the grouping handler. //in this case all we can do is remove it and try again. if (tries < MAX_GROUP_RETRY) { routeUsingStrictOrdering(message, context, groupingHandler, groupId, tries + 1); } else { ActiveMQServerLogger.LOGGER.impossibleToRouteGrouped(); route(message, context, false); } } }
private void simpleRouting(Message message, RoutingContext context) throws Exception { if (logger.isTraceEnabled()) { logger.trace("Routing message " + message + " on binding=" + this); } // We check at the version before we started routing, // this is because if something changed in between we want to check the correct version int currentVersion = version.get(); for (Map.Entry<SimpleString, List<Binding>> entry : routingNameBindingMap.entrySet()) { SimpleString routingName = entry.getKey(); List<Binding> bindings = entry.getValue(); if (bindings == null) { // The value can become null if it's concurrently removed while we're iterating - this is expected // ConcurrentHashMap behaviour! continue; } Binding theBinding = getNextBinding(message, routingName, bindings); if (theBinding != null && theBinding.getFilter() == null && bindings.size() == 1 && theBinding.isLocal()) { context.setReusable(true, currentVersion); } else { // notice that once this is set to false, any calls to setReusable(true) will be moot as the context will ignore it context.setReusable(false, currentVersion); } if (theBinding != null) { theBinding.route(message, context); } } }
pos = incrementPos(pos, length);
Map<SimpleString, List<Binding>> routingNames = ((BindingsImpl) bindings).getRoutingNameBindingMap(); for (SimpleString key : routingNames.keySet()) { if (!key.toString().equals(topic.getAddress())) {
private void internalTest(final boolean route) throws Exception { final FakeBinding fake = new FakeBinding(new SimpleString("a")); final Bindings bind = new BindingsImpl(null, null); bind.addBinding(fake); bind.addBinding(new FakeBinding(new SimpleString("a"))); bind.addBinding(new FakeBinding(new SimpleString("a"))); Thread t = new Thread() { @Override public void run() { try { bind.removeBinding(fake); } catch (Exception e) { e.printStackTrace(); } } }; Queue queue = new FakeQueue(new SimpleString("a")); t.start(); for (int i = 0; i < 100; i++) { if (route) { bind.route(new CoreMessage(i, 100), new RoutingContextImpl(new FakeTransaction())); } else { bind.redistribute(new CoreMessage(i, 100), queue, new RoutingContextImpl(new FakeTransaction())); } } }
logger.trace("Adding binding " + binding + " into " + this + " bindingTable: " + debugBindings()); updated();