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