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 {
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        void gc();
058    
059        ActiveMQDestination getActiveMQDestination();
060    
061        MemoryUsage getMemoryUsage();
062    
063        void dispose(ConnectionContext context) throws IOException;
064    
065        DestinationStatistics getDestinationStatistics();
066    
067        DeadLetterStrategy getDeadLetterStrategy();
068    
069        Message[] browse();
070    
071        String getName();
072    
073        MessageStore getMessageStore();
074    
075        boolean isProducerFlowControl();
076    
077        void setProducerFlowControl(boolean value);
078    
079        /**
080         * Set's the interval at which warnings about producers being blocked by
081         * resource usage will be triggered. Values of 0 or less will disable
082         * warnings
083         * 
084         * @param blockedProducerWarningInterval the interval at which warning about
085         *            blocked producers will be triggered.
086         */
087        public void setBlockedProducerWarningInterval(long blockedProducerWarningInterval);
088    
089        /**
090         * 
091         * @return the interval at which warning about blocked producers will be
092         *         triggered.
093         */
094        public long getBlockedProducerWarningInterval();
095    
096        int getMaxProducersToAudit();
097    
098        void setMaxProducersToAudit(int maxProducersToAudit);
099    
100        int getMaxAuditDepth();
101    
102        void setMaxAuditDepth(int maxAuditDepth);
103    
104        boolean isEnableAudit();
105    
106        void setEnableAudit(boolean enableAudit);
107    
108        boolean isActive();
109    
110        int getMaxPageSize();
111    
112        public void setMaxPageSize(int maxPageSize);
113    
114        public int getMaxBrowsePageSize();
115    
116        public void setMaxBrowsePageSize(int maxPageSize);
117    
118        public boolean isUseCache();
119    
120        public void setUseCache(boolean useCache);
121    
122        public int getMinimumMessageSize();
123    
124        public void setMinimumMessageSize(int minimumMessageSize);
125    
126        public int getCursorMemoryHighWaterMark();
127    
128        public void setCursorMemoryHighWaterMark(int cursorMemoryHighWaterMark);
129    
130        /**
131         * optionally called by a Subscriber - to inform the Destination its ready
132         * for more messages
133         */
134        public void wakeup();
135    
136        /**
137         * @return true if lazyDispatch is enabled
138         */
139        public boolean isLazyDispatch();
140    
141        /**
142         * set the lazy dispatch - default is false
143         * 
144         * @param value
145         */
146        public void setLazyDispatch(boolean value);
147    
148        /**
149         * Inform the Destination a message has expired
150         * 
151         * @param context
152         * @param subs
153         * @param node
154         */
155        void messageExpired(ConnectionContext context, Subscription subs, MessageReference node);
156    
157        /**
158         * called when message is consumed
159         * 
160         * @param context
161         * @param messageReference
162         */
163        void messageConsumed(ConnectionContext context, MessageReference messageReference);
164    
165        /**
166         * Called when message is delivered to the broker
167         * 
168         * @param context
169         * @param messageReference
170         */
171        void messageDelivered(ConnectionContext context, MessageReference messageReference);
172    
173        /**
174         * Called when a message is discarded - e.g. running low on memory This will
175         * happen only if the policy is enabled - e.g. non durable topics
176         * 
177         * @param context
178         * @param messageReference
179         * @param sub 
180         */
181        void messageDiscarded(ConnectionContext context, Subscription sub, MessageReference messageReference);
182    
183        /**
184         * Called when there is a slow consumer
185         * 
186         * @param context
187         * @param subs
188         */
189        void slowConsumer(ConnectionContext context, Subscription subs);
190    
191        /**
192         * Called to notify a producer is too fast
193         * 
194         * @param context
195         * @param producerInfo
196         */
197        void fastProducer(ConnectionContext context, ProducerInfo producerInfo);
198    
199        /**
200         * Called when a Usage reaches a limit
201         * 
202         * @param context
203         * @param usage
204         */
205        void isFull(ConnectionContext context, Usage usage);
206    
207        List<Subscription> getConsumers();
208    
209        /**
210         * called on Queues in slave mode to allow dispatch to follow subscription
211         * choice of master
212         * 
213         * @param messageDispatchNotification
214         * @throws Exception
215         */
216        void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception;
217        
218        boolean isPrioritizedMessages();
219    
220        SlowConsumerStrategy getSlowConsumerStrategy();
221    }