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.web;
018
019 import java.util.Iterator;
020 import java.util.Set;
021
022 import org.apache.activemq.broker.Broker;
023 import org.apache.activemq.broker.BrokerService;
024 import org.apache.activemq.broker.jmx.BrokerView;
025 import org.apache.activemq.broker.jmx.BrokerViewMBean;
026 import org.apache.activemq.broker.jmx.ManagedRegionBroker;
027 import org.apache.activemq.broker.jmx.ManagementContext;
028 import org.apache.activemq.broker.region.Queue;
029 import org.apache.activemq.command.ActiveMQDestination;
030
031 /**
032 * An implementation of {@link BrokerFacade} which uses a local in JVM broker
033 *
034 * @version $Revision: 569067 $
035 */
036 public class LocalBrokerFacade extends BrokerFacadeSupport {
037 private BrokerService brokerService;
038
039 public LocalBrokerFacade(BrokerService brokerService) {
040 this.brokerService = brokerService;
041 }
042
043 public BrokerService getBrokerService() {
044 return brokerService;
045 }
046
047 public Broker getBroker() throws Exception {
048 return brokerService.getBroker();
049 }
050
051 public ManagementContext getManagementContext() {
052 return brokerService.getManagementContext();
053 }
054
055 public BrokerViewMBean getBrokerAdmin() throws Exception {
056 // TODO could use JMX to look this up
057 return brokerService.getAdminView();
058 }
059
060 public ManagedRegionBroker getManagedBroker() throws Exception {
061 BrokerView adminView = brokerService.getAdminView();
062 if (adminView == null) {
063 return null;
064 }
065 return adminView.getBroker();
066 }
067
068 public void purgeQueue(ActiveMQDestination destination) throws Exception {
069 Set destinations = getManagedBroker().getQueueRegion().getDestinations(destination);
070 for (Iterator i = destinations.iterator(); i.hasNext();) {
071 Queue regionQueue = (Queue)i.next();
072 regionQueue.purge();
073 }
074 }
075 }