KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > ActiveMQPrefetchPolicy


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq;
19
20 import java.io.Serializable JavaDoc;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24
25 /**
26  * Defines the prefetch message policies for different types of consumers
27  *
28  * @org.apache.xbean.XBean element="prefetchPolicy"
29  *
30  * @version $Revision: 1.3 $
31  */

32 public class ActiveMQPrefetchPolicy implements Serializable JavaDoc {
33     private static final Log log = LogFactory.getLog(ActiveMQPrefetchPolicy.class);
34     private static final int MAX_PREFETCH_SIZE = (Short.MAX_VALUE -1);
35     private int queuePrefetch;
36     private int queueBrowserPrefetch;
37     private int topicPrefetch;
38     private int durableTopicPrefetch;
39     private int optimizeDurableTopicPrefetch;
40     private int inputStreamPrefetch;
41     private int maximumPendingMessageLimit;
42
43     /**
44      * Initialize default prefetch policies
45      */

46     public ActiveMQPrefetchPolicy() {
47         this.queuePrefetch = 1000;
48         this.queueBrowserPrefetch = 500;
49         this.topicPrefetch = MAX_PREFETCH_SIZE;
50         this.durableTopicPrefetch = 100;
51         this.optimizeDurableTopicPrefetch=1000;
52         this.inputStreamPrefetch = 100;
53     }
54
55     /**
56      * @return Returns the durableTopicPrefetch.
57      */

58     public int getDurableTopicPrefetch() {
59         return durableTopicPrefetch;
60     }
61
62     /**
63      * @param durableTopicPrefetch The durableTopicPrefetch to set.
64      */

65     public void setDurableTopicPrefetch(int durableTopicPrefetch) {
66         this.durableTopicPrefetch = getMaxPrefetchLimit(durableTopicPrefetch);
67     }
68
69     /**
70      * @return Returns the queuePrefetch.
71      */

72     public int getQueuePrefetch() {
73         return queuePrefetch;
74     }
75
76     /**
77      * @param queuePrefetch The queuePrefetch to set.
78      */

79     public void setQueuePrefetch(int queuePrefetch) {
80         this.queuePrefetch = getMaxPrefetchLimit(queuePrefetch);
81     }
82
83     /**
84      * @return Returns the queueBrowserPrefetch.
85      */

86     public int getQueueBrowserPrefetch() {
87         return queueBrowserPrefetch;
88     }
89
90     /**
91      * @param queueBrowserPrefetch The queueBrowserPrefetch to set.
92      */

93     public void setQueueBrowserPrefetch(int queueBrowserPrefetch) {
94         this.queueBrowserPrefetch = getMaxPrefetchLimit(queueBrowserPrefetch);
95     }
96
97     /**
98      * @return Returns the topicPrefetch.
99      */

100     public int getTopicPrefetch() {
101         return topicPrefetch;
102     }
103
104     /**
105      * @param topicPrefetch The topicPrefetch to set.
106      */

107     public void setTopicPrefetch(int topicPrefetch) {
108         this.topicPrefetch = getMaxPrefetchLimit(topicPrefetch);
109     }
110     
111     /**
112      * @return Returns the optimizeDurableTopicPrefetch.
113      */

114     public int getOptimizeDurableTopicPrefetch(){
115         return optimizeDurableTopicPrefetch;
116     }
117
118     /**
119      * @param optimizeAcknowledgePrefetch The optimizeDurableTopicPrefetch to set.
120      */

121     public void setOptimizeDurableTopicPrefetch(int optimizeAcknowledgePrefetch){
122         this.optimizeDurableTopicPrefetch=optimizeAcknowledgePrefetch;
123     }
124     
125     public int getMaximumPendingMessageLimit() {
126         return maximumPendingMessageLimit;
127     }
128
129     /**
130      * Sets how many messages a broker will keep around, above the prefetch limit, for non-durable
131      * topics before starting to discard older messages.
132      */

133     public void setMaximumPendingMessageLimit(int maximumPendingMessageLimit) {
134         this.maximumPendingMessageLimit = maximumPendingMessageLimit;
135     }
136
137     
138     private int getMaxPrefetchLimit(int value) {
139         int result = Math.min(value, MAX_PREFETCH_SIZE);
140         if (result < value) {
141             log.warn("maximum prefetch limit has been reset from " + value + " to " + MAX_PREFETCH_SIZE);
142         }
143         return result;
144     }
145
146     public void setAll(int i) {
147         this.durableTopicPrefetch=i;
148         this.queueBrowserPrefetch=i;
149         this.queuePrefetch=i;
150         this.topicPrefetch=i;
151         this.inputStreamPrefetch=1;
152         this.optimizeDurableTopicPrefetch=i;
153     }
154
155     public int getInputStreamPrefetch() {
156         return inputStreamPrefetch;
157     }
158
159     public void setInputStreamPrefetch(int inputStreamPrefetch) {
160         this.inputStreamPrefetch = getMaxPrefetchLimit(inputStreamPrefetch);
161     }
162
163     
164 }
165
Popular Tags