001: /**
002: * Copyright (C) 2001-2005 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.jmx;
018:
019: import org.objectweb.fractal.api.Component;
020: import org.objectweb.fractal.jmx.agent.Admin;
021: import org.objectweb.fractal.jmx.agent.AdminAttributes;
022: import org.objectweb.fractal.util.Fractal;
023: import org.objectweb.jorm.api.PMapper;
024: import org.objectweb.perseus.cache.api.CacheAttributeController;
025: import org.objectweb.perseus.cache.api.CacheManager;
026: import org.objectweb.perseus.cache.api.UnbindManager;
027: import org.objectweb.perseus.dependency.api.DependencyGraph;
028: import org.objectweb.perseus.pool.api.Pool;
029: import org.objectweb.perseus.pool.api.PoolAttributes;
030: import org.objectweb.speedo.AbstractSpeedo;
031: import org.objectweb.speedo.jmx.mbeans.Cache;
032: import org.objectweb.speedo.jmx.mbeans.Connection;
033: import org.objectweb.speedo.jmx.mbeans.PMF;
034: import org.objectweb.speedo.jmx.mbeans.Query;
035: import org.objectweb.speedo.jmx.mbeans.Tx;
036: import org.objectweb.speedo.lib.FractalHelper;
037: import org.objectweb.speedo.mapper.api.JormFactory;
038: import org.objectweb.speedo.mapper.api.JormFactoryAttributes;
039: import org.objectweb.speedo.pm.jdo.api.JDOPOManagerFactoryItf;
040: import org.objectweb.speedo.query.api.QueryManagerAttribute;
041: import org.objectweb.util.monolog.api.Logger;
042: import org.objectweb.util.monolog.wrapper.remote.lib.Logging;
043:
044: import javax.management.MBeanServer;
045: import javax.management.ObjectName;
046:
047: /**
048: *
049: *
050: * @author S.Chassande-Barrioz
051: */
052: public class JMXConfigurator {
053: private MBeanServer server;
054: private Component speedo;
055: private Logger logger;
056:
057: private final static String EXPOSED_ITFS = "*:*";
058:
059: public JMXConfigurator(Component speedo, Logger logger)
060: throws Exception {
061: this .speedo = speedo;
062: this .logger = logger;
063: //Fetch the MBean server
064: Component agentC = FractalHelper.getSubComponent(speedo,
065: AbstractSpeedo.JMX_AGENT_PATH + ".agent", logger);
066: server = ((AdminAttributes) Fractal
067: .getAttributeController(agentC)).getRawMBeanServer();
068: }
069:
070: public void init() throws Exception {
071: addConnectionMBeans();
072: addPMFMBeans();
073: addQueryMBean();
074: addCacheMBeans();
075: addTxMBeans();
076: addLoggingMBeans();
077: exposeMBeans();
078: }
079:
080: public void exposeMBeans() throws Exception {
081: Component agentC = FractalHelper.getSubComponent(speedo,
082: AbstractSpeedo.JMX_AGENT_PATH + ".agent", logger);
083: AdminAttributes aa = (AdminAttributes) Fractal
084: .getAttributeController(agentC);
085: aa.setItfPatterns(EXPOSED_ITFS);
086: ((Admin) agentC.getFcInterface("admin")).expose();
087: }
088:
089: public void addConnectionMBeans() throws Exception {
090: Connection c = new Connection(
091: getPoolAttributes(AbstractSpeedo.CONNECTION_POOL_PATH),
092: getPoolItf(AbstractSpeedo.PM_POOL_PATH), getPMF());
093: server.registerMBean(c,
094: new ObjectName("speedo:name=connection"));
095: }
096:
097: public void addPMFMBeans() throws Exception {
098: PMapper mapper = (PMapper) FractalHelper.getSubComponent(
099: speedo, AbstractSpeedo.PRIMITIVE_MAPPER_PATH, logger)
100: .getFcInterface("mapper");
101: PMF p = new PMF(getPoolAttributes(AbstractSpeedo.PM_POOL_PATH),
102: getPoolItf(AbstractSpeedo.PM_POOL_PATH), getPMF(),
103: mapper, getJormFactory(), getJormFactoryAttributes());
104: server.registerMBean(p, new ObjectName("speedo:name=pmf"));
105: }
106:
107: public void addQueryMBean() throws Exception {
108: Component cache = FractalHelper.getSubComponent(speedo,
109: AbstractSpeedo.QUERY_CACHE_PATH, logger);
110: CacheAttributeController ca = (CacheAttributeController) Fractal
111: .getAttributeController(FractalHelper.getSubComponent(
112: cache, "cache-manager", logger));
113: UnbindManager um = (UnbindManager) cache
114: .getFcInterface("unbind-manager");
115: CacheManager cm = (CacheManager) cache
116: .getFcInterface("cache-manager");
117: QueryManagerAttribute qma = (QueryManagerAttribute) Fractal
118: .getAttributeController(FractalHelper.getSubComponent(
119: speedo, AbstractSpeedo.QUERY_MANAGER, logger));
120: Query qm = new Query(ca, um, cm, qma);
121: server.registerMBean(qm, new ObjectName("speedo:name=query"));
122: }
123:
124: public void addCacheMBeans() throws Exception {
125: Component cache = FractalHelper.getSubComponent(speedo,
126: AbstractSpeedo.MEMORY_CACHE_PATH, logger);
127: CacheAttributeController ca = (CacheAttributeController) Fractal
128: .getAttributeController(FractalHelper.getSubComponent(
129: cache, "cache-manager", logger));
130: UnbindManager um = (UnbindManager) cache
131: .getFcInterface("unbind-manager");
132: CacheManager cm = (CacheManager) cache
133: .getFcInterface("cache-manager");
134: Cache c = new Cache(ca, um, cm, getPMF(), getJormFactory());
135: server.registerMBean(c, new ObjectName("speedo:name=cache"));
136: }
137:
138: public void addTxMBeans() throws Exception {
139: DependencyGraph dg = (DependencyGraph) FractalHelper
140: .getSubComponent(speedo,
141: AbstractSpeedo.DEPENDENCY_GRAPH_PATH, logger)
142: .getFcInterface("dependency-graph");
143: Tx p = new Tx(getPMF(), dg);
144: server.registerMBean(p, new ObjectName("speedo:name=tx"));
145: }
146:
147: public void addLoggingMBeans() throws Exception {
148: server.registerMBean(new Logging(), new ObjectName(
149: "speedo:name=log"));
150: }
151:
152: private JDOPOManagerFactoryItf getPMF() throws Exception {
153: return (JDOPOManagerFactoryItf) FractalHelper.getSubComponent(
154: speedo, AbstractSpeedo.PMF_PATH, logger)
155: .getFcInterface("po-manager-factory");
156: }
157:
158: public PoolAttributes getPoolAttributes(String poolpath)
159: throws Exception {
160: return (PoolAttributes) Fractal
161: .getAttributeController(FractalHelper.getSubComponent(
162: speedo, poolpath, logger));
163: }
164:
165: public Pool getPoolItf(String poolpath) throws Exception {
166: return (Pool) FractalHelper.getSubComponent(speedo, poolpath,
167: logger).getFcInterface("pool");
168: }
169:
170: private JormFactory getJormFactory() throws Exception {
171: return (JormFactory) FractalHelper.getSubComponent(speedo,
172: AbstractSpeedo.JORM_FACTORY_PATH, logger)
173: .getFcInterface("jorm-factory");
174: }
175:
176: private JormFactoryAttributes getJormFactoryAttributes()
177: throws Exception {
178: return (JormFactoryAttributes) Fractal
179: .getAttributeController(FractalHelper.getSubComponent(
180: speedo, AbstractSpeedo.JORM_FACTORY_PATH,
181: logger));
182: }
183: }
|