001 /**
002 *
003 * Copyright 2004 Protique Ltd
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * 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 *
017 **/
018
019 package org.activemq;
020
021 import org.apache.commons.logging.Log;
022 import org.apache.commons.logging.LogFactory;
023
024
025 /**
026 * Defines the pretech message policies for different types of consumers
027 * @version $Revision: 1.1.1.1 $
028 */
029 public class ActiveMQPrefetchPolicy {
030 private static final Log log = LogFactory.getLog(ActiveMQPrefetchPolicy.class);
031 private static final int MAX_PREFETCH_SIZE = (Short.MAX_VALUE -1);
032 private int queuePrefetch;
033 private int queueBrowserPrefetch;
034 private int topicPrefetch;
035 private int durableTopicPrefetch;
036
037
038 /**
039 * Initialize default prefetch policies
040 */
041 public ActiveMQPrefetchPolicy() {
042 this.queuePrefetch = 1000;
043 this.queueBrowserPrefetch = 500;
044 this.topicPrefetch = 1000;
045 this.durableTopicPrefetch = 100;
046 }
047
048 /**
049 * @return Returns the durableTopicPrefetch.
050 */
051 public int getDurableTopicPrefetch() {
052 return durableTopicPrefetch;
053 }
054
055 /**
056 * @param durableTopicPrefetch The durableTopicPrefetch to set.
057 */
058 public void setDurableTopicPrefetch(int durableTopicPrefetch) {
059 this.durableTopicPrefetch = getMaxPrefetchLimit(durableTopicPrefetch);
060 }
061
062 /**
063 * @return Returns the queuePrefetch.
064 */
065 public int getQueuePrefetch() {
066 return queuePrefetch;
067 }
068
069 /**
070 * @param queuePrefetch The queuePrefetch to set.
071 */
072 public void setQueuePrefetch(int queuePrefetch) {
073 this.queuePrefetch = getMaxPrefetchLimit(queuePrefetch);
074 }
075
076 /**
077 * @return Returns the queueBrowserPrefetch.
078 */
079 public int getQueueBrowserPrefetch() {
080 return queueBrowserPrefetch;
081 }
082
083 /**
084 * @param queueBrowserPrefetch The queueBrowserPrefetch to set.
085 */
086 public void setQueueBrowserPrefetch(int queueBrowserPrefetch) {
087 this.queueBrowserPrefetch = getMaxPrefetchLimit(queueBrowserPrefetch);
088 }
089
090 /**
091 * @return Returns the topicPrefetch.
092 */
093 public int getTopicPrefetch() {
094 return topicPrefetch;
095 }
096
097 /**
098 * @param topicPrefetch The topicPrefetch to set.
099 */
100 public void setTopicPrefetch(int topicPrefetch) {
101 this.topicPrefetch = getMaxPrefetchLimit(topicPrefetch);
102 }
103
104 private int getMaxPrefetchLimit(int value) {
105 int result = Math.min(value, MAX_PREFETCH_SIZE);
106 if (result < value) {
107 log.warn("maximum prefetch limit has been reset from " + value + " to " + MAX_PREFETCH_SIZE);
108 }
109 return result;
110 }
111 }