KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > web > LocalBrokerFacade


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * 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 and
16  * 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 JavaDoc;
34 import javax.management.MBeanServerInvocationHandler JavaDoc;
35 import javax.management.ObjectName JavaDoc;
36 import java.util.ArrayList JavaDoc;
37 import java.util.Collection JavaDoc;
38 import java.util.Collections JavaDoc;
39 import java.util.Iterator JavaDoc;
40 import java.util.List JavaDoc;
41 import java.util.Set JavaDoc;
42
43 /**
44  * An implementation of {@link BrokerFacade} which uses a local in JVM broker
45  *
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 JavaDoc {
60         return brokerService.getBroker();
61     }
62
63     public ManagementContext getManagementContext() {
64         return brokerService.getManagementContext();
65     }
66
67     public BrokerViewMBean getBrokerAdmin() throws Exception JavaDoc {
68         // TODO could use JMX to look this up
69
return brokerService.getAdminView();
70     }
71
72     public ManagedRegionBroker getManagedBroker() throws Exception JavaDoc {
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 JavaDoc {
81         Set JavaDoc destinations = getManagedBroker().getQueueRegion().getDestinations(destination);
82         for (Iterator JavaDoc i=destinations.iterator(); i.hasNext();) {
83             Queue regionQueue = (Queue)i.next();
84             regionQueue.purge();
85         }
86     }
87 }
88
Popular Tags