Source code: org/activemq/ActiveMQPrefetchPolicy.java
1 /**
2 *
3 * Copyright 2004 Protique Ltd
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 **/
18
19 package org.activemq;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24
25 /**
26 * Defines the pretech message policies for different types of consumers
27 * @version $Revision: 1.1.1.1 $
28 */
29 public class ActiveMQPrefetchPolicy {
30 private static final Log log = LogFactory.getLog(ActiveMQPrefetchPolicy.class);
31 private static final int MAX_PREFETCH_SIZE = (Short.MAX_VALUE -1);
32 private int queuePrefetch;
33 private int queueBrowserPrefetch;
34 private int topicPrefetch;
35 private int durableTopicPrefetch;
36
37
38 /**
39 * Initialize default prefetch policies
40 */
41 public ActiveMQPrefetchPolicy() {
42 this.queuePrefetch = 1000;
43 this.queueBrowserPrefetch = 500;
44 this.topicPrefetch = 1000;
45 this.durableTopicPrefetch = 100;
46 }
47
48 /**
49 * @return Returns the durableTopicPrefetch.
50 */
51 public int getDurableTopicPrefetch() {
52 return durableTopicPrefetch;
53 }
54
55 /**
56 * @param durableTopicPrefetch The durableTopicPrefetch to set.
57 */
58 public void setDurableTopicPrefetch(int durableTopicPrefetch) {
59 this.durableTopicPrefetch = getMaxPrefetchLimit(durableTopicPrefetch);
60 }
61
62 /**
63 * @return Returns the queuePrefetch.
64 */
65 public int getQueuePrefetch() {
66 return queuePrefetch;
67 }
68
69 /**
70 * @param queuePrefetch The queuePrefetch to set.
71 */
72 public void setQueuePrefetch(int queuePrefetch) {
73 this.queuePrefetch = getMaxPrefetchLimit(queuePrefetch);
74 }
75
76 /**
77 * @return Returns the queueBrowserPrefetch.
78 */
79 public int getQueueBrowserPrefetch() {
80 return queueBrowserPrefetch;
81 }
82
83 /**
84 * @param queueBrowserPrefetch The queueBrowserPrefetch to set.
85 */
86 public void setQueueBrowserPrefetch(int queueBrowserPrefetch) {
87 this.queueBrowserPrefetch = getMaxPrefetchLimit(queueBrowserPrefetch);
88 }
89
90 /**
91 * @return Returns the topicPrefetch.
92 */
93 public int getTopicPrefetch() {
94 return topicPrefetch;
95 }
96
97 /**
98 * @param topicPrefetch The topicPrefetch to set.
99 */
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 }