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 */
017 package org.apache.activemq.broker.region.policy;
018
019 import org.apache.activemq.broker.Broker;
020 import org.apache.activemq.broker.region.DurableTopicSubscription;
021 import org.apache.activemq.broker.region.cursors.PendingMessageCursor;
022 import org.apache.activemq.broker.region.cursors.StoreDurableSubscriberCursor;
023
024 /**
025 * Creates a PendingMessageCursor that access the persistent store to retrieve
026 * messages
027 *
028 * @org.apache.xbean.XBean element="storeDurableSubscriberCursor"
029 * description="Pending messages for a durable
030 * subscriber are referenced from the Store"
031 *
032 */
033 public class StorePendingDurableSubscriberMessageStoragePolicy implements PendingDurableSubscriberMessageStoragePolicy {
034 boolean immediatePriorityDispatch = true;
035 boolean useCache = true;
036
037 public boolean isImmediatePriorityDispatch() {
038 return immediatePriorityDispatch;
039 }
040
041 /**
042 * Ensure that new higher priority messages will get an immediate dispatch
043 * rather than wait for the end of the current cursor batch.
044 * Useful when there is a large message backlog and intermittent high priority messages.
045 *
046 * @param immediatePriorityDispatch
047 */
048 public void setImmediatePriorityDispatch(boolean immediatePriorityDispatch) {
049 this.immediatePriorityDispatch = immediatePriorityDispatch;
050 }
051
052 public boolean isUseCache() {
053 return useCache;
054 }
055
056 public void setUseCache(boolean useCache) {
057 this.useCache = useCache;
058 }
059
060 /**
061 * Retrieve the configured pending message storage cursor;
062 * @param broker
063 *
064 * @param clientId
065 * @param name
066 * @param maxBatchSize
067 * @param sub
068 * @return the Pending Message cursor
069 */
070 public PendingMessageCursor getSubscriberPendingMessageCursor(Broker broker,String clientId, String name, int maxBatchSize, DurableTopicSubscription sub) {
071 StoreDurableSubscriberCursor cursor = new StoreDurableSubscriberCursor(broker,clientId, name, maxBatchSize, sub);
072 cursor.setUseCache(isUseCache());
073 cursor.setImmediatePriorityDispatch(isImmediatePriorityDispatch());
074 return cursor;
075 }
076 }