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