KickJava   Java API By Example, From Geeks To Geeks.

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


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.jmx.BrokerViewMBean;
21 import org.apache.activemq.broker.jmx.ManagementContext;
22 import org.apache.activemq.command.ActiveMQDestination;
23
24 import javax.management.MBeanServerConnection JavaDoc;
25 import javax.management.MBeanServerInvocationHandler JavaDoc;
26 import javax.management.MalformedObjectNameException JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28
29 /**
30  * A {@link BrokerFacade} which uses JMX to communicate with a remote broker
31  *
32  * @version $Revision: 504257 $
33  */

34 public class JMXBrokerFacade extends BrokerFacadeSupport {
35     private ManagementContext managementContext;
36     private ObjectName JavaDoc brokerName;
37
38     public BrokerViewMBean getBrokerAdmin() throws Exception JavaDoc {
39         MBeanServerConnection JavaDoc mbeanServer = getManagementContext().getMBeanServer();
40         return (BrokerViewMBean) MBeanServerInvocationHandler.newProxyInstance(mbeanServer, getBrokerName(), BrokerViewMBean.class, true);
41     }
42
43     public void purgeQueue(ActiveMQDestination destination) throws Exception JavaDoc {
44         /** TODO */
45     }
46
47     public ManagementContext getManagementContext() {
48         if (managementContext == null) {
49             managementContext = new ManagementContext();
50             managementContext.setCreateConnector(true);
51         }
52         return managementContext;
53     }
54
55     public void setManagementContext(ManagementContext managementContext) {
56         this.managementContext = managementContext;
57     }
58
59     public ObjectName JavaDoc getBrokerName() throws MalformedObjectNameException JavaDoc {
60         if (brokerName == null) {
61             brokerName = createBrokerName();
62         }
63         return brokerName;
64     }
65
66     public void setBrokerName(ObjectName JavaDoc brokerName) {
67         this.brokerName = brokerName;
68     }
69
70     protected ObjectName JavaDoc createBrokerName() throws MalformedObjectNameException JavaDoc {
71         return new ObjectName JavaDoc(getManagementContext().getJmxDomainName() + ":Type=Broker");
72     }
73 }
74
Popular Tags