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