1 /**2 *3 * Licensed to the Apache Software Foundation (ASF) under one or more4 * contributor license agreements. See the NOTICE file distributed with5 * this work for additional information regarding copyright ownership.6 * The ASF licenses this file to You under the Apache License, Version 2.07 * (the "License"); you may not use this file except in compliance with8 * the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */18 package org.apache.activemq.web;19 20 import org.apache.activemq.broker.Broker;21 import org.apache.activemq.broker.BrokerService;22 import org.apache.activemq.broker.jmx.BrokerView;23 import org.apache.activemq.broker.jmx.BrokerViewMBean;24 import org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean;25 import org.apache.activemq.broker.jmx.ManagedRegionBroker;26 import org.apache.activemq.broker.jmx.ManagementContext;27 import org.apache.activemq.broker.jmx.TopicViewMBean;28 import org.apache.activemq.broker.region.Queue;29 import org.apache.activemq.command.ActiveMQDestination;30 import org.apache.commons.logging.Log;31 import org.apache.commons.logging.LogFactory;32 33 import javax.management.MBeanServer ;34 import javax.management.MBeanServerInvocationHandler ;35 import javax.management.ObjectName ;36 import java.util.ArrayList ;37 import java.util.Collection ;38 import java.util.Collections ;39 import java.util.Iterator ;40 import java.util.List ;41 import java.util.Set ;42 43 /**44 * An implementation of {@link BrokerFacade} which uses a local in JVM broker45 *46 * @version $Revision: 504251 $47 */48 public class LocalBrokerFacade extends BrokerFacadeSupport {49 private BrokerService brokerService;50 51 public LocalBrokerFacade(BrokerService brokerService) {52 this.brokerService = brokerService;53 }54 55 public BrokerService getBrokerService() {56 return brokerService;57 }58 59 public Broker getBroker() throws Exception {60 return brokerService.getBroker();61 }62 63 public ManagementContext getManagementContext() {64 return brokerService.getManagementContext();65 }66 67 public BrokerViewMBean getBrokerAdmin() throws Exception {68 // TODO could use JMX to look this up69 return brokerService.getAdminView();70 }71 72 public ManagedRegionBroker getManagedBroker() throws Exception {73 BrokerView adminView = brokerService.getAdminView();74 if (adminView == null) {75 return null;76 }77 return adminView.getBroker();78 }79 80 public void purgeQueue(ActiveMQDestination destination) throws Exception {81 Set destinations = getManagedBroker().getQueueRegion().getDestinations(destination);82 for (Iterator i=destinations.iterator(); i.hasNext();) {83 Queue regionQueue = (Queue)i.next();84 regionQueue.purge();85 }86 }87 }88