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