Package org.objectweb.speedo.jmx

Source Code of org.objectweb.speedo.jmx.JMXConfigurator

/**
* Copyright (C) 2001-2005 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
package org.objectweb.speedo.jmx;

import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.jmx.agent.Admin;
import org.objectweb.fractal.jmx.agent.AdminAttributes;
import org.objectweb.fractal.util.Fractal;
import org.objectweb.jorm.api.PMapper;
import org.objectweb.perseus.cache.api.CacheAttributeController;
import org.objectweb.perseus.cache.api.CacheManager;
import org.objectweb.perseus.cache.api.UnbindManager;
import org.objectweb.perseus.dependency.api.DependencyGraph;
import org.objectweb.perseus.pool.api.Pool;
import org.objectweb.perseus.pool.api.PoolAttributes;
import org.objectweb.speedo.AbstractSpeedo;
import org.objectweb.speedo.jmx.mbeans.Cache;
import org.objectweb.speedo.jmx.mbeans.Connection;
import org.objectweb.speedo.jmx.mbeans.PMF;
import org.objectweb.speedo.jmx.mbeans.Query;
import org.objectweb.speedo.jmx.mbeans.Tx;
import org.objectweb.speedo.lib.FractalHelper;
import org.objectweb.speedo.mapper.api.JormFactory;
import org.objectweb.speedo.mapper.api.JormFactoryAttributes;
import org.objectweb.speedo.pm.jdo.api.JDOPOManagerFactoryItf;
import org.objectweb.speedo.query.api.QueryManagerAttribute;
import org.objectweb.util.monolog.api.Logger;
import org.objectweb.util.monolog.wrapper.remote.lib.Logging;

import javax.management.MBeanServer;
import javax.management.ObjectName;

/**
*
*
* @author S.Chassande-Barrioz
*/
public class JMXConfigurator {
    private MBeanServer server;
    private Component speedo;
    private Logger logger;
   
    private final static String EXPOSED_ITFS = "*:*";

    public JMXConfigurator(Component speedo, Logger logger) throws Exception {
        this.speedo = speedo;
        this.logger = logger;
        //Fetch the MBean server
        Component agentC = FractalHelper.getSubComponent(
                speedo, AbstractSpeedo.JMX_AGENT_PATH + ".agent", logger);
        server = ((AdminAttributes)
                Fractal.getAttributeController(agentC)).getRawMBeanServer();
    }
   
    public void init() throws Exception {
        addConnectionMBeans();
        addPMFMBeans();
        addQueryMBean();
        addCacheMBeans();
        addTxMBeans();
        addLoggingMBeans();
        exposeMBeans();
    }
   
    public void exposeMBeans() throws Exception {
        Component agentC = FractalHelper.getSubComponent(
                speedo, AbstractSpeedo.JMX_AGENT_PATH + ".agent", logger);
        AdminAttributes aa = (AdminAttributes)
                Fractal.getAttributeController(agentC);
        aa.setItfPatterns(EXPOSED_ITFS);
    ((Admin) agentC.getFcInterface("admin")).expose();
    }
   
    public void addConnectionMBeans() throws Exception {
        Connection c = new Connection(
                getPoolAttributes(AbstractSpeedo.CONNECTION_POOL_PATH),
                getPoolItf(AbstractSpeedo.PM_POOL_PATH),
                getPMF());
        server.registerMBean(c, new ObjectName("speedo:name=connection"));
    }
   
    public void addPMFMBeans() throws Exception {
        PMapper mapper = (PMapper)
      FractalHelper.getSubComponent(
            speedo, AbstractSpeedo.PRIMITIVE_MAPPER_PATH, logger)
            .getFcInterface("mapper");
        PMF p = new PMF(
                getPoolAttributes(AbstractSpeedo.PM_POOL_PATH),
                getPoolItf(AbstractSpeedo.PM_POOL_PATH),
                getPMF(),
                mapper,
                getJormFactory(),
                getJormFactoryAttributes());
        server.registerMBean(p, new ObjectName("speedo:name=pmf"));
    }

    public void addQueryMBean() throws Exception {
        Component cache = FractalHelper.getSubComponent(
                speedo, AbstractSpeedo.QUERY_CACHE_PATH, logger);
        CacheAttributeController ca = (CacheAttributeController)
          Fractal.getAttributeController(
                FractalHelper.getSubComponent(cache, "cache-manager", logger));
        UnbindManager um = (UnbindManager) cache.getFcInterface("unbind-manager");
        CacheManager cm = (CacheManager) cache.getFcInterface("cache-manager");
        QueryManagerAttribute qma = (QueryManagerAttribute)
          Fractal.getAttributeController(
                FractalHelper.getSubComponent(
                        speedo, AbstractSpeedo.QUERY_MANAGER, logger));
        Query qm = new Query(ca, um, cm, qma);
        server.registerMBean(qm, new ObjectName("speedo:name=query"));
    }
   
    public void addCacheMBeans() throws Exception {
        Component cache = FractalHelper.getSubComponent(
                speedo, AbstractSpeedo.MEMORY_CACHE_PATH, logger);
        CacheAttributeController ca = (CacheAttributeController)
          Fractal.getAttributeController(
                FractalHelper.getSubComponent(cache, "cache-manager", logger));
        UnbindManager um = (UnbindManager) cache.getFcInterface("unbind-manager");
        CacheManager cm = (CacheManager) cache.getFcInterface("cache-manager");
        Cache c = new Cache(ca, um, cm, getPMF(), getJormFactory());
        server.registerMBean(c, new ObjectName("speedo:name=cache"));
    }
   
    public void addTxMBeans() throws Exception {
        DependencyGraph dg = (DependencyGraph) FractalHelper.getSubComponent(
                speedo, AbstractSpeedo.DEPENDENCY_GRAPH_PATH, logger)
                  .getFcInterface("dependency-graph");
        Tx p = new Tx(getPMF(), dg);
        server.registerMBean(p, new ObjectName("speedo:name=tx"));
    }

    public void addLoggingMBeans() throws Exception {
        server.registerMBean(new Logging(), new ObjectName("speedo:name=log"));
    }

    private JDOPOManagerFactoryItf getPMF() throws Exception {
        return(JDOPOManagerFactoryItf)
        FractalHelper.getSubComponent(
                speedo, AbstractSpeedo.PMF_PATH, logger)
                .getFcInterface("po-manager-factory");
    }
   
    public PoolAttributes getPoolAttributes(String poolpath) throws Exception {
        return (PoolAttributes)
        Fractal.getAttributeController(
                FractalHelper.getSubComponent(
                        speedo, poolpath, logger));
    }
   
    public Pool getPoolItf(String poolpath) throws Exception {
        return (Pool) FractalHelper.getSubComponent(
                        speedo, poolpath, logger).getFcInterface("pool");
    }
   
    private JormFactory getJormFactory() throws Exception {
        return (JormFactory) FractalHelper.getSubComponent(
            speedo, AbstractSpeedo.JORM_FACTORY_PATH, logger)
                .getFcInterface("jorm-factory");
    }
    private JormFactoryAttributes getJormFactoryAttributes() throws Exception {
        return (JormFactoryAttributes) Fractal.getAttributeController(
                FractalHelper.getSubComponent(
                        speedo, AbstractSpeedo.JORM_FACTORY_PATH, logger));
    }
}
TOP

Related Classes of org.objectweb.speedo.jmx.JMXConfigurator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.