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;
018    
019    import java.net.URI;
020    import java.util.Collections;
021    import java.util.Map;
022    import java.util.Set;
023    import org.apache.activemq.broker.region.Destination;
024    import org.apache.activemq.broker.region.MessageReference;
025    import org.apache.activemq.broker.region.Subscription;
026    import org.apache.activemq.command.ActiveMQDestination;
027    import org.apache.activemq.command.BrokerId;
028    import org.apache.activemq.command.BrokerInfo;
029    import org.apache.activemq.command.ConnectionInfo;
030    import org.apache.activemq.command.ConsumerInfo;
031    import org.apache.activemq.command.DestinationInfo;
032    import org.apache.activemq.command.Message;
033    import org.apache.activemq.command.MessageAck;
034    import org.apache.activemq.command.MessageDispatch;
035    import org.apache.activemq.command.MessageDispatchNotification;
036    import org.apache.activemq.command.MessagePull;
037    import org.apache.activemq.command.ProducerInfo;
038    import org.apache.activemq.command.RemoveSubscriptionInfo;
039    import org.apache.activemq.command.Response;
040    import org.apache.activemq.command.SessionInfo;
041    import org.apache.activemq.command.TransactionId;
042    import org.apache.activemq.kaha.Store;
043    import org.apache.activemq.usage.Usage;
044    
045    /**
046     * Implementation of the broker where all it's methods throw an
047     * BrokerStoppedException.
048     * 
049     * @version $Revision$
050     */
051    public class ErrorBroker implements Broker {
052    
053        private final String message;
054    
055        public ErrorBroker(String message) {
056            this.message = message;
057        }
058    
059        @SuppressWarnings("unchecked")
060        public Map<ActiveMQDestination, Destination> getDestinationMap() {
061            return Collections.EMPTY_MAP;
062        }
063    
064        public Set getDestinations(ActiveMQDestination destination) {
065            return Collections.EMPTY_SET;
066        }
067    
068        public Broker getAdaptor(Class type) {
069            if (type.isInstance(this)) {
070                return this;
071            }
072            return null;
073        }
074    
075        public BrokerId getBrokerId() {
076            throw new BrokerStoppedException(this.message);
077        }
078    
079        public String getBrokerName() {
080            throw new BrokerStoppedException(this.message);
081        }
082    
083        public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {
084            throw new BrokerStoppedException(this.message);
085        }
086    
087        public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception {
088            throw new BrokerStoppedException(this.message);
089        }
090    
091        public void addSession(ConnectionContext context, SessionInfo info) throws Exception {
092            throw new BrokerStoppedException(this.message);
093        }
094    
095        public void removeSession(ConnectionContext context, SessionInfo info) throws Exception {
096            throw new BrokerStoppedException(this.message);
097        }
098    
099        public void addProducer(ConnectionContext context, ProducerInfo info) throws Exception {
100            throw new BrokerStoppedException(this.message);
101        }
102    
103        public void removeProducer(ConnectionContext context, ProducerInfo info) throws Exception {
104            throw new BrokerStoppedException(this.message);
105        }
106    
107        public Connection[] getClients() throws Exception {
108            throw new BrokerStoppedException(this.message);
109        }
110    
111        public ActiveMQDestination[] getDestinations() throws Exception {
112            throw new BrokerStoppedException(this.message);
113        }
114    
115        public TransactionId[] getPreparedTransactions(ConnectionContext context) throws Exception {
116            throw new BrokerStoppedException(this.message);
117        }
118    
119        public void beginTransaction(ConnectionContext context, TransactionId xid) throws Exception {
120            throw new BrokerStoppedException(this.message);
121        }
122    
123        public int prepareTransaction(ConnectionContext context, TransactionId xid) throws Exception {
124            throw new BrokerStoppedException(this.message);
125        }
126    
127        public void rollbackTransaction(ConnectionContext context, TransactionId xid) throws Exception {
128            throw new BrokerStoppedException(this.message);
129        }
130    
131        public void commitTransaction(ConnectionContext context, TransactionId xid, boolean onePhase) throws Exception {
132            throw new BrokerStoppedException(this.message);
133        }
134    
135        public void forgetTransaction(ConnectionContext context, TransactionId transactionId) throws Exception {
136            throw new BrokerStoppedException(this.message);
137        }
138    
139        public Destination addDestination(ConnectionContext context, ActiveMQDestination destination) throws Exception {
140            throw new BrokerStoppedException(this.message);
141        }
142    
143        public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception {
144            throw new BrokerStoppedException(this.message);
145        }
146    
147        public Subscription addConsumer(ConnectionContext context, ConsumerInfo info) throws Exception {
148            throw new BrokerStoppedException(this.message);
149        }
150    
151        public void removeConsumer(ConnectionContext context, ConsumerInfo info) throws Exception {
152            throw new BrokerStoppedException(this.message);
153        }
154    
155        public void removeSubscription(ConnectionContext context, RemoveSubscriptionInfo info) throws Exception {
156            throw new BrokerStoppedException(this.message);
157        }
158    
159        public void send(ProducerBrokerExchange producerExchange, Message message) throws Exception {
160            throw new BrokerStoppedException(this.message);
161        }
162    
163        public void acknowledge(ConsumerBrokerExchange consumerExchange, MessageAck ack) throws Exception {
164            throw new BrokerStoppedException(this.message);
165        }
166    
167        public void gc() {
168            throw new BrokerStoppedException(this.message);
169        }
170    
171        public void start() throws Exception {
172            throw new BrokerStoppedException(this.message);
173        }
174    
175        public void stop() throws Exception {
176            throw new BrokerStoppedException(this.message);
177        }
178    
179        public void addBroker(Connection connection, BrokerInfo info) {
180            throw new BrokerStoppedException(this.message);
181    
182        }
183    
184        public void removeBroker(Connection connection, BrokerInfo info) {
185            throw new BrokerStoppedException(this.message);
186        }
187    
188        public BrokerInfo[] getPeerBrokerInfos() {
189            throw new BrokerStoppedException(this.message);
190        }
191    
192        public void preProcessDispatch(MessageDispatch messageDispatch) {
193            throw new BrokerStoppedException(this.message);
194        }
195    
196        public void postProcessDispatch(MessageDispatch messageDispatch) {
197            throw new BrokerStoppedException(this.message);
198        }
199    
200        public void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception {
201            throw new BrokerStoppedException(this.message);
202        }
203    
204        public boolean isStopped() {
205            return true;
206        }
207    
208        public Set<ActiveMQDestination> getDurableDestinations() {
209            throw new BrokerStoppedException(this.message);
210        }
211    
212        public void addDestinationInfo(ConnectionContext context, DestinationInfo info) throws Exception {
213            throw new BrokerStoppedException(this.message);
214        }
215    
216        public void removeDestinationInfo(ConnectionContext context, DestinationInfo info) throws Exception {
217            throw new BrokerStoppedException(this.message);
218        }
219    
220        public boolean isFaultTolerantConfiguration() {
221            throw new BrokerStoppedException(this.message);
222        }
223    
224        public ConnectionContext getAdminConnectionContext() {
225            throw new BrokerStoppedException(this.message);
226        }
227    
228        public void setAdminConnectionContext(ConnectionContext adminConnectionContext) {
229            throw new BrokerStoppedException(this.message);
230        }
231    
232        public Response messagePull(ConnectionContext context, MessagePull pull) {
233            throw new BrokerStoppedException(this.message);
234        }
235    
236        public Store getTempDataStore() {
237            throw new BrokerStoppedException(this.message);
238        }
239    
240        public URI getVmConnectorURI() {
241            throw new BrokerStoppedException(this.message);
242        }
243    
244        public void brokerServiceStarted() {
245            throw new BrokerStoppedException(this.message);
246        }
247    
248        public BrokerService getBrokerService() {
249            throw new BrokerStoppedException(this.message);
250        }
251    
252        public boolean isExpired(MessageReference messageReference) {
253            throw new BrokerStoppedException(this.message);
254        }
255    
256        public void messageExpired(ConnectionContext context, MessageReference message) {
257            throw new BrokerStoppedException(this.message);
258        }
259    
260        public void sendToDeadLetterQueue(ConnectionContext context, MessageReference messageReference) {
261            throw new BrokerStoppedException(this.message);
262        }
263    
264        public Broker getRoot() {
265            throw new BrokerStoppedException(this.message);
266        }
267        
268        public long getBrokerSequenceId() {
269            throw new BrokerStoppedException(this.message);
270        }
271        
272        public void fastProducer(ConnectionContext context,ProducerInfo producerInfo) {
273            throw new BrokerStoppedException(this.message);
274        }
275    
276        public void isFull(ConnectionContext context,Destination destination, Usage usage) {
277            throw new BrokerStoppedException(this.message);
278        }
279    
280        public void messageConsumed(ConnectionContext context,MessageReference messageReference) {
281            throw new BrokerStoppedException(this.message);
282        }
283    
284        public void messageDelivered(ConnectionContext context,MessageReference messageReference) {
285            throw new BrokerStoppedException(this.message);
286        }
287    
288        public void messageDiscarded(ConnectionContext context,MessageReference messageReference) {
289            throw new BrokerStoppedException(this.message);
290        }
291    
292        public void slowConsumer(ConnectionContext context, Destination destination,Subscription subs) {
293            throw new BrokerStoppedException(this.message);
294        }
295        
296        public void nowMasterBroker() {   
297            throw new BrokerStoppedException(this.message);
298        }
299    }