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.policy;
018
019import java.util.Set;
020
021import org.apache.activemq.ActiveMQPrefetchPolicy;
022import org.apache.activemq.broker.Broker;
023import org.apache.activemq.broker.region.BaseDestination;
024import org.apache.activemq.broker.region.Destination;
025import org.apache.activemq.broker.region.DurableTopicSubscription;
026import org.apache.activemq.broker.region.Queue;
027import org.apache.activemq.broker.region.QueueBrowserSubscription;
028import org.apache.activemq.broker.region.QueueSubscription;
029import org.apache.activemq.broker.region.Subscription;
030import org.apache.activemq.broker.region.Topic;
031import org.apache.activemq.broker.region.TopicSubscription;
032import org.apache.activemq.broker.region.cursors.PendingMessageCursor;
033import org.apache.activemq.broker.region.group.GroupFactoryFinder;
034import org.apache.activemq.broker.region.group.MessageGroupMapFactory;
035import org.apache.activemq.filter.DestinationMapEntry;
036import org.apache.activemq.network.NetworkBridgeFilterFactory;
037import org.apache.activemq.usage.SystemUsage;
038import org.slf4j.Logger;
039import org.slf4j.LoggerFactory;
040
041/**
042 * Represents an entry in a {@link PolicyMap} for assigning policies to a
043 * specific destination or a hierarchical wildcard area of destinations.
044 *
045 * @org.apache.xbean.XBean
046 *
047 */
048public class PolicyEntry extends DestinationMapEntry {
049
050    private static final Logger LOG = LoggerFactory.getLogger(PolicyEntry.class);
051    private DispatchPolicy dispatchPolicy;
052    private SubscriptionRecoveryPolicy subscriptionRecoveryPolicy;
053    private boolean sendAdvisoryIfNoConsumers;
054    private boolean sendDuplicateFromStoreToDLQ = true;
055    private DeadLetterStrategy deadLetterStrategy = Destination.DEFAULT_DEAD_LETTER_STRATEGY;
056    private PendingMessageLimitStrategy pendingMessageLimitStrategy;
057    private MessageEvictionStrategy messageEvictionStrategy;
058    private long memoryLimit;
059    private String messageGroupMapFactoryType = "cached";
060    private MessageGroupMapFactory messageGroupMapFactory;
061    private PendingQueueMessageStoragePolicy pendingQueuePolicy;
062    private PendingDurableSubscriberMessageStoragePolicy pendingDurableSubscriberPolicy;
063    private PendingSubscriberMessageStoragePolicy pendingSubscriberPolicy;
064    private int maxProducersToAudit=BaseDestination.MAX_PRODUCERS_TO_AUDIT;
065    private int maxAuditDepth=BaseDestination.MAX_AUDIT_DEPTH;
066    private int maxQueueAuditDepth=BaseDestination.MAX_AUDIT_DEPTH;
067    private boolean enableAudit=true;
068    private boolean producerFlowControl = true;
069    private boolean alwaysRetroactive = false;
070    private long blockedProducerWarningInterval = Destination.DEFAULT_BLOCKED_PRODUCER_WARNING_INTERVAL;
071    private boolean optimizedDispatch=false;
072    private int maxPageSize=BaseDestination.MAX_PAGE_SIZE;
073    private int maxBrowsePageSize=BaseDestination.MAX_BROWSE_PAGE_SIZE;
074    private boolean useCache=true;
075    private long minimumMessageSize=1024;
076    private boolean useConsumerPriority=true;
077    private boolean strictOrderDispatch=false;
078    private boolean lazyDispatch=false;
079    private int timeBeforeDispatchStarts = 0;
080    private int consumersBeforeDispatchStarts = 0;
081    private boolean advisoryForSlowConsumers;
082    private boolean advisoryForFastProducers;
083    private boolean advisoryForDiscardingMessages;
084    private boolean advisoryWhenFull;
085    private boolean advisoryForDelivery;
086    private boolean advisoryForConsumed;
087    private boolean includeBodyForAdvisory;
088    private long expireMessagesPeriod = BaseDestination.EXPIRE_MESSAGE_PERIOD;
089    private int maxExpirePageSize = BaseDestination.MAX_BROWSE_PAGE_SIZE;
090    private int queuePrefetch=ActiveMQPrefetchPolicy.DEFAULT_QUEUE_PREFETCH;
091    private int queueBrowserPrefetch=ActiveMQPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH;
092    private int topicPrefetch=ActiveMQPrefetchPolicy.DEFAULT_TOPIC_PREFETCH;
093    private int durableTopicPrefetch=ActiveMQPrefetchPolicy.DEFAULT_DURABLE_TOPIC_PREFETCH;
094    private boolean usePrefetchExtension = true;
095    private int cursorMemoryHighWaterMark = 70;
096    private int storeUsageHighWaterMark = 100;
097    private SlowConsumerStrategy slowConsumerStrategy;
098    private boolean prioritizedMessages;
099    private boolean allConsumersExclusiveByDefault;
100    private boolean gcInactiveDestinations;
101    private boolean gcWithNetworkConsumers;
102    private long inactiveTimeoutBeforeGC = BaseDestination.DEFAULT_INACTIVE_TIMEOUT_BEFORE_GC;
103    private boolean reduceMemoryFootprint;
104    private NetworkBridgeFilterFactory networkBridgeFilterFactory;
105    private boolean doOptimzeMessageStorage = true;
106    private int maxDestinations = -1;
107    private boolean useTopicSubscriptionInflightStats = true;
108
109    /*
110     * percentage of in-flight messages above which optimize message store is disabled
111     */
112    private int optimizeMessageStoreInFlightLimit = 10;
113    private boolean persistJMSRedelivered = false;
114    private int sendFailIfNoSpace = -1;
115    private long sendFailIfNoSpaceAfterTimeout = -1;
116
117
118    public void configure(Broker broker,Queue queue) {
119        baseConfiguration(broker,queue);
120        if (dispatchPolicy != null) {
121            queue.setDispatchPolicy(dispatchPolicy);
122        }
123        queue.setDeadLetterStrategy(getDeadLetterStrategy());
124        queue.setMessageGroupMapFactory(getMessageGroupMapFactory());
125        if (memoryLimit > 0) {
126            queue.getMemoryUsage().setLimit(memoryLimit);
127        }
128        if (pendingQueuePolicy != null) {
129            PendingMessageCursor messages = pendingQueuePolicy.getQueuePendingMessageCursor(broker,queue);
130            queue.setMessages(messages);
131        }
132
133        queue.setUseConsumerPriority(isUseConsumerPriority());
134        queue.setStrictOrderDispatch(isStrictOrderDispatch());
135        queue.setOptimizedDispatch(isOptimizedDispatch());
136        queue.setLazyDispatch(isLazyDispatch());
137        queue.setTimeBeforeDispatchStarts(getTimeBeforeDispatchStarts());
138        queue.setConsumersBeforeDispatchStarts(getConsumersBeforeDispatchStarts());
139        queue.setAllConsumersExclusiveByDefault(isAllConsumersExclusiveByDefault());
140        queue.setPersistJMSRedelivered(isPersistJMSRedelivered());
141    }
142
143    public void update(Queue queue) {
144        update(queue, null);
145    }
146
147    /**
148     * Update a queue with this policy.  Only apply properties that
149     * match the includedProperties list.  Not all properties are eligible
150     * to be updated.
151     *
152     * If includedProperties is null then all of the properties will be set as
153     * isUpdate will return true
154     * @param queue
155     * @param includedProperties
156     */
157    public void update(Queue queue, Set<String> includedProperties) {
158        baseUpdate(queue, includedProperties);
159        if (isUpdate("memoryLimit", includedProperties) && memoryLimit > 0) {
160            queue.getMemoryUsage().setLimit(memoryLimit);
161        }
162        if (isUpdate("useConsumerPriority", includedProperties)) {
163            queue.setUseConsumerPriority(isUseConsumerPriority());
164        }
165        if (isUpdate("strictOrderDispatch", includedProperties)) {
166            queue.setStrictOrderDispatch(isStrictOrderDispatch());
167        }
168        if (isUpdate("optimizedDispatch", includedProperties)) {
169            queue.setOptimizedDispatch(isOptimizedDispatch());
170        }
171        if (isUpdate("lazyDispatch", includedProperties)) {
172            queue.setLazyDispatch(isLazyDispatch());
173        }
174        if (isUpdate("timeBeforeDispatchStarts", includedProperties)) {
175            queue.setTimeBeforeDispatchStarts(getTimeBeforeDispatchStarts());
176        }
177        if (isUpdate("consumersBeforeDispatchStarts", includedProperties)) {
178            queue.setConsumersBeforeDispatchStarts(getConsumersBeforeDispatchStarts());
179        }
180        if (isUpdate("allConsumersExclusiveByDefault", includedProperties)) {
181            queue.setAllConsumersExclusiveByDefault(isAllConsumersExclusiveByDefault());
182        }
183        if (isUpdate("persistJMSRedelivered", includedProperties)) {
184            queue.setPersistJMSRedelivered(isPersistJMSRedelivered());
185        }
186    }
187
188    public void configure(Broker broker,Topic topic) {
189        baseConfiguration(broker,topic);
190        if (dispatchPolicy != null) {
191            topic.setDispatchPolicy(dispatchPolicy);
192        }
193        topic.setDeadLetterStrategy(getDeadLetterStrategy());
194        if (subscriptionRecoveryPolicy != null) {
195            SubscriptionRecoveryPolicy srp = subscriptionRecoveryPolicy.copy();
196            srp.setBroker(broker);
197            topic.setSubscriptionRecoveryPolicy(srp);
198        }
199        if (memoryLimit > 0) {
200            topic.getMemoryUsage().setLimit(memoryLimit);
201        }
202        topic.setLazyDispatch(isLazyDispatch());
203    }
204
205    public void update(Topic topic) {
206        update(topic, null);
207    }
208
209    //If includedProperties is null then all of the properties will be set as
210    //isUpdate will return true
211    public void update(Topic topic, Set<String> includedProperties) {
212        baseUpdate(topic, includedProperties);
213        if (isUpdate("memoryLimit", includedProperties) && memoryLimit > 0) {
214            topic.getMemoryUsage().setLimit(memoryLimit);
215        }
216        if (isUpdate("lazyDispatch", includedProperties)) {
217            topic.setLazyDispatch(isLazyDispatch());
218        }
219    }
220
221    // attributes that can change on the fly
222    public void baseUpdate(BaseDestination destination) {
223        baseUpdate(destination, null);
224    }
225
226    // attributes that can change on the fly
227    //If includedProperties is null then all of the properties will be set as
228    //isUpdate will return true
229    public void baseUpdate(BaseDestination destination, Set<String> includedProperties) {
230        if (isUpdate("producerFlowControl", includedProperties)) {
231            destination.setProducerFlowControl(isProducerFlowControl());
232        }
233        if (isUpdate("alwaysRetroactive", includedProperties)) {
234            destination.setAlwaysRetroactive(isAlwaysRetroactive());
235        }
236        if (isUpdate("blockedProducerWarningInterval", includedProperties)) {
237            destination.setBlockedProducerWarningInterval(getBlockedProducerWarningInterval());
238        }
239        if (isUpdate("maxPageSize", includedProperties)) {
240            destination.setMaxPageSize(getMaxPageSize());
241        }
242        if (isUpdate("maxBrowsePageSize", includedProperties)) {
243            destination.setMaxBrowsePageSize(getMaxBrowsePageSize());
244        }
245        if (isUpdate("minimumMessageSize", includedProperties)) {
246            destination.setMinimumMessageSize((int) getMinimumMessageSize());
247        }
248        if (isUpdate("maxExpirePageSize", includedProperties)) {
249            destination.setMaxExpirePageSize(getMaxExpirePageSize());
250        }
251        if (isUpdate("cursorMemoryHighWaterMark", includedProperties)) {
252            destination.setCursorMemoryHighWaterMark(getCursorMemoryHighWaterMark());
253        }
254        if (isUpdate("storeUsageHighWaterMark", includedProperties)) {
255            destination.setStoreUsageHighWaterMark(getStoreUsageHighWaterMark());
256        }
257        if (isUpdate("gcInactiveDestinations", includedProperties)) {
258            destination.setGcIfInactive(isGcInactiveDestinations());
259        }
260        if (isUpdate("gcWithNetworkConsumers", includedProperties)) {
261            destination.setGcWithNetworkConsumers(isGcWithNetworkConsumers());
262        }
263        if (isUpdate("inactiveTimeoutBeforeGc", includedProperties)) {
264            destination.setInactiveTimeoutBeforeGC(getInactiveTimeoutBeforeGC());
265        }
266        if (isUpdate("reduceMemoryFootprint", includedProperties)) {
267            destination.setReduceMemoryFootprint(isReduceMemoryFootprint());
268        }
269        if (isUpdate("doOptimizeMessageStore", includedProperties)) {
270            destination.setDoOptimzeMessageStorage(isDoOptimzeMessageStorage());
271        }
272        if (isUpdate("optimizeMessageStoreInFlightLimit", includedProperties)) {
273            destination.setOptimizeMessageStoreInFlightLimit(getOptimizeMessageStoreInFlightLimit());
274        }
275        if (isUpdate("advisoryForConsumed", includedProperties)) {
276            destination.setAdvisoryForConsumed(isAdvisoryForConsumed());
277        }
278        if (isUpdate("advisoryForDelivery", includedProperties)) {
279            destination.setAdvisoryForDelivery(isAdvisoryForDelivery());
280        }
281        if (isUpdate("advisoryForDiscardingMessages", includedProperties)) {
282            destination.setAdvisoryForDiscardingMessages(isAdvisoryForDiscardingMessages());
283        }
284        if (isUpdate("advisoryForSlowConsumers", includedProperties)) {
285            destination.setAdvisoryForSlowConsumers(isAdvisoryForSlowConsumers());
286        }
287        if (isUpdate("advisoryForFastProducers", includedProperties)) {
288            destination.setAdvisoryForFastProducers(isAdvisoryForFastProducers());
289        }
290        if (isUpdate("advisoryWhenFull", includedProperties)) {
291            destination.setAdvisoryWhenFull(isAdvisoryWhenFull());
292        }
293        if (isUpdate("includeBodyForAdvisory", includedProperties)) {
294            destination.setIncludeBodyForAdvisory(isIncludeBodyForAdvisory());
295        }
296        if (isUpdate("sendAdvisoryIfNoConsumers", includedProperties)) {
297            destination.setSendAdvisoryIfNoConsumers(isSendAdvisoryIfNoConsumers());
298        }
299        if (isUpdate("sendDuplicateFromStoreToDLQ", includedProperties)) {
300            destination.setSendDuplicateFromStoreToDLQ(isSendDuplicateFromStoreToDLQ());
301        }
302    }
303
304    public void baseConfiguration(Broker broker, BaseDestination destination) {
305        baseUpdate(destination);
306        destination.setEnableAudit(isEnableAudit());
307        destination.setMaxAuditDepth(getMaxQueueAuditDepth());
308        destination.setMaxProducersToAudit(getMaxProducersToAudit());
309        destination.setUseCache(isUseCache());
310        destination.setExpireMessagesPeriod(getExpireMessagesPeriod());
311        SlowConsumerStrategy scs = getSlowConsumerStrategy();
312        if (scs != null) {
313            scs.setBrokerService(broker);
314            scs.addDestination(destination);
315        }
316        destination.setSlowConsumerStrategy(scs);
317        destination.setPrioritizedMessages(isPrioritizedMessages());
318        if (sendFailIfNoSpace != -1) {
319            destination.getSystemUsage().setSendFailIfNoSpace(isSendFailIfNoSpace());
320        }
321        if (sendFailIfNoSpaceAfterTimeout != -1) {
322            destination.getSystemUsage().setSendFailIfNoSpaceAfterTimeout(getSendFailIfNoSpaceAfterTimeout());
323        }
324    }
325
326    public void configure(Broker broker, SystemUsage memoryManager, TopicSubscription subscription) {
327        configurePrefetch(subscription);
328        subscription.setUsePrefetchExtension(isUsePrefetchExtension());
329        subscription.setCursorMemoryHighWaterMark(getCursorMemoryHighWaterMark());
330        subscription.setUseTopicSubscriptionInflightStats(isUseTopicSubscriptionInflightStats());
331        if (pendingMessageLimitStrategy != null) {
332            int value = pendingMessageLimitStrategy.getMaximumPendingMessageLimit(subscription);
333            int consumerLimit = subscription.getInfo().getMaximumPendingMessageLimit();
334            if (consumerLimit > 0) {
335                if (value < 0 || consumerLimit < value) {
336                    value = consumerLimit;
337                }
338            }
339            if (value >= 0) {
340                LOG.debug("Setting the maximumPendingMessages size to: {} for consumer: {}", value, subscription.getInfo().getConsumerId());
341                subscription.setMaximumPendingMessages(value);
342            }
343        }
344        if (messageEvictionStrategy != null) {
345            subscription.setMessageEvictionStrategy(messageEvictionStrategy);
346        }
347        if (pendingSubscriberPolicy != null) {
348            String name = subscription.getContext().getClientId() + "_" + subscription.getConsumerInfo().getConsumerId();
349            int maxBatchSize = subscription.getConsumerInfo().getPrefetchSize();
350            subscription.setMatched(pendingSubscriberPolicy.getSubscriberPendingMessageCursor(broker,name, maxBatchSize,subscription));
351        }
352        if (enableAudit) {
353            subscription.setEnableAudit(enableAudit);
354            subscription.setMaxProducersToAudit(maxProducersToAudit);
355            subscription.setMaxAuditDepth(maxAuditDepth);
356        }
357    }
358
359    public void configure(Broker broker, SystemUsage memoryManager, DurableTopicSubscription sub) {
360        String clientId = sub.getSubscriptionKey().getClientId();
361        String subName = sub.getSubscriptionKey().getSubscriptionName();
362        sub.setCursorMemoryHighWaterMark(getCursorMemoryHighWaterMark());
363        configurePrefetch(sub);
364        if (pendingDurableSubscriberPolicy != null) {
365            PendingMessageCursor cursor = pendingDurableSubscriberPolicy.getSubscriberPendingMessageCursor(broker,clientId, subName,sub.getPrefetchSize(),sub);
366            cursor.setSystemUsage(memoryManager);
367            sub.setPending(cursor);
368        }
369        int auditDepth = getMaxAuditDepth();
370        if (auditDepth == BaseDestination.MAX_AUDIT_DEPTH && this.isPrioritizedMessages()) {
371            sub.setMaxAuditDepth(auditDepth * 10);
372        } else {
373            sub.setMaxAuditDepth(auditDepth);
374        }
375        sub.setMaxProducersToAudit(getMaxProducersToAudit());
376        sub.setUsePrefetchExtension(isUsePrefetchExtension());
377    }
378
379    public void configure(Broker broker, SystemUsage memoryManager, QueueBrowserSubscription sub) {
380        configurePrefetch(sub);
381        sub.setCursorMemoryHighWaterMark(getCursorMemoryHighWaterMark());
382        sub.setUsePrefetchExtension(isUsePrefetchExtension());
383
384        // TODO
385        // We currently need an infinite audit because of the way that browser dispatch
386        // is done.  We should refactor the browsers to better handle message dispatch so
387        // we can remove this and perform a more efficient dispatch.
388        sub.setMaxProducersToAudit(Integer.MAX_VALUE);
389        sub.setMaxAuditDepth(Short.MAX_VALUE);
390
391        // part solution - dispatching to browsers needs to be restricted
392        sub.setMaxMessages(getMaxBrowsePageSize());
393    }
394
395    public void configure(Broker broker, SystemUsage memoryManager, QueueSubscription sub) {
396        configurePrefetch(sub);
397        sub.setCursorMemoryHighWaterMark(getCursorMemoryHighWaterMark());
398        sub.setUsePrefetchExtension(isUsePrefetchExtension());
399        sub.setMaxProducersToAudit(getMaxProducersToAudit());
400    }
401
402    public void configurePrefetch(Subscription subscription) {
403
404        final int currentPrefetch = subscription.getConsumerInfo().getPrefetchSize();
405        if (subscription instanceof QueueBrowserSubscription) {
406            if (currentPrefetch == ActiveMQPrefetchPolicy.DEFAULT_QUEUE_BROWSER_PREFETCH) {
407                ((QueueBrowserSubscription) subscription).setPrefetchSize(getQueueBrowserPrefetch());
408            }
409        } else if (subscription instanceof QueueSubscription) {
410            if (currentPrefetch == ActiveMQPrefetchPolicy.DEFAULT_QUEUE_PREFETCH) {
411                ((QueueSubscription) subscription).setPrefetchSize(getQueuePrefetch());
412            }
413        } else if (subscription instanceof DurableTopicSubscription) {
414            if (currentPrefetch == ActiveMQPrefetchPolicy.DEFAULT_DURABLE_TOPIC_PREFETCH ||
415                    subscription.getConsumerInfo().getPrefetchSize() == ActiveMQPrefetchPolicy.DEFAULT_OPTIMIZE_DURABLE_TOPIC_PREFETCH) {
416                ((DurableTopicSubscription)subscription).setPrefetchSize(getDurableTopicPrefetch());
417            }
418        } else if (subscription instanceof TopicSubscription) {
419            if (currentPrefetch == ActiveMQPrefetchPolicy.DEFAULT_TOPIC_PREFETCH) {
420                ((TopicSubscription) subscription).setPrefetchSize(getTopicPrefetch());
421            }
422        }
423        if (currentPrefetch != 0 && subscription.getPrefetchSize() == 0) {
424            // tell the sub so that it can issue a pull request
425            subscription.updateConsumerPrefetch(0);
426        }
427    }
428
429    private boolean isUpdate(String property, Set<String> includedProperties) {
430        return includedProperties == null || includedProperties.contains(property);
431    }
432    // Properties
433    // -------------------------------------------------------------------------
434    public DispatchPolicy getDispatchPolicy() {
435        return dispatchPolicy;
436    }
437
438    public void setDispatchPolicy(DispatchPolicy policy) {
439        this.dispatchPolicy = policy;
440    }
441
442    public SubscriptionRecoveryPolicy getSubscriptionRecoveryPolicy() {
443        return subscriptionRecoveryPolicy;
444    }
445
446    public void setSubscriptionRecoveryPolicy(SubscriptionRecoveryPolicy subscriptionRecoveryPolicy) {
447        this.subscriptionRecoveryPolicy = subscriptionRecoveryPolicy;
448    }
449
450    public boolean isSendAdvisoryIfNoConsumers() {
451        return sendAdvisoryIfNoConsumers;
452    }
453
454    /**
455     * Sends an advisory message if a non-persistent message is sent and there
456     * are no active consumers
457     */
458    public void setSendAdvisoryIfNoConsumers(boolean sendAdvisoryIfNoConsumers) {
459        this.sendAdvisoryIfNoConsumers = sendAdvisoryIfNoConsumers;
460    }
461
462    public boolean isSendDuplicateFromStoreToDLQ() {
463        return sendDuplicateFromStoreToDLQ;
464    }
465
466    /**
467     * Sends a copy of message to DLQ if a duplicate messages are paged-in from
468     * the messages store
469     */
470    public void setSendDuplicateFromStoreToDLQ(boolean sendDuplicateFromStoreToDLQ) {
471        this.sendDuplicateFromStoreToDLQ = sendDuplicateFromStoreToDLQ;
472    }
473
474    public DeadLetterStrategy getDeadLetterStrategy() {
475        return deadLetterStrategy;
476    }
477
478    /**
479     * Sets the policy used to determine which dead letter queue destination
480     * should be used
481     */
482    public void setDeadLetterStrategy(DeadLetterStrategy deadLetterStrategy) {
483        this.deadLetterStrategy = deadLetterStrategy;
484    }
485
486    public PendingMessageLimitStrategy getPendingMessageLimitStrategy() {
487        return pendingMessageLimitStrategy;
488    }
489
490    /**
491     * Sets the strategy to calculate the maximum number of messages that are
492     * allowed to be pending on consumers (in addition to their prefetch sizes).
493     * Once the limit is reached, non-durable topics can then start discarding
494     * old messages. This allows us to keep dispatching messages to slow
495     * consumers while not blocking fast consumers and discarding the messages
496     * oldest first.
497     */
498    public void setPendingMessageLimitStrategy(PendingMessageLimitStrategy pendingMessageLimitStrategy) {
499        this.pendingMessageLimitStrategy = pendingMessageLimitStrategy;
500    }
501
502    public MessageEvictionStrategy getMessageEvictionStrategy() {
503        return messageEvictionStrategy;
504    }
505
506    /**
507     * Sets the eviction strategy used to decide which message to evict when the
508     * slow consumer needs to discard messages
509     */
510    public void setMessageEvictionStrategy(MessageEvictionStrategy messageEvictionStrategy) {
511        this.messageEvictionStrategy = messageEvictionStrategy;
512    }
513
514    public long getMemoryLimit() {
515        return memoryLimit;
516    }
517
518    /**
519     * When set using Xbean, values of the form "20 Mb", "1024kb", and "1g" can be used
520     * @org.apache.xbean.Property propertyEditor="org.apache.activemq.util.MemoryPropertyEditor"
521     */
522    public void setMemoryLimit(long memoryLimit) {
523        this.memoryLimit = memoryLimit;
524    }
525
526    public MessageGroupMapFactory getMessageGroupMapFactory() {
527        if (messageGroupMapFactory == null) {
528            try {
529            messageGroupMapFactory = GroupFactoryFinder.createMessageGroupMapFactory(getMessageGroupMapFactoryType());
530            }catch(Exception e){
531                LOG.error("Failed to create message group Factory ",e);
532            }
533        }
534        return messageGroupMapFactory;
535    }
536
537    /**
538     * Sets the factory used to create new instances of {MessageGroupMap} used
539     * to implement the <a
540     * href="http://activemq.apache.org/message-groups.html">Message Groups</a>
541     * functionality.
542     */
543    public void setMessageGroupMapFactory(MessageGroupMapFactory messageGroupMapFactory) {
544        this.messageGroupMapFactory = messageGroupMapFactory;
545    }
546
547
548    public String getMessageGroupMapFactoryType() {
549        return messageGroupMapFactoryType;
550    }
551
552    public void setMessageGroupMapFactoryType(String messageGroupMapFactoryType) {
553        this.messageGroupMapFactoryType = messageGroupMapFactoryType;
554    }
555
556
557    /**
558     * @return the pendingDurableSubscriberPolicy
559     */
560    public PendingDurableSubscriberMessageStoragePolicy getPendingDurableSubscriberPolicy() {
561        return this.pendingDurableSubscriberPolicy;
562    }
563
564    /**
565     * @param pendingDurableSubscriberPolicy the pendingDurableSubscriberPolicy
566     *                to set
567     */
568    public void setPendingDurableSubscriberPolicy(PendingDurableSubscriberMessageStoragePolicy pendingDurableSubscriberPolicy) {
569        this.pendingDurableSubscriberPolicy = pendingDurableSubscriberPolicy;
570    }
571
572    /**
573     * @return the pendingQueuePolicy
574     */
575    public PendingQueueMessageStoragePolicy getPendingQueuePolicy() {
576        return this.pendingQueuePolicy;
577    }
578
579    /**
580     * @param pendingQueuePolicy the pendingQueuePolicy to set
581     */
582    public void setPendingQueuePolicy(PendingQueueMessageStoragePolicy pendingQueuePolicy) {
583        this.pendingQueuePolicy = pendingQueuePolicy;
584    }
585
586    /**
587     * @return the pendingSubscriberPolicy
588     */
589    public PendingSubscriberMessageStoragePolicy getPendingSubscriberPolicy() {
590        return this.pendingSubscriberPolicy;
591    }
592
593    /**
594     * @param pendingSubscriberPolicy the pendingSubscriberPolicy to set
595     */
596    public void setPendingSubscriberPolicy(PendingSubscriberMessageStoragePolicy pendingSubscriberPolicy) {
597        this.pendingSubscriberPolicy = pendingSubscriberPolicy;
598    }
599
600    /**
601     * @return true if producer flow control enabled
602     */
603    public boolean isProducerFlowControl() {
604        return producerFlowControl;
605    }
606
607    /**
608     * @param producerFlowControl
609     */
610    public void setProducerFlowControl(boolean producerFlowControl) {
611        this.producerFlowControl = producerFlowControl;
612    }
613
614    /**
615     * @return true if topic is always retroactive
616     */
617    public boolean isAlwaysRetroactive() {
618        return alwaysRetroactive;
619    }
620
621    /**
622     * @param alwaysRetroactive
623     */
624    public void setAlwaysRetroactive(boolean alwaysRetroactive) {
625        this.alwaysRetroactive = alwaysRetroactive;
626    }
627
628
629    /**
630     * Set's the interval at which warnings about producers being blocked by
631     * resource usage will be triggered. Values of 0 or less will disable
632     * warnings
633     *
634     * @param blockedProducerWarningInterval the interval at which warning about
635     *            blocked producers will be triggered.
636     */
637    public void setBlockedProducerWarningInterval(long blockedProducerWarningInterval) {
638        this.blockedProducerWarningInterval = blockedProducerWarningInterval;
639    }
640
641    /**
642     *
643     * @return the interval at which warning about blocked producers will be
644     *         triggered.
645     */
646    public long getBlockedProducerWarningInterval() {
647        return blockedProducerWarningInterval;
648    }
649
650    /**
651     * @return the maxProducersToAudit
652     */
653    public int getMaxProducersToAudit() {
654        return maxProducersToAudit;
655    }
656
657    /**
658     * @param maxProducersToAudit the maxProducersToAudit to set
659     */
660    public void setMaxProducersToAudit(int maxProducersToAudit) {
661        this.maxProducersToAudit = maxProducersToAudit;
662    }
663
664    /**
665     * @return the maxAuditDepth
666     */
667    public int getMaxAuditDepth() {
668        return maxAuditDepth;
669    }
670
671    /**
672     * @param maxAuditDepth the maxAuditDepth to set
673     */
674    public void setMaxAuditDepth(int maxAuditDepth) {
675        this.maxAuditDepth = maxAuditDepth;
676    }
677
678    /**
679     * @return the enableAudit
680     */
681    public boolean isEnableAudit() {
682        return enableAudit;
683    }
684
685    /**
686     * @param enableAudit the enableAudit to set
687     */
688    public void setEnableAudit(boolean enableAudit) {
689        this.enableAudit = enableAudit;
690    }
691
692    public int getMaxQueueAuditDepth() {
693        return maxQueueAuditDepth;
694    }
695
696    public void setMaxQueueAuditDepth(int maxQueueAuditDepth) {
697        this.maxQueueAuditDepth = maxQueueAuditDepth;
698    }
699
700    public boolean isOptimizedDispatch() {
701        return optimizedDispatch;
702    }
703
704    public void setOptimizedDispatch(boolean optimizedDispatch) {
705        this.optimizedDispatch = optimizedDispatch;
706    }
707
708    public int getMaxPageSize() {
709        return maxPageSize;
710    }
711
712    public void setMaxPageSize(int maxPageSize) {
713        this.maxPageSize = maxPageSize;
714    }
715
716    public int getMaxBrowsePageSize() {
717        return maxBrowsePageSize;
718    }
719
720    public void setMaxBrowsePageSize(int maxPageSize) {
721        this.maxBrowsePageSize = maxPageSize;
722    }
723
724    public boolean isUseCache() {
725        return useCache;
726    }
727
728    public void setUseCache(boolean useCache) {
729        this.useCache = useCache;
730    }
731
732    public long getMinimumMessageSize() {
733        return minimumMessageSize;
734    }
735
736    public void setMinimumMessageSize(long minimumMessageSize) {
737        this.minimumMessageSize = minimumMessageSize;
738    }
739
740    public boolean isUseConsumerPriority() {
741        return useConsumerPriority;
742    }
743
744    public void setUseConsumerPriority(boolean useConsumerPriority) {
745        this.useConsumerPriority = useConsumerPriority;
746    }
747
748    public boolean isStrictOrderDispatch() {
749        return strictOrderDispatch;
750    }
751
752    public void setStrictOrderDispatch(boolean strictOrderDispatch) {
753        this.strictOrderDispatch = strictOrderDispatch;
754    }
755
756    public boolean isLazyDispatch() {
757        return lazyDispatch;
758    }
759
760    public void setLazyDispatch(boolean lazyDispatch) {
761        this.lazyDispatch = lazyDispatch;
762    }
763
764    public int getTimeBeforeDispatchStarts() {
765        return timeBeforeDispatchStarts;
766    }
767
768    public void setTimeBeforeDispatchStarts(int timeBeforeDispatchStarts) {
769        this.timeBeforeDispatchStarts = timeBeforeDispatchStarts;
770    }
771
772    public int getConsumersBeforeDispatchStarts() {
773        return consumersBeforeDispatchStarts;
774    }
775
776    public void setConsumersBeforeDispatchStarts(int consumersBeforeDispatchStarts) {
777        this.consumersBeforeDispatchStarts = consumersBeforeDispatchStarts;
778    }
779
780    /**
781     * @return the advisoryForSlowConsumers
782     */
783    public boolean isAdvisoryForSlowConsumers() {
784        return advisoryForSlowConsumers;
785    }
786
787    /**
788     * @param advisoryForSlowConsumers the advisoryForSlowConsumers to set
789     */
790    public void setAdvisoryForSlowConsumers(boolean advisoryForSlowConsumers) {
791        this.advisoryForSlowConsumers = advisoryForSlowConsumers;
792    }
793
794    /**
795     * @return the advisoryForDiscardingMessages
796     */
797    public boolean isAdvisoryForDiscardingMessages() {
798        return advisoryForDiscardingMessages;
799    }
800
801    /**
802     * @param advisoryForDiscardingMessages the advisoryForDiscardingMessages to set
803     */
804    public void setAdvisoryForDiscardingMessages(
805            boolean advisoryForDiscardingMessages) {
806        this.advisoryForDiscardingMessages = advisoryForDiscardingMessages;
807    }
808
809    /**
810     * @return the advisoryWhenFull
811     */
812    public boolean isAdvisoryWhenFull() {
813        return advisoryWhenFull;
814    }
815
816    /**
817     * @param advisoryWhenFull the advisoryWhenFull to set
818     */
819    public void setAdvisoryWhenFull(boolean advisoryWhenFull) {
820        this.advisoryWhenFull = advisoryWhenFull;
821    }
822
823    /**
824     * @return the advisoryForDelivery
825     */
826    public boolean isAdvisoryForDelivery() {
827        return advisoryForDelivery;
828    }
829
830    /**
831     * @param advisoryForDelivery the advisoryForDelivery to set
832     */
833    public void setAdvisoryForDelivery(boolean advisoryForDelivery) {
834        this.advisoryForDelivery = advisoryForDelivery;
835    }
836
837    /**
838     * @return the advisoryForConsumed
839     */
840    public boolean isAdvisoryForConsumed() {
841        return advisoryForConsumed;
842    }
843
844    /**
845     * @param advisoryForConsumed the advisoryForConsumed to set
846     */
847    public void setAdvisoryForConsumed(boolean advisoryForConsumed) {
848        this.advisoryForConsumed = advisoryForConsumed;
849    }
850
851    /**
852     * @return the advisdoryForFastProducers
853     */
854    public boolean isAdvisoryForFastProducers() {
855        return advisoryForFastProducers;
856    }
857
858    /**
859     * @param advisoryForFastProducers the advisdoryForFastProducers to set
860     */
861    public void setAdvisoryForFastProducers(boolean advisoryForFastProducers) {
862        this.advisoryForFastProducers = advisoryForFastProducers;
863    }
864
865    /**
866     * Returns true if the original message body should be included when applicable
867     * for advisory messages
868     *
869     * @return
870     */
871    public boolean isIncludeBodyForAdvisory() {
872        return includeBodyForAdvisory;
873    }
874
875    /**
876     * Sets if the original message body should be included when applicable
877     * for advisory messages
878     *
879     * @param includeBodyForAdvisory
880     */
881    public void setIncludeBodyForAdvisory(boolean includeBodyForAdvisory) {
882        this.includeBodyForAdvisory = includeBodyForAdvisory;
883    }
884
885    public void setMaxExpirePageSize(int maxExpirePageSize) {
886        this.maxExpirePageSize = maxExpirePageSize;
887    }
888
889    public int getMaxExpirePageSize() {
890        return maxExpirePageSize;
891    }
892
893    public void setExpireMessagesPeriod(long expireMessagesPeriod) {
894        this.expireMessagesPeriod = expireMessagesPeriod;
895    }
896
897    public long getExpireMessagesPeriod() {
898        return expireMessagesPeriod;
899    }
900
901    /**
902     * Get the queuePrefetch
903     * @return the queuePrefetch
904     */
905    public int getQueuePrefetch() {
906        return this.queuePrefetch;
907    }
908
909    /**
910     * Set the queuePrefetch
911     * @param queuePrefetch the queuePrefetch to set
912     */
913    public void setQueuePrefetch(int queuePrefetch) {
914        this.queuePrefetch = queuePrefetch;
915    }
916
917    /**
918     * Get the queueBrowserPrefetch
919     * @return the queueBrowserPrefetch
920     */
921    public int getQueueBrowserPrefetch() {
922        return this.queueBrowserPrefetch;
923    }
924
925    /**
926     * Set the queueBrowserPrefetch
927     * @param queueBrowserPrefetch the queueBrowserPrefetch to set
928     */
929    public void setQueueBrowserPrefetch(int queueBrowserPrefetch) {
930        this.queueBrowserPrefetch = queueBrowserPrefetch;
931    }
932
933    /**
934     * Get the topicPrefetch
935     * @return the topicPrefetch
936     */
937    public int getTopicPrefetch() {
938        return this.topicPrefetch;
939    }
940
941    /**
942     * Set the topicPrefetch
943     * @param topicPrefetch the topicPrefetch to set
944     */
945    public void setTopicPrefetch(int topicPrefetch) {
946        this.topicPrefetch = topicPrefetch;
947    }
948
949    /**
950     * Get the durableTopicPrefetch
951     * @return the durableTopicPrefetch
952     */
953    public int getDurableTopicPrefetch() {
954        return this.durableTopicPrefetch;
955    }
956
957    /**
958     * Set the durableTopicPrefetch
959     * @param durableTopicPrefetch the durableTopicPrefetch to set
960     */
961    public void setDurableTopicPrefetch(int durableTopicPrefetch) {
962        this.durableTopicPrefetch = durableTopicPrefetch;
963    }
964
965    public boolean isUsePrefetchExtension() {
966        return this.usePrefetchExtension;
967    }
968
969    public void setUsePrefetchExtension(boolean usePrefetchExtension) {
970        this.usePrefetchExtension = usePrefetchExtension;
971    }
972
973    public int getCursorMemoryHighWaterMark() {
974        return this.cursorMemoryHighWaterMark;
975    }
976
977    public void setCursorMemoryHighWaterMark(int cursorMemoryHighWaterMark) {
978        this.cursorMemoryHighWaterMark = cursorMemoryHighWaterMark;
979    }
980
981    public void setStoreUsageHighWaterMark(int storeUsageHighWaterMark) {
982        this.storeUsageHighWaterMark = storeUsageHighWaterMark;
983    }
984
985    public int getStoreUsageHighWaterMark() {
986        return storeUsageHighWaterMark;
987    }
988
989    public void setSlowConsumerStrategy(SlowConsumerStrategy slowConsumerStrategy) {
990        this.slowConsumerStrategy = slowConsumerStrategy;
991    }
992
993    public SlowConsumerStrategy getSlowConsumerStrategy() {
994        return this.slowConsumerStrategy;
995    }
996
997
998    public boolean isPrioritizedMessages() {
999        return this.prioritizedMessages;
1000    }
1001
1002    public void setPrioritizedMessages(boolean prioritizedMessages) {
1003        this.prioritizedMessages = prioritizedMessages;
1004    }
1005
1006    public void setAllConsumersExclusiveByDefault(boolean allConsumersExclusiveByDefault) {
1007        this.allConsumersExclusiveByDefault = allConsumersExclusiveByDefault;
1008    }
1009
1010    public boolean isAllConsumersExclusiveByDefault() {
1011        return allConsumersExclusiveByDefault;
1012    }
1013
1014    public boolean isGcInactiveDestinations() {
1015        return this.gcInactiveDestinations;
1016    }
1017
1018    public void setGcInactiveDestinations(boolean gcInactiveDestinations) {
1019        this.gcInactiveDestinations = gcInactiveDestinations;
1020    }
1021
1022    /**
1023     * @return the amount of time spent inactive before GC of the destination kicks in.
1024     *
1025     * @deprecated use getInactiveTimeoutBeforeGC instead.
1026     */
1027    @Deprecated
1028    public long getInactiveTimoutBeforeGC() {
1029        return getInactiveTimeoutBeforeGC();
1030    }
1031
1032    /**
1033     * Sets the amount of time a destination is inactive before it is marked for GC
1034     *
1035     * @param inactiveTimoutBeforeGC
1036     *        time in milliseconds to configure as the inactive timeout.
1037     *
1038     * @deprecated use getInactiveTimeoutBeforeGC instead.
1039     */
1040    @Deprecated
1041    public void setInactiveTimoutBeforeGC(long inactiveTimoutBeforeGC) {
1042        setInactiveTimeoutBeforeGC(inactiveTimoutBeforeGC);
1043    }
1044
1045    /**
1046     * @return the amount of time spent inactive before GC of the destination kicks in.
1047     */
1048    public long getInactiveTimeoutBeforeGC() {
1049        return this.inactiveTimeoutBeforeGC;
1050    }
1051
1052    /**
1053     * Sets the amount of time a destination is inactive before it is marked for GC
1054     *
1055     * @param inactiveTimeoutBeforeGC
1056     *        time in milliseconds to configure as the inactive timeout.
1057     */
1058    public void setInactiveTimeoutBeforeGC(long inactiveTimeoutBeforeGC) {
1059        this.inactiveTimeoutBeforeGC = inactiveTimeoutBeforeGC;
1060    }
1061
1062    public void setGcWithNetworkConsumers(boolean gcWithNetworkConsumers) {
1063        this.gcWithNetworkConsumers = gcWithNetworkConsumers;
1064    }
1065
1066    public boolean isGcWithNetworkConsumers() {
1067        return gcWithNetworkConsumers;
1068    }
1069
1070    public boolean isReduceMemoryFootprint() {
1071        return reduceMemoryFootprint;
1072    }
1073
1074    public void setReduceMemoryFootprint(boolean reduceMemoryFootprint) {
1075        this.reduceMemoryFootprint = reduceMemoryFootprint;
1076    }
1077
1078    public void setNetworkBridgeFilterFactory(NetworkBridgeFilterFactory networkBridgeFilterFactory) {
1079        this.networkBridgeFilterFactory = networkBridgeFilterFactory;
1080    }
1081
1082    public NetworkBridgeFilterFactory getNetworkBridgeFilterFactory() {
1083        return networkBridgeFilterFactory;
1084    }
1085
1086    public boolean isDoOptimzeMessageStorage() {
1087        return doOptimzeMessageStorage;
1088    }
1089
1090    public void setDoOptimzeMessageStorage(boolean doOptimzeMessageStorage) {
1091        this.doOptimzeMessageStorage = doOptimzeMessageStorage;
1092    }
1093
1094    public int getOptimizeMessageStoreInFlightLimit() {
1095        return optimizeMessageStoreInFlightLimit;
1096    }
1097
1098    public void setOptimizeMessageStoreInFlightLimit(int optimizeMessageStoreInFlightLimit) {
1099        this.optimizeMessageStoreInFlightLimit = optimizeMessageStoreInFlightLimit;
1100    }
1101
1102    public void setPersistJMSRedelivered(boolean val) {
1103        this.persistJMSRedelivered = val;
1104    }
1105
1106    public boolean isPersistJMSRedelivered() {
1107        return persistJMSRedelivered;
1108    }
1109
1110    public int getMaxDestinations() {
1111        return maxDestinations;
1112    }
1113
1114    /**
1115     * Sets the maximum number of destinations that can be created
1116     *
1117     * @param maxDestinations
1118     *            maximum number of destinations
1119     */
1120    public void setMaxDestinations(int maxDestinations) {
1121        this.maxDestinations = maxDestinations;
1122    }
1123
1124    @Override
1125    public String toString() {
1126        return "PolicyEntry [" + destination + "]";
1127    }
1128
1129    public void setSendFailIfNoSpace(boolean val) {
1130        if (val) {
1131            this.sendFailIfNoSpace = 1;
1132        } else {
1133            this.sendFailIfNoSpace = 0;
1134        }
1135    }
1136
1137    public boolean isSendFailIfNoSpace() {
1138        return sendFailIfNoSpace == 1;
1139    }
1140
1141    public void setSendFailIfNoSpaceAfterTimeout(long sendFailIfNoSpaceAfterTimeout) {
1142        this.sendFailIfNoSpaceAfterTimeout = sendFailIfNoSpaceAfterTimeout;
1143    }
1144
1145    public long getSendFailIfNoSpaceAfterTimeout() {
1146        return this.sendFailIfNoSpaceAfterTimeout;
1147    }
1148
1149    public boolean isUseTopicSubscriptionInflightStats() {
1150        return useTopicSubscriptionInflightStats;
1151    }
1152
1153    public void setUseTopicSubscriptionInflightStats(boolean useTopicSubscriptionInflightStats) {
1154        this.useTopicSubscriptionInflightStats = useTopicSubscriptionInflightStats;
1155    }
1156}