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.util.Map;
020    import java.util.Set;
021    
022    import org.apache.activemq.Service;
023    import org.apache.activemq.broker.ConnectionContext;
024    import org.apache.activemq.broker.ConsumerBrokerExchange;
025    import org.apache.activemq.broker.ProducerBrokerExchange;
026    import org.apache.activemq.command.ActiveMQDestination;
027    import org.apache.activemq.command.ConsumerInfo;
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.MessagePull;
032    import org.apache.activemq.command.ProducerInfo;
033    import org.apache.activemq.command.RemoveSubscriptionInfo;
034    import org.apache.activemq.command.Response;
035    
036    /**
037     * A Region is used to implement the different QOS options available to 
038     * a broker.  A Broker is composed of multiple message processing Regions that
039     * provide different QOS options.
040     * 
041     * @version $Revision$
042     */
043    public interface Region extends Service {
044    
045        /**
046         * Used to create a destination.  Usually, this method is invoked as a side-effect of sending
047         * a message to a destination that does not exist yet.
048         * 
049         * @param context
050         * @param destination the destination to create.
051         * @return TODO
052         * @throws Exception TODO
053         */
054        Destination addDestination(ConnectionContext context, ActiveMQDestination destination) throws Exception;
055        
056        /**
057         * Used to destroy a destination.  
058         * This should try to quiesce use of the destination up to the timeout allotted time before removing the destination.
059         * This will remove all persistent messages associated with the destination.
060         * 
061         * @param context the environment the operation is being executed under.
062         * @param destination what is being removed from the broker.
063         * @param timeout the max amount of time to wait for the destination to quiesce
064         * @throws Exception TODO
065         */
066        void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception;
067    
068        /**
069         * Returns a copy of the current destinations available in the region
070         * 
071         * @return a copy of the regions currently active at the time of the call with the key the destination and the value the Destination.
072         */
073        Map<ActiveMQDestination, Destination> getDestinationMap();
074        
075    
076        /**
077         * Adds a consumer.
078         * @param context the environment the operation is being executed under.
079         * @return TODO
080         * @throws Exception TODO
081         */
082        Subscription addConsumer(ConnectionContext context, ConsumerInfo info) throws Exception;
083    
084        /**
085         * Removes a consumer.
086         * @param context the environment the operation is being executed under.
087         * @throws Exception TODO
088         */
089        void removeConsumer(ConnectionContext context, ConsumerInfo info) throws Exception;
090        
091        /**
092         * Adds a Producer.
093         * @param context the environment the operation is being executed under.
094         * @throws Exception TODO
095         */
096        void addProducer(ConnectionContext context, ProducerInfo info) throws Exception;
097    
098        /**
099         * Removes a Producer.
100         * @param context the environment the operation is being executed under.
101         * @throws Exception TODO
102         */
103        void removeProducer(ConnectionContext context, ProducerInfo info) throws Exception;
104    
105    
106        /**
107         * Deletes a durable subscription.
108         * @param context the environment the operation is being executed under.
109         * @param info TODO
110         * @throws Exception TODO
111         */
112        void removeSubscription(ConnectionContext context, RemoveSubscriptionInfo info) throws Exception;
113        
114        /**
115         * Send a message to the broker to using the specified destination.  The destination specified
116         * in the message does not need to match the destination the message is sent to.  This is 
117         * handy in case the message is being sent to a dead letter destination.
118         * @param producerExchange the environment the operation is being executed under.
119         * @param message 
120         * @throws Exception TODO
121         */
122        void send(ProducerBrokerExchange producerExchange, Message message) throws Exception;
123        
124        /**
125         * Used to acknowledge the receipt of a message by a client.
126         * @param consumerExchange the environment the operation is being executed under.
127         * @throws Exception TODO
128         */
129        void acknowledge(ConsumerBrokerExchange consumerExchange, MessageAck ack) throws Exception;
130        
131        /**
132         * Allows a consumer to pull a message from a queue
133         */
134        Response messagePull(ConnectionContext context, MessagePull pull) throws Exception;
135    
136        /**
137         * Process a notification of a dispatch - used by a Slave Broker
138         * @param messageDispatchNotification
139         * @throws Exception TODO
140         */
141        void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception;
142    
143        void gc();
144    
145        /**
146         * Provide an exact or wildcard lookup of destinations in the region
147         * 
148         * @return a set of matching destination objects.
149         */
150        Set <Destination>getDestinations(ActiveMQDestination destination);
151        
152    }