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;
018
019import java.net.URI;
020import java.util.Collections;
021import java.util.Map;
022import java.util.Set;
023import java.util.concurrent.ThreadPoolExecutor;
024
025import org.apache.activemq.broker.region.Destination;
026import org.apache.activemq.broker.region.MessageReference;
027import org.apache.activemq.broker.region.Subscription;
028import org.apache.activemq.command.ActiveMQDestination;
029import org.apache.activemq.command.BrokerId;
030import org.apache.activemq.command.BrokerInfo;
031import org.apache.activemq.command.ConnectionInfo;
032import org.apache.activemq.command.ConsumerControl;
033import org.apache.activemq.command.ConsumerInfo;
034import org.apache.activemq.command.DestinationInfo;
035import org.apache.activemq.command.Message;
036import org.apache.activemq.command.MessageAck;
037import org.apache.activemq.command.MessageDispatch;
038import org.apache.activemq.command.MessageDispatchNotification;
039import org.apache.activemq.command.MessagePull;
040import org.apache.activemq.command.ProducerInfo;
041import org.apache.activemq.command.RemoveSubscriptionInfo;
042import org.apache.activemq.command.Response;
043import org.apache.activemq.command.SessionInfo;
044import org.apache.activemq.command.TransactionId;
045import org.apache.activemq.store.PListStore;
046import org.apache.activemq.thread.Scheduler;
047import org.apache.activemq.usage.Usage;
048
049/**
050 * Implementation of the broker where all it's methods throw an
051 * BrokerStoppedException.
052 *
053 *
054 */
055public class ErrorBroker implements Broker {
056
057    private final String message;
058
059    public ErrorBroker(String message) {
060        this.message = message;
061    }
062
063    @Override
064    @SuppressWarnings("unchecked")
065    public Map<ActiveMQDestination, Destination> getDestinationMap() {
066        return Collections.EMPTY_MAP;
067    }
068
069    @Override
070    public Map<ActiveMQDestination, Destination> getDestinationMap(ActiveMQDestination destination) {
071        return Collections.EMPTY_MAP;
072    }
073
074    @Override
075    public Set getDestinations(ActiveMQDestination destination) {
076        return Collections.EMPTY_SET;
077    }
078
079    @Override
080    public Broker getAdaptor(Class type) {
081        if (type.isInstance(this)) {
082            return this;
083        }
084        return null;
085    }
086
087    @Override
088    public BrokerId getBrokerId() {
089        throw new BrokerStoppedException(this.message);
090    }
091
092    @Override
093    public String getBrokerName() {
094        throw new BrokerStoppedException(this.message);
095    }
096
097    @Override
098    public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {
099        throw new BrokerStoppedException(this.message);
100    }
101
102    @Override
103    public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception {
104        throw new BrokerStoppedException(this.message);
105    }
106
107    @Override
108    public void addSession(ConnectionContext context, SessionInfo info) throws Exception {
109        throw new BrokerStoppedException(this.message);
110    }
111
112    @Override
113    public void removeSession(ConnectionContext context, SessionInfo info) throws Exception {
114        throw new BrokerStoppedException(this.message);
115    }
116
117    @Override
118    public void addProducer(ConnectionContext context, ProducerInfo info) throws Exception {
119        throw new BrokerStoppedException(this.message);
120    }
121
122    @Override
123    public void removeProducer(ConnectionContext context, ProducerInfo info) throws Exception {
124        throw new BrokerStoppedException(this.message);
125    }
126
127    @Override
128    public Connection[] getClients() throws Exception {
129        throw new BrokerStoppedException(this.message);
130    }
131
132    @Override
133    public ActiveMQDestination[] getDestinations() throws Exception {
134        throw new BrokerStoppedException(this.message);
135    }
136
137    @Override
138    public TransactionId[] getPreparedTransactions(ConnectionContext context) throws Exception {
139        throw new BrokerStoppedException(this.message);
140    }
141
142    @Override
143    public void beginTransaction(ConnectionContext context, TransactionId xid) throws Exception {
144        throw new BrokerStoppedException(this.message);
145    }
146
147    @Override
148    public int prepareTransaction(ConnectionContext context, TransactionId xid) throws Exception {
149        throw new BrokerStoppedException(this.message);
150    }
151
152    @Override
153    public void rollbackTransaction(ConnectionContext context, TransactionId xid) throws Exception {
154        throw new BrokerStoppedException(this.message);
155    }
156
157    @Override
158    public void commitTransaction(ConnectionContext context, TransactionId xid, boolean onePhase) throws Exception {
159        throw new BrokerStoppedException(this.message);
160    }
161
162    @Override
163    public void forgetTransaction(ConnectionContext context, TransactionId transactionId) throws Exception {
164        throw new BrokerStoppedException(this.message);
165    }
166
167    @Override
168    public Destination addDestination(ConnectionContext context, ActiveMQDestination destination,boolean flag) throws Exception {
169        throw new BrokerStoppedException(this.message);
170    }
171
172    @Override
173    public void removeDestination(ConnectionContext context, ActiveMQDestination destination, long timeout) throws Exception {
174        throw new BrokerStoppedException(this.message);
175    }
176
177    @Override
178    public Subscription addConsumer(ConnectionContext context, ConsumerInfo info) throws Exception {
179        throw new BrokerStoppedException(this.message);
180    }
181
182    @Override
183    public void removeConsumer(ConnectionContext context, ConsumerInfo info) throws Exception {
184        throw new BrokerStoppedException(this.message);
185    }
186
187    @Override
188    public void removeSubscription(ConnectionContext context, RemoveSubscriptionInfo info) throws Exception {
189        throw new BrokerStoppedException(this.message);
190    }
191
192    @Override
193    public void send(ProducerBrokerExchange producerExchange, Message message) throws Exception {
194        throw new BrokerStoppedException(this.message);
195    }
196
197    @Override
198    public void acknowledge(ConsumerBrokerExchange consumerExchange, MessageAck ack) throws Exception {
199        throw new BrokerStoppedException(this.message);
200    }
201
202    @Override
203    public void gc() {
204        throw new BrokerStoppedException(this.message);
205    }
206
207    @Override
208    public void start() throws Exception {
209        throw new BrokerStoppedException(this.message);
210    }
211
212    @Override
213    public void stop() throws Exception {
214        throw new BrokerStoppedException(this.message);
215    }
216
217    @Override
218    public void addBroker(Connection connection, BrokerInfo info) {
219        throw new BrokerStoppedException(this.message);
220
221    }
222
223    @Override
224    public void removeBroker(Connection connection, BrokerInfo info) {
225        throw new BrokerStoppedException(this.message);
226    }
227
228    @Override
229    public BrokerInfo[] getPeerBrokerInfos() {
230        throw new BrokerStoppedException(this.message);
231    }
232
233    @Override
234    public void preProcessDispatch(MessageDispatch messageDispatch) {
235        throw new BrokerStoppedException(this.message);
236    }
237
238    @Override
239    public void postProcessDispatch(MessageDispatch messageDispatch) {
240        throw new BrokerStoppedException(this.message);
241    }
242
243    @Override
244    public void processDispatchNotification(MessageDispatchNotification messageDispatchNotification) throws Exception {
245        throw new BrokerStoppedException(this.message);
246    }
247
248    @Override
249    public boolean isStopped() {
250        return true;
251    }
252
253    @Override
254    public Set<ActiveMQDestination> getDurableDestinations() {
255        throw new BrokerStoppedException(this.message);
256    }
257
258    @Override
259    public void addDestinationInfo(ConnectionContext context, DestinationInfo info) throws Exception {
260        throw new BrokerStoppedException(this.message);
261    }
262
263    @Override
264    public void removeDestinationInfo(ConnectionContext context, DestinationInfo info) throws Exception {
265        throw new BrokerStoppedException(this.message);
266    }
267
268    @Override
269    public boolean isFaultTolerantConfiguration() {
270        throw new BrokerStoppedException(this.message);
271    }
272
273    @Override
274    public ConnectionContext getAdminConnectionContext() {
275        throw new BrokerStoppedException(this.message);
276    }
277
278    @Override
279    public void setAdminConnectionContext(ConnectionContext adminConnectionContext) {
280        throw new BrokerStoppedException(this.message);
281    }
282
283    @Override
284    public Response messagePull(ConnectionContext context, MessagePull pull) {
285        throw new BrokerStoppedException(this.message);
286    }
287
288    @Override
289    public PListStore getTempDataStore() {
290        throw new BrokerStoppedException(this.message);
291    }
292
293    @Override
294    public URI getVmConnectorURI() {
295        throw new BrokerStoppedException(this.message);
296    }
297
298    @Override
299    public void brokerServiceStarted() {
300        throw new BrokerStoppedException(this.message);
301    }
302
303    @Override
304    public BrokerService getBrokerService() {
305        throw new BrokerStoppedException(this.message);
306    }
307
308    @Override
309    public boolean isExpired(MessageReference messageReference) {
310        throw new BrokerStoppedException(this.message);
311    }
312
313    @Override
314    public void messageExpired(ConnectionContext context, MessageReference message, Subscription subscription) {
315        throw new BrokerStoppedException(this.message);
316    }
317
318    @Override
319    public boolean sendToDeadLetterQueue(ConnectionContext context, MessageReference messageReference,
320                                         Subscription subscription, Throwable poisonCause) {
321        throw new BrokerStoppedException(this.message);
322    }
323
324    @Override
325    public Broker getRoot() {
326        throw new BrokerStoppedException(this.message);
327    }
328
329    @Override
330    public long getBrokerSequenceId() {
331        throw new BrokerStoppedException(this.message);
332    }
333
334    @Override
335    public void fastProducer(ConnectionContext context,ProducerInfo producerInfo,ActiveMQDestination destination) {
336        throw new BrokerStoppedException(this.message);
337    }
338
339    @Override
340    public void isFull(ConnectionContext context,Destination destination, Usage usage) {
341        throw new BrokerStoppedException(this.message);
342    }
343
344    @Override
345    public void messageConsumed(ConnectionContext context,MessageReference messageReference) {
346        throw new BrokerStoppedException(this.message);
347    }
348
349    @Override
350    public void messageDelivered(ConnectionContext context,MessageReference messageReference) {
351        throw new BrokerStoppedException(this.message);
352    }
353
354    @Override
355    public void messageDiscarded(ConnectionContext context, Subscription sub, MessageReference messageReference) {
356        throw new BrokerStoppedException(this.message);
357    }
358
359    @Override
360    public void slowConsumer(ConnectionContext context, Destination destination,Subscription subs) {
361        throw new BrokerStoppedException(this.message);
362    }
363
364    @Override
365    public void nowMasterBroker() {
366        throw new BrokerStoppedException(this.message);
367    }
368
369    @Override
370    public void processConsumerControl(ConsumerBrokerExchange consumerExchange,
371            ConsumerControl control) {
372        throw new BrokerStoppedException(this.message);
373    }
374
375    @Override
376    public void reapplyInterceptor() {
377        throw new BrokerStoppedException(this.message);
378    }
379
380    @Override
381    public Scheduler getScheduler() {
382        throw new BrokerStoppedException(this.message);
383    }
384
385    @Override
386    public ThreadPoolExecutor getExecutor() {
387        throw new BrokerStoppedException(this.message);
388    }
389
390    @Override
391    public void networkBridgeStarted(BrokerInfo brokerInfo, boolean createdByDuplex, String remoteIp) {
392        throw new BrokerStoppedException(this.message);
393    }
394
395    @Override
396    public void networkBridgeStopped(BrokerInfo brokerInfo) {
397        throw new BrokerStoppedException(this.message);
398    }
399}