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