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