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;
018    
019    import java.io.IOException;
020    import java.util.List;
021    import org.apache.activemq.Service;
022    import org.apache.activemq.broker.ConnectionContext;
023    import org.apache.activemq.broker.ProducerBrokerExchange;
024    import org.apache.activemq.broker.region.policy.DeadLetterStrategy;
025    import org.apache.activemq.broker.region.policy.SharedDeadLetterStrategy;
026    import org.apache.activemq.broker.region.policy.SlowConsumerStrategy;
027    import org.apache.activemq.command.ActiveMQDestination;
028    import org.apache.activemq.command.Message;
029    import org.apache.activemq.command.MessageAck;
030    import org.apache.activemq.command.MessageDispatchNotification;
031    import org.apache.activemq.command.ProducerInfo;
032    import org.apache.activemq.store.MessageStore;
033    import org.apache.activemq.thread.Task;
034    import org.apache.activemq.usage.MemoryUsage;
035    import org.apache.activemq.usage.Usage;
036    
037    /**
038     *
039     */
040    public interface Destination extends Service, Task, Message.MessageDestination {
041    
042        public static final DeadLetterStrategy DEFAULT_DEAD_LETTER_STRATEGY = new SharedDeadLetterStrategy();
043        public static final long DEFAULT_BLOCKED_PRODUCER_WARNING_INTERVAL = 30000;
044    
045        void addSubscription(ConnectionContext context, Subscription sub) throws Exception;
046    
047        void removeSubscription(ConnectionContext context, Subscription sub, long lastDeliveredSequenceId) throws Exception;
048    
049        void addProducer(ConnectionContext context, ProducerInfo info) throws Exception;
050    
051        void removeProducer(ConnectionContext context, ProducerInfo info) throws Exception;
052    
053        void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception;
054    
055        void acknowledge(ConnectionContext context, Subscription sub, final MessageAck ack, final MessageReference node) throws IOException;
056    
057        long getInactiveTimoutBeforeGC();
058    
059        void markForGC(long timeStamp);
060    
061        boolean canGC();
062    
063        void gc();
064    
065        ActiveMQDestination getActiveMQDestination();
066    
067        MemoryUsage getMemoryUsage();
068    
069        void setMemoryUsage(MemoryUsage memoryUsage);
070    
071        void dispose(ConnectionContext context) throws IOException;
072    
073        boolean isDisposed();
074    
075        DestinationStatistics getDestinationStatistics();
076    
077        DeadLetterStrategy getDeadLetterStrategy();
078    
079        Message[] browse();
080    
081        String getName();
082    
083        MessageStore getMessageStore();
084    
085        boolean isProducerFlowControl();
086    
087        void setProducerFlowControl(boolean value);
088    
089        boolean isAlwaysRetroactive();
090    
091        void setAlwaysRetroactive(boolean value);
092    
093        /**
094         * Set's the interval at which warnings about producers being blocked by
095         * resource usage will be triggered. Values of 0 or less will disable
096         * warnings
097         *
098         * @param blockedProducerWarningInterval the interval at which warning about
099         *            blocked producers will be triggered.
100         */
101        public void setBlockedProducerWarningInterval(long blockedProducerWarningInterval);
102    
103        /**
104         *
105         * @return the interval at which warning about blocked producers will be
106         *         triggered.
107         */
108        public long getBlockedProducerWarningInterval();
109    
110        int getMaxProducersToAudit();
111    
112        void setMaxProducersToAudit(int maxProducersToAudit);
113    
114        int getMaxAuditDepth();
115    
116        void setMaxAuditDepth(int maxAuditDepth);
117    
118        boolean isEnableAudit();
119    
120        void setEnableAudit(boolean enableAudit);
121    
122        boolean isActive();
123    
124        int getMaxPageSize();
125    
126        public void setMaxPageSize(int maxPageSize);
127    
128        public int getMaxBrowsePageSize();
129    
130        public void setMaxBrowsePageSize(int maxPageSize);
131    
132        public boolean isUseCache();
133    
134        public void setUseCache(boolean useCache);
135    
136        public int getMinimumMessageSize();
137    
138        public void setMinimumMessageSize(int minimumMessageSize);
139    
140        public int getCursorMemoryHighWaterMark();
141    
142        public void setCursorMemoryHighWaterMark(int cursorMemoryHighWaterMark);
143    
144        /**
145         * optionally called by a Subscriber - to inform the Destination its ready
146         * for more messages
147         */
148        public void wakeup();
149    
150        /**
151         * @return true if lazyDispatch is enabled
152         */
153        public boolean isLazyDispatch();
154    
155        /**
156         * set the lazy dispatch - default is false
157         *
158         * @param value
159         */
160        public void setLazyDispatch(boolean value);
161    
162        /**
163         * Inform the Destination a message has expired
164         *
165         * @param context
166         * @param subs
167         * @param node
168         */
169        void messageExpired(ConnectionContext context, Subscription subs, MessageReference node);
170    
171        /**
172         * called when message is consumed
173         *
174         * @param context
175         * @param messageReference
176         */
177        void messageConsumed(ConnectionContext context, MessageReference messageReference);
178    
179        /**
180         * Called when message is delivered to the broker
181         *
182         * @param context
183         * @param messageReference
184         */
185        void messageDelivered(ConnectionContext context, MessageReference messageReference);
186    
187        /**
188         * Called when a message is discarded - e.g. running low on memory This will
189         * happen only if the policy is enabled - e.g. non durable topics
190         *
191         * @param context
192         * @param messageReference
193         * @param sub
194         */
195        void messageDiscarded(ConnectionContext context, Subscription sub, MessageReference messageReference);
196    
197        /**
198         * Called when there is a slow consumer
199         *
200         * @param context
201         * @param subs
202         */
203        void slowConsumer(ConnectionContext context, Subscription subs);
204    
205        /**
206         * Called to notify a producer is too fast
207         *
208         * @param context
209         * @param producerInfo
210         */
211        void fastProducer(ConnectionContext context, ProducerInfo producerInfo);
212    
213        /**
214         * Called when a Usage reaches a limit
215         *
216         * @param context
217         * @param usage
218         */
219        void isFull(ConnectionContext context, Usage<?> usage);
220    
221        List<Subscription> getConsumers();
222    
223        /**
224         * called on Queues in slave mode to allow dispatch to follow subscription
225         * choice of master
226         *
227         * @param messageDispatchNotification
228         * @throws Exception
229         */
230        void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception;
231    
232        boolean isPrioritizedMessages();
233    
234        SlowConsumerStrategy getSlowConsumerStrategy();
235    
236        boolean isDoOptimzeMessageStorage();
237        void setDoOptimzeMessageStorage(boolean doOptimzeMessageStorage);
238    
239        public void clearPendingMessages();
240    }