|
ActiveMQ example source code file (RemoteJMXBrokerFacade.java)
The ActiveMQ RemoteJMXBrokerFacade.java source code/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.activemq.web; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import javax.management.MBeanServerConnection; import javax.management.MBeanServerInvocationHandler; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import javax.management.QueryExp; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; import org.apache.activemq.broker.jmx.BrokerViewMBean; import org.apache.activemq.broker.jmx.ManagementContext; import org.apache.activemq.broker.jmx.QueueViewMBean; import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.web.config.WebConsoleConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * A {@link BrokerFacade} which uses a JMX-Connection to communicate with a * broker * * */ public class RemoteJMXBrokerFacade extends BrokerFacadeSupport { private static final transient Logger LOG = LoggerFactory.getLogger(RemoteJMXBrokerFacade.class); private String brokerName; private JMXConnector connector; private WebConsoleConfiguration configuration; public void setBrokerName(String brokerName) { this.brokerName = brokerName; } public WebConsoleConfiguration getConfiguration() { return configuration; } public void setConfiguration(WebConsoleConfiguration configuration) { this.configuration = configuration; } /** * Shutdown this facade aka close any open connection. */ public void shutdown() { closeConnection(); } private ObjectName getBrokerObjectName(MBeanServerConnection connection) throws IOException, MalformedObjectNameException { Set<ObjectName> brokers = findBrokers(connection); if (brokers.size() == 0) { throw new IOException("No broker could be found in the JMX."); } ObjectName name = brokers.iterator().next(); return name; } public BrokerViewMBean getBrokerAdmin() throws Exception { MBeanServerConnection connection = getMBeanServerConnection(); Set brokers = findBrokers(connection); if (brokers.size() == 0) { throw new IOException("No broker could be found in the JMX."); } ObjectName name = (ObjectName)brokers.iterator().next(); BrokerViewMBean mbean = (BrokerViewMBean)MBeanServerInvocationHandler.newProxyInstance(connection, name, BrokerViewMBean.class, true); return mbean; } public String getBrokerName() throws Exception, MalformedObjectNameException { return getBrokerAdmin().getBrokerName(); } protected MBeanServerConnection getMBeanServerConnection() throws Exception { JMXConnector connector = this.connector; if (isConnectionActive(connector)) { return connector.getMBeanServerConnection(); } synchronized (this) { closeConnection(); LOG.debug("Creating a new JMX-Connection to the broker"); this.connector = createConnection(); return this.connector.getMBeanServerConnection(); } } protected boolean isConnectionActive(JMXConnector connector) { if (connector == null) { return false; } try { MBeanServerConnection connection = connector.getMBeanServerConnection(); int brokerCount = findBrokers(connection).size(); return brokerCount > 0; } catch (Exception e) { return false; } } protected JMXConnector createConnection() { Map<String, Object> env = new HashMap Other ActiveMQ examples (source code examples)Here is a short list of links related to this ActiveMQ RemoteJMXBrokerFacade.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.