001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.activemq.broker.region; 018 019import java.util.ArrayList; 020import java.util.HashMap; 021import java.util.Iterator; 022import java.util.List; 023import java.util.Map; 024import java.util.Set; 025import java.util.concurrent.ConcurrentHashMap; 026import java.util.concurrent.locks.ReentrantReadWriteLock; 027 028import javax.jms.IllegalStateException; 029import javax.jms.JMSException; 030 031import org.apache.activemq.DestinationDoesNotExistException; 032import org.apache.activemq.advisory.AdvisorySupport; 033import org.apache.activemq.broker.ConnectionContext; 034import org.apache.activemq.broker.ConsumerBrokerExchange; 035import org.apache.activemq.broker.ProducerBrokerExchange; 036import org.apache.activemq.broker.region.policy.PolicyEntry; 037import org.apache.activemq.broker.region.virtual.CompositeDestinationFilter; 038import org.apache.activemq.command.ActiveMQDestination; 039import org.apache.activemq.command.ConsumerControl; 040import org.apache.activemq.command.ConsumerId; 041import org.apache.activemq.command.ConsumerInfo; 042import org.apache.activemq.command.Message; 043import org.apache.activemq.command.MessageAck; 044import org.apache.activemq.command.MessageDispatchNotification; 045import org.apache.activemq.command.MessagePull; 046import org.apache.activemq.command.ProducerInfo; 047import org.apache.activemq.command.RemoveSubscriptionInfo; 048import org.apache.activemq.command.Response; 049import org.apache.activemq.filter.DestinationFilter; 050import org.apache.activemq.filter.DestinationMap; 051import org.apache.activemq.security.SecurityContext; 052import org.apache.activemq.thread.TaskRunnerFactory; 053import org.apache.activemq.usage.SystemUsage; 054import org.slf4j.Logger; 055import org.slf4j.LoggerFactory; 056 057/** 058 * 059 */ 060public abstract class AbstractRegion implements Region { 061 062 private static final Logger LOG = LoggerFactory.getLogger(AbstractRegion.class); 063 064 protected final Map<ActiveMQDestination, Destination> destinations = new ConcurrentHashMap<ActiveMQDestination, Destination>(); 065 protected final DestinationMap destinationMap = new DestinationMap(); 066 protected final Map<ConsumerId, Subscription> subscriptions = new ConcurrentHashMap<ConsumerId, Subscription>(); 067 protected final SystemUsage usageManager; 068 protected final DestinationFactory destinationFactory; 069 protected final DestinationStatistics destinationStatistics; 070 protected final RegionStatistics regionStatistics = new RegionStatistics(); 071 protected final RegionBroker broker; 072 protected boolean autoCreateDestinations = true; 073 protected final TaskRunnerFactory taskRunnerFactory; 074 protected final ReentrantReadWriteLock destinationsLock = new ReentrantReadWriteLock(); 075 protected final Map<ConsumerId, Object> consumerChangeMutexMap = new HashMap<ConsumerId, Object>(); 076 protected boolean started; 077 078 public AbstractRegion(RegionBroker broker, DestinationStatistics destinationStatistics, SystemUsage memoryManager, 079 TaskRunnerFactory taskRunnerFactory, DestinationFactory destinationFactory) { 080 if (broker == null) { 081 throw new IllegalArgumentException("null broker"); 082 } 083 this.broker = broker; 084 this.destinationStatistics = destinationStatistics; 085 this.usageManager = memoryManager; 086 this.taskRunnerFactory = taskRunnerFactory; 087 if (destinationFactory == null) { 088 throw new IllegalArgumentException("null destinationFactory"); 089 } 090 this.destinationFactory = destinationFactory; 091 } 092 093 @Override 094 public final void start() throws Exception { 095 started = true; 096 097 Set<ActiveMQDestination> inactiveDests = getInactiveDestinations(); 098 for (Iterator<ActiveMQDestination> iter = inactiveDests.iterator(); iter.hasNext();) { 099 ActiveMQDestination dest = iter.next(); 100 101 ConnectionContext context = new ConnectionContext(); 102 context.setBroker(broker.getBrokerService().getBroker()); 103 context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); 104 context.getBroker().addDestination(context, dest, false); 105 } 106 destinationsLock.readLock().lock(); 107 try{ 108 for (Iterator<Destination> i = destinations.values().iterator(); i.hasNext();) { 109 Destination dest = i.next(); 110 dest.start(); 111 } 112 } finally { 113 destinationsLock.readLock().unlock(); 114 } 115 } 116 117 @Override 118 public void stop() throws Exception { 119 started = false; 120 destinationsLock.readLock().lock(); 121 try{ 122 for (Iterator<Destination> i = destinations.values().iterator(); i.hasNext();) { 123 Destination dest = i.next(); 124 dest.stop(); 125 } 126 } finally { 127 destinationsLock.readLock().unlock(); 128 } 129 130 destinationsLock.writeLock().lock(); 131 try { 132 destinations.clear(); 133 regionStatistics.getAdvisoryDestinations().reset(); 134 regionStatistics.getDestinations().reset(); 135 regionStatistics.getAllDestinations().reset(); 136 } finally { 137 destinationsLock.writeLock().unlock(); 138 } 139 } 140 141 @Override 142 public Destination addDestination(ConnectionContext context, ActiveMQDestination destination, 143 boolean createIfTemporary) throws Exception { 144 145 destinationsLock.writeLock().lock(); 146 try { 147 Destination dest = destinations.get(destination); 148 if (dest == null) { 149 if (destination.isTemporary() == false || createIfTemporary) { 150 // Limit the number of destinations that can be created if 151 // maxDestinations has been set on a policy 152 validateMaxDestinations(destination); 153 154 LOG.debug("{} adding destination: {}", broker.getBrokerName(), destination); 155 dest = createDestination(context, destination); 156 // intercept if there is a valid interceptor defined 157 DestinationInterceptor destinationInterceptor = broker.getDestinationInterceptor(); 158 if (destinationInterceptor != null) { 159 dest = destinationInterceptor.intercept(dest); 160 } 161 dest.start(); 162 addSubscriptionsForDestination(context, dest); 163 destinations.put(destination, dest); 164 updateRegionDestCounts(destination, 1); 165 destinationMap.unsynchronizedPut(destination, dest); 166 } 167 if (dest == null) { 168 throw new DestinationDoesNotExistException(destination.getQualifiedName()); 169 } 170 } 171 return dest; 172 } finally { 173 destinationsLock.writeLock().unlock(); 174 } 175 } 176 177 public Map<ConsumerId, Subscription> getSubscriptions() { 178 return subscriptions; 179 } 180 181 182 /** 183 * Updates the counts in RegionStatistics based on whether or not the destination 184 * is an Advisory Destination or not 185 * 186 * @param destination the destination being used to determine which counters to update 187 * @param count the count to add to the counters 188 */ 189 protected void updateRegionDestCounts(ActiveMQDestination destination, int count) { 190 if (destination != null) { 191 if (AdvisorySupport.isAdvisoryTopic(destination)) { 192 regionStatistics.getAdvisoryDestinations().add(count); 193 } else { 194 regionStatistics.getDestinations().add(count); 195 } 196 regionStatistics.getAllDestinations().add(count); 197 } 198 } 199 200 /** 201 * This method checks whether or not the destination can be created based on 202 * {@link PolicyEntry#getMaxDestinations}, if it has been set. Advisory 203 * topics are ignored. 204 * 205 * @param destination 206 * @throws Exception 207 */ 208 protected void validateMaxDestinations(ActiveMQDestination destination) 209 throws Exception { 210 if (broker.getDestinationPolicy() != null) { 211 PolicyEntry entry = broker.getDestinationPolicy().getEntryFor(destination); 212 // Make sure the destination is not an advisory topic 213 if (entry != null && entry.getMaxDestinations() >= 0 214 && !AdvisorySupport.isAdvisoryTopic(destination)) { 215 // If there is an entry for this destination, look up the set of 216 // destinations associated with this policy 217 // If a destination isn't specified, then just count up 218 // non-advisory destinations (ie count all destinations) 219 int destinationSize = (int) (entry.getDestination() != null ? 220 destinationMap.unsynchronizedGet(entry.getDestination()).size() : regionStatistics.getDestinations().getCount()); 221 if (destinationSize >= entry.getMaxDestinations()) { 222 if (entry.getDestination() != null) { 223 throw new IllegalStateException( 224 "The maxmimum number of destinations allowed ("+ entry.getMaxDestinations() + 225 ") for the policy " + entry.getDestination() + " has already been reached."); 226 // No destination has been set (default policy) 227 } else { 228 throw new IllegalStateException("The maxmimum number of destinations allowed (" 229 + entry.getMaxDestinations() + ") has already been reached."); 230 } 231 } 232 } 233 } 234 } 235 236 protected List<Subscription> addSubscriptionsForDestination(ConnectionContext context, Destination dest) throws Exception { 237 List<Subscription> rc = new ArrayList<Subscription>(); 238 // Add all consumers that are interested in the destination. 239 for (Iterator<Subscription> iter = subscriptions.values().iterator(); iter.hasNext();) { 240 Subscription sub = iter.next(); 241 if (sub.matches(dest.getActiveMQDestination())) { 242 try { 243 ConnectionContext originalContext = sub.getContext() != null ? sub.getContext() : context; 244 dest.addSubscription(originalContext, sub); 245 rc.add(sub); 246 } catch (SecurityException e) { 247 if (sub.isWildcard()) { 248 LOG.debug("Subscription denied for {} to destination {}: {}", 249 sub, dest.getActiveMQDestination(), e.getMessage()); 250 } else { 251 throw e; 252 } 253 } 254 } 255 } 256 return rc; 257 258 } 259 260 @Override 261 public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) 262 throws Exception { 263 264 // No timeout.. then try to shut down right way, fails if there are 265 // current subscribers. 266 if (timeout == 0) { 267 for (Iterator<Subscription> iter = subscriptions.values().iterator(); iter.hasNext();) { 268 Subscription sub = iter.next(); 269 if (sub.matches(destination) ) { 270 throw new JMSException("Destination still has an active subscription: " + destination); 271 } 272 } 273 } 274 275 if (timeout > 0) { 276 // TODO: implement a way to notify the subscribers that we want to 277 // take the down 278 // the destination and that they should un-subscribe.. Then wait up 279 // to timeout time before 280 // dropping the subscription. 281 } 282 283 LOG.debug("{} removing destination: {}", broker.getBrokerName(), destination); 284 285 destinationsLock.writeLock().lock(); 286 try { 287 Destination dest = destinations.remove(destination); 288 if (dest != null) { 289 updateRegionDestCounts(destination, -1); 290 291 // timeout<0 or we timed out, we now force any remaining 292 // subscriptions to un-subscribe. 293 for (Iterator<Subscription> iter = subscriptions.values().iterator(); iter.hasNext();) { 294 Subscription sub = iter.next(); 295 if (sub.matches(destination)) { 296 dest.removeSubscription(context, sub, 0l); 297 } 298 } 299 destinationMap.unsynchronizedRemove(destination, dest); 300 if (dest instanceof Queue){ 301 ((Queue) dest).purge(); 302 } 303 dispose(context, dest); 304 DestinationInterceptor destinationInterceptor = broker.getDestinationInterceptor(); 305 if (destinationInterceptor != null) { 306 destinationInterceptor.remove(dest); 307 } 308 309 } else { 310 LOG.debug("Cannot remove a destination that doesn't exist: {}", destination); 311 } 312 } finally { 313 destinationsLock.writeLock().unlock(); 314 } 315 } 316 317 /** 318 * Provide an exact or wildcard lookup of destinations in the region 319 * 320 * @return a set of matching destination objects. 321 */ 322 @Override 323 @SuppressWarnings("unchecked") 324 public Set<Destination> getDestinations(ActiveMQDestination destination) { 325 destinationsLock.readLock().lock(); 326 try{ 327 return destinationMap.unsynchronizedGet(destination); 328 } finally { 329 destinationsLock.readLock().unlock(); 330 } 331 } 332 333 @Override 334 public Map<ActiveMQDestination, Destination> getDestinationMap() { 335 return destinations; 336 } 337 338 @Override 339 @SuppressWarnings("unchecked") 340 public Subscription addConsumer(ConnectionContext context, ConsumerInfo info) throws Exception { 341 LOG.debug("{} adding consumer: {} for destination: {}", 342 broker.getBrokerName(), info.getConsumerId(), info.getDestination()); 343 ActiveMQDestination destination = info.getDestination(); 344 if (destination != null && !destination.isPattern() && !destination.isComposite()) { 345 // lets auto-create the destination 346 lookup(context, destination,true); 347 } 348 349 Object addGuard; 350 synchronized (consumerChangeMutexMap) { 351 addGuard = consumerChangeMutexMap.get(info.getConsumerId()); 352 if (addGuard == null) { 353 addGuard = new Object(); 354 consumerChangeMutexMap.put(info.getConsumerId(), addGuard); 355 } 356 } 357 synchronized (addGuard) { 358 Subscription o = subscriptions.get(info.getConsumerId()); 359 if (o != null) { 360 LOG.warn("A duplicate subscription was detected. Clients may be misbehaving. Later warnings you may see about subscription removal are a consequence of this."); 361 return o; 362 } 363 364 // We may need to add some destinations that are in persistent store 365 // but not active 366 // in the broker. 367 // 368 // TODO: think about this a little more. This is good cause 369 // destinations are not loaded into 370 // memory until a client needs to use the queue, but a management 371 // agent viewing the 372 // broker will not see a destination that exists in persistent 373 // store. We may want to 374 // eagerly load all destinations into the broker but have an 375 // inactive state for the 376 // destination which has reduced memory usage. 377 // 378 DestinationFilter.parseFilter(info.getDestination()); 379 380 Subscription sub = createSubscription(context, info); 381 382 // At this point we're done directly manipulating subscriptions, 383 // but we need to retain the synchronized block here. Consider 384 // otherwise what would happen if at this point a second 385 // thread added, then removed, as would be allowed with 386 // no mutex held. Remove is only essentially run once 387 // so everything after this point would be leaked. 388 389 // Add the subscription to all the matching queues. 390 // But copy the matches first - to prevent deadlocks 391 List<Destination> addList = new ArrayList<Destination>(); 392 destinationsLock.readLock().lock(); 393 try { 394 for (Destination dest : (Set<Destination>) destinationMap.unsynchronizedGet(info.getDestination())) { 395 addList.add(dest); 396 } 397 // ensure sub visible to any new dest addSubscriptionsForDestination 398 subscriptions.put(info.getConsumerId(), sub); 399 } finally { 400 destinationsLock.readLock().unlock(); 401 } 402 403 List<Destination> removeList = new ArrayList<Destination>(); 404 for (Destination dest : addList) { 405 try { 406 dest.addSubscription(context, sub); 407 removeList.add(dest); 408 } catch (SecurityException e){ 409 if (sub.isWildcard()) { 410 LOG.debug("Subscription denied for {} to destination {}: {}", 411 sub, dest.getActiveMQDestination(), e.getMessage()); 412 } else { 413 // remove partial subscriptions 414 for (Destination remove : removeList) { 415 try { 416 remove.removeSubscription(context, sub, info.getLastDeliveredSequenceId()); 417 } catch (Exception ex) { 418 LOG.error("Error unsubscribing {} from {}: {}", 419 sub, remove, ex.getMessage(), ex); 420 } 421 } 422 subscriptions.remove(info.getConsumerId()); 423 removeList.clear(); 424 throw e; 425 } 426 } 427 } 428 removeList.clear(); 429 430 if (info.isBrowser()) { 431 ((QueueBrowserSubscription) sub).destinationsAdded(); 432 } 433 434 return sub; 435 } 436 } 437 438 /** 439 * Get all the Destinations that are in storage 440 * 441 * @return Set of all stored destinations 442 */ 443 @SuppressWarnings("rawtypes") 444 public Set getDurableDestinations() { 445 return destinationFactory.getDestinations(); 446 } 447 448 /** 449 * @return all Destinations that don't have active consumers 450 */ 451 protected Set<ActiveMQDestination> getInactiveDestinations() { 452 Set<ActiveMQDestination> inactiveDests = destinationFactory.getDestinations(); 453 destinationsLock.readLock().lock(); 454 try { 455 inactiveDests.removeAll(destinations.keySet()); 456 } finally { 457 destinationsLock.readLock().unlock(); 458 } 459 return inactiveDests; 460 } 461 462 @Override 463 @SuppressWarnings("unchecked") 464 public void removeConsumer(ConnectionContext context, ConsumerInfo info) throws Exception { 465 LOG.debug("{} removing consumer: {} for destination: {}", 466 broker.getBrokerName(), info.getConsumerId(), info.getDestination()); 467 468 Subscription sub = subscriptions.remove(info.getConsumerId()); 469 // The sub could be removed elsewhere - see ConnectionSplitBroker 470 if (sub != null) { 471 472 // remove the subscription from all the matching queues. 473 List<Destination> removeList = new ArrayList<Destination>(); 474 destinationsLock.readLock().lock(); 475 try { 476 for (Destination dest : (Set<Destination>) destinationMap.unsynchronizedGet(info.getDestination())) { 477 removeList.add(dest); 478 } 479 } finally { 480 destinationsLock.readLock().unlock(); 481 } 482 for (Destination dest : removeList) { 483 dest.removeSubscription(context, sub, info.getLastDeliveredSequenceId()); 484 } 485 486 destroySubscription(sub); 487 } 488 synchronized (consumerChangeMutexMap) { 489 consumerChangeMutexMap.remove(info.getConsumerId()); 490 } 491 } 492 493 protected void destroySubscription(Subscription sub) { 494 sub.destroy(); 495 } 496 497 @Override 498 public void removeSubscription(ConnectionContext context, RemoveSubscriptionInfo info) throws Exception { 499 throw new JMSException("Invalid operation."); 500 } 501 502 @Override 503 public void send(final ProducerBrokerExchange producerExchange, Message messageSend) throws Exception { 504 final ConnectionContext context = producerExchange.getConnectionContext(); 505 506 if (producerExchange.isMutable() || producerExchange.getRegionDestination() == null) { 507 final Destination regionDestination = lookup(context, messageSend.getDestination(),false); 508 producerExchange.setRegionDestination(regionDestination); 509 } 510 511 producerExchange.getRegionDestination().send(producerExchange, messageSend); 512 513 if (producerExchange.getProducerState() != null && producerExchange.getProducerState().getInfo() != null){ 514 producerExchange.getProducerState().getInfo().incrementSentCount(); 515 } 516 } 517 518 @Override 519 public void acknowledge(ConsumerBrokerExchange consumerExchange, MessageAck ack) throws Exception { 520 Subscription sub = consumerExchange.getSubscription(); 521 if (sub == null) { 522 sub = subscriptions.get(ack.getConsumerId()); 523 if (sub == null) { 524 if (!consumerExchange.getConnectionContext().isInRecoveryMode()) { 525 LOG.warn("Ack for non existent subscription, ack: {}", ack); 526 throw new IllegalArgumentException("The subscription does not exist: " + ack.getConsumerId()); 527 } else { 528 LOG.debug("Ack for non existent subscription in recovery, ack: {}", ack); 529 return; 530 } 531 } 532 consumerExchange.setSubscription(sub); 533 } 534 sub.acknowledge(consumerExchange.getConnectionContext(), ack); 535 } 536 537 @Override 538 public Response messagePull(ConnectionContext context, MessagePull pull) throws Exception { 539 Subscription sub = subscriptions.get(pull.getConsumerId()); 540 if (sub == null) { 541 throw new IllegalArgumentException("The subscription does not exist: " + pull.getConsumerId()); 542 } 543 return sub.pullMessage(context, pull); 544 } 545 546 protected Destination lookup(ConnectionContext context, ActiveMQDestination destination,boolean createTemporary) throws Exception { 547 Destination dest = null; 548 549 destinationsLock.readLock().lock(); 550 try { 551 dest = destinations.get(destination); 552 } finally { 553 destinationsLock.readLock().unlock(); 554 } 555 556 if (dest == null) { 557 if (isAutoCreateDestinations()) { 558 // Try to auto create the destination... re-invoke broker 559 // from the 560 // top so that the proper security checks are performed. 561 dest = context.getBroker().addDestination(context, destination, createTemporary); 562 } 563 564 if (dest == null) { 565 throw new JMSException("The destination " + destination + " does not exist."); 566 } 567 } 568 return dest; 569 } 570 571 @Override 572 public void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception { 573 Subscription sub = subscriptions.get(messageDispatchNotification.getConsumerId()); 574 if (sub != null) { 575 sub.processMessageDispatchNotification(messageDispatchNotification); 576 } else { 577 throw new JMSException("Slave broker out of sync with master - Subscription: " 578 + messageDispatchNotification.getConsumerId() + " on " 579 + messageDispatchNotification.getDestination() + " does not exist for dispatch of message: " 580 + messageDispatchNotification.getMessageId()); 581 } 582 } 583 584 /* 585 * For a Queue/TempQueue, dispatch order is imperative to match acks, so the 586 * dispatch is deferred till the notification to ensure that the 587 * subscription chosen by the master is used. AMQ-2102 588 */ 589 protected void processDispatchNotificationViaDestination(MessageDispatchNotification messageDispatchNotification) 590 throws Exception { 591 Destination dest = null; 592 destinationsLock.readLock().lock(); 593 try { 594 dest = destinations.get(messageDispatchNotification.getDestination()); 595 } finally { 596 destinationsLock.readLock().unlock(); 597 } 598 599 if (dest != null) { 600 dest.processDispatchNotification(messageDispatchNotification); 601 } else { 602 throw new JMSException("Slave broker out of sync with master - Destination: " 603 + messageDispatchNotification.getDestination() + " does not exist for consumer " 604 + messageDispatchNotification.getConsumerId() + " with message: " 605 + messageDispatchNotification.getMessageId()); 606 } 607 } 608 609 @Override 610 public void gc() { 611 for (Subscription sub : subscriptions.values()) { 612 sub.gc(); 613 } 614 615 destinationsLock.readLock().lock(); 616 try { 617 for (Destination dest : destinations.values()) { 618 dest.gc(); 619 } 620 } finally { 621 destinationsLock.readLock().unlock(); 622 } 623 } 624 625 protected abstract Subscription createSubscription(ConnectionContext context, ConsumerInfo info) throws Exception; 626 627 protected Destination createDestination(ConnectionContext context, ActiveMQDestination destination) 628 throws Exception { 629 return destinationFactory.createDestination(context, destination, destinationStatistics); 630 } 631 632 public boolean isAutoCreateDestinations() { 633 return autoCreateDestinations; 634 } 635 636 public void setAutoCreateDestinations(boolean autoCreateDestinations) { 637 this.autoCreateDestinations = autoCreateDestinations; 638 } 639 640 @Override 641 @SuppressWarnings("unchecked") 642 public void addProducer(ConnectionContext context, ProducerInfo info) throws Exception { 643 destinationsLock.readLock().lock(); 644 try { 645 for (Destination dest : (Set<Destination>) destinationMap.unsynchronizedGet(info.getDestination())) { 646 dest.addProducer(context, info); 647 } 648 } finally { 649 destinationsLock.readLock().unlock(); 650 } 651 } 652 653 /** 654 * Removes a Producer. 655 * 656 * @param context 657 * the environment the operation is being executed under. 658 * @throws Exception 659 * TODO 660 */ 661 @Override 662 @SuppressWarnings("unchecked") 663 public void removeProducer(ConnectionContext context, ProducerInfo info) throws Exception { 664 destinationsLock.readLock().lock(); 665 try { 666 for (Destination dest : (Set<Destination>) destinationMap.unsynchronizedGet(info.getDestination())) { 667 dest.removeProducer(context, info); 668 } 669 } finally { 670 destinationsLock.readLock().unlock(); 671 } 672 } 673 674 protected void dispose(ConnectionContext context, Destination dest) throws Exception { 675 dest.dispose(context); 676 dest.stop(); 677 destinationFactory.removeDestination(dest); 678 } 679 680 @Override 681 public void processConsumerControl(ConsumerBrokerExchange consumerExchange, ConsumerControl control) { 682 Subscription sub = subscriptions.get(control.getConsumerId()); 683 if (sub != null && sub instanceof AbstractSubscription) { 684 ((AbstractSubscription) sub).setPrefetchSize(control.getPrefetch()); 685 if (broker.getDestinationPolicy() != null) { 686 PolicyEntry entry = broker.getDestinationPolicy().getEntryFor(control.getDestination()); 687 if (entry != null) { 688 entry.configurePrefetch(sub); 689 } 690 } 691 LOG.debug("setting prefetch: {}, on subscription: {}; resulting value: {}", 692 control.getPrefetch(), control.getConsumerId(), sub.getConsumerInfo().getPrefetchSize()); 693 try { 694 lookup(consumerExchange.getConnectionContext(), control.getDestination(),false).wakeup(); 695 } catch (Exception e) { 696 LOG.warn("failed to deliver post consumerControl dispatch-wakeup, to destination: {}", control.getDestination(), e); 697 } 698 } 699 } 700 701 @Override 702 public void reapplyInterceptor() { 703 destinationsLock.writeLock().lock(); 704 try { 705 DestinationInterceptor destinationInterceptor = broker.getDestinationInterceptor(); 706 Map<ActiveMQDestination, Destination> map = getDestinationMap(); 707 for (ActiveMQDestination key : map.keySet()) { 708 Destination destination = map.get(key); 709 if (destination instanceof CompositeDestinationFilter) { 710 destination = ((CompositeDestinationFilter) destination).next; 711 } 712 if (destinationInterceptor != null) { 713 destination = destinationInterceptor.intercept(destination); 714 } 715 getDestinationMap().put(key, destination); 716 Destination prev = destinations.put(key, destination); 717 if (prev == null) { 718 updateRegionDestCounts(key, 1); 719 } 720 } 721 } finally { 722 destinationsLock.writeLock().unlock(); 723 } 724 } 725}