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