All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fusesource.fabric.camel.facade.JmxTemplateCamelFacade Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2010 Red Hat, Inc.
 *
 *  Red Hat 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.fusesource.fabric.camel.facade;

import java.util.List;
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;

import org.fusesource.fabric.service.JmxTemplateSupport;
import org.fusesource.fabric.camel.facade.mbean.CamelComponentMBean;
import org.fusesource.fabric.camel.facade.mbean.CamelConsumerMBean;
import org.fusesource.fabric.camel.facade.mbean.CamelEndpointMBean;
import org.fusesource.fabric.camel.facade.mbean.CamelFabricTracerMBean;
import org.fusesource.fabric.camel.facade.mbean.CamelProcessorMBean;
import org.fusesource.fabric.camel.facade.mbean.CamelRouteMBean;
import org.fusesource.fabric.camel.facade.mbean.CamelThreadPoolMBean;
import org.fusesource.fabric.camel.facade.mbean.CamelContextMBean;

/**
 *
 */
public class JmxTemplateCamelFacade implements CamelFacade {
    private final JmxTemplateSupport template;

    public JmxTemplateCamelFacade(JmxTemplateSupport template) {
        this.template = template;
    }

    /**
     * Executes a JMX operation on a BrokerFacade
     */
    public  T execute(final CamelFacadeCallback callback) {
        return template.execute(new JmxTemplateSupport.JmxConnectorCallback() {
            public T doWithJmxConnector(JMXConnector connector) throws Exception {
                MBeanServerConnection connection = connector.getMBeanServerConnection();
                CamelFacade camelFacade = new RemoteJMXCamelFacade(connection);
                return callback.doWithCamelFacade(camelFacade);
            }
        });
    }

    public List getCamelContexts() throws Exception {
        return execute(new CamelFacadeCallback>() {
           public List doWithCamelFacade(CamelFacade camel) throws Exception {
                return camel.getCamelContexts();
            }
        });
    }

    public CamelContextMBean getCamelContext(final String managementName) {
        return execute(new CamelFacadeCallback() {
           public CamelContextMBean doWithCamelFacade(CamelFacade camel) throws Exception {
                return camel.getCamelContext(managementName);
            }
        });
    }

    public CamelFabricTracerMBean getFabricTracer(final String managementName) throws Exception {
        return execute(new CamelFacadeCallback() {
           public CamelFabricTracerMBean doWithCamelFacade(CamelFacade camel) throws Exception {
                return camel.getFabricTracer(managementName);
            }
        });
    }

    public List getComponents(final String managementName) throws Exception {
        return execute(new CamelFacadeCallback>() {
           public List doWithCamelFacade(CamelFacade camel) throws Exception {
                return camel.getComponents(managementName);
            }
        });
    }

    public List getRoutes(final String managementName) throws Exception {
        return execute(new CamelFacadeCallback>() {
           public List doWithCamelFacade(CamelFacade camel) throws Exception {
                return camel.getRoutes(managementName);
            }
        });
    }

    public List getEndpoints(final String managementName) throws Exception {
        return execute(new CamelFacadeCallback>() {
           public List doWithCamelFacade(CamelFacade camel) throws Exception {
                return camel.getEndpoints(managementName);
            }
        });
    }

    public List getConsumers(final String managementName) throws Exception {
        return execute(new CamelFacadeCallback>() {
           public List doWithCamelFacade(CamelFacade camel) throws Exception {
                return camel.getConsumers(managementName);
            }
        });
    }

    public List getProcessors(final String managementName) throws Exception {
        return execute(new CamelFacadeCallback>() {
           public List doWithCamelFacade(CamelFacade camel) throws Exception {
                return camel.getProcessors(managementName);
            }
        });
    }

    public List getThreadPools(final String managementName) throws Exception {
        return execute(new CamelFacadeCallback>() {
           public List doWithCamelFacade(CamelFacade camel) throws Exception {
                return camel.getThreadPools(managementName);
            }
        });
    }

    public String dumpRoutesStatsAsXml(final String managementName) throws Exception {
        return execute(new CamelFacadeCallback() {
            public String doWithCamelFacade(CamelFacade camel) throws Exception {
                return camel.dumpRoutesStatsAsXml(managementName);
            }
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy