KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > jmx > JMXConfigurator


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

18 package org.objectweb.speedo.jmx;
19
20 import org.objectweb.fractal.api.Component;
21 import org.objectweb.fractal.jmx.agent.Admin;
22 import org.objectweb.fractal.jmx.agent.AdminAttributes;
23 import org.objectweb.fractal.util.Fractal;
24 import org.objectweb.jorm.api.PMapper;
25 import org.objectweb.perseus.cache.api.CacheAttributeController;
26 import org.objectweb.perseus.cache.api.CacheManager;
27 import org.objectweb.perseus.cache.api.UnbindManager;
28 import org.objectweb.perseus.dependency.api.DependencyGraph;
29 import org.objectweb.perseus.pool.api.Pool;
30 import org.objectweb.perseus.pool.api.PoolAttributes;
31 import org.objectweb.speedo.Speedo;
32 import org.objectweb.speedo.jmx.mbeans.Cache;
33 import org.objectweb.speedo.jmx.mbeans.Connection;
34 import org.objectweb.speedo.jmx.mbeans.PMF;
35 import org.objectweb.speedo.jmx.mbeans.Query;
36 import org.objectweb.speedo.jmx.mbeans.Tx;
37 import org.objectweb.speedo.lib.FractalHelper;
38 import org.objectweb.speedo.mapper.api.JormFactory;
39 import org.objectweb.speedo.pm.api.ProxyManagerFactory;
40 import org.objectweb.speedo.query.api.QueryManagerAttribute;
41 import org.objectweb.util.monolog.api.Logger;
42 import org.objectweb.util.monolog.wrapper.remote.lib.Logging;
43
44 import javax.management.MBeanServer JavaDoc;
45 import javax.management.ObjectName JavaDoc;
46
47 /**
48  *
49  *
50  * @author S.Chassande-Barrioz
51  */

52 public class JMXConfigurator {
53     private MBeanServer JavaDoc server;
54     private Component speedo;
55     private Logger logger;
56     
57     private final static String JavaDoc EXPOSED_ITFS = "*:*";
58
59     public JMXConfigurator(Component speedo, Logger logger) throws Exception JavaDoc {
60         this.speedo = speedo;
61         this.logger = logger;
62         //Fetch the MBean server
63
Component agentC = FractalHelper.getSubComponent(
64                 speedo, Speedo.JMX_AGENT_PATH + ".agent", logger);
65         server = ((AdminAttributes)
66                 Fractal.getAttributeController(agentC)).getRawMBeanServer();
67     }
68     
69     public void init() throws Exception JavaDoc {
70         addConnectionMBeans();
71         addPMFMBeans();
72         addQueryMBean();
73         addCacheMBeans();
74         addTxMBeans();
75         addLoggingMBeans();
76         exposeMBeans();
77     }
78     
79     public void exposeMBeans() throws Exception JavaDoc {
80         Component agentC = FractalHelper.getSubComponent(
81                 speedo, Speedo.JMX_AGENT_PATH + ".agent", logger);
82         AdminAttributes aa = (AdminAttributes)
83                 Fractal.getAttributeController(agentC);
84         aa.setItfPatterns(EXPOSED_ITFS);
85         ((Admin) agentC.getFcInterface("admin")).expose();
86     }
87     
88     public void addConnectionMBeans() throws Exception JavaDoc {
89         Connection c = new Connection(
90                 getPoolAttributes(Speedo.CONNECTION_POOL_PATH),
91                 getPoolItf(Speedo.PM_POOL_PATH),
92                 getPMF());
93         server.registerMBean(c, new ObjectName JavaDoc("speedo:name=connection"));
94     }
95     
96     public void addPMFMBeans() throws Exception JavaDoc {
97         PMapper mapper = (PMapper)
98             FractalHelper.getSubComponent(
99                 speedo, Speedo.PRIMITIVE_MAPPER_PATH, logger)
100                 .getFcInterface("mapper");
101         PMF p = new PMF(
102                 getPoolAttributes(Speedo.PM_POOL_PATH),
103                 getPoolItf(Speedo.PM_POOL_PATH),
104                 getPMF(),
105                 mapper,
106                 getJormFactory());
107         server.registerMBean(p, new ObjectName JavaDoc("speedo:name=pmf"));
108     }
109
110     public void addQueryMBean() throws Exception JavaDoc {
111         Component cache = FractalHelper.getSubComponent(
112                 speedo, Speedo.QUERY_CACHE_PATH, logger);
113         CacheAttributeController ca = (CacheAttributeController)
114             Fractal.getAttributeController(
115                 FractalHelper.getSubComponent(cache, "cache-manager", logger));
116         UnbindManager um = (UnbindManager) cache.getFcInterface("unbind-manager");
117         CacheManager cm = (CacheManager) cache.getFcInterface("cache-manager");
118         QueryManagerAttribute qma = (QueryManagerAttribute)
119             Fractal.getAttributeController(
120                 FractalHelper.getSubComponent(
121                         speedo, Speedo.QUERY_MANAGER, logger));
122         Query qm = new Query(ca, um, cm, qma);
123         server.registerMBean(qm, new ObjectName JavaDoc("speedo:name=query"));
124     }
125     
126     public void addCacheMBeans() throws Exception JavaDoc {
127         Component cache = FractalHelper.getSubComponent(
128                 speedo, Speedo.MEMORY_CACHE_PATH, logger);
129         CacheAttributeController ca = (CacheAttributeController)
130             Fractal.getAttributeController(
131                 FractalHelper.getSubComponent(cache, "cache-manager", logger));
132         UnbindManager um = (UnbindManager) cache.getFcInterface("unbind-manager");
133         CacheManager cm = (CacheManager) cache.getFcInterface("cache-manager");
134         Cache c = new Cache(ca, um, cm, getPMF(), getJormFactory());
135         server.registerMBean(c, new ObjectName JavaDoc("speedo:name=cache"));
136     }
137     
138     public void addTxMBeans() throws Exception JavaDoc {
139         DependencyGraph dg = (DependencyGraph) FractalHelper.getSubComponent(
140                 speedo, Speedo.DEPENDENCY_GRAPH_PATH, logger)
141                     .getFcInterface("dependency-graph");
142         Tx p = new Tx(getPMF(), dg);
143         server.registerMBean(p, new ObjectName JavaDoc("speedo:name=tx"));
144     }
145
146     public void addLoggingMBeans() throws Exception JavaDoc {
147         server.registerMBean(new Logging(), new ObjectName JavaDoc("speedo:name=log"));
148     }
149
150     private ProxyManagerFactory getPMF() throws Exception JavaDoc {
151         return(ProxyManagerFactory)
152             FractalHelper.getSubComponent(
153                     speedo, Speedo.PMF_PATH, logger)
154                     .getFcInterface("proxy-manager-factory");
155     }
156     
157     public PoolAttributes getPoolAttributes(String JavaDoc poolpath) throws Exception JavaDoc {
158         return (PoolAttributes)
159             Fractal.getAttributeController(
160                 FractalHelper.getSubComponent(
161                         speedo, poolpath, logger));
162     }
163     
164     public Pool getPoolItf(String JavaDoc poolpath) throws Exception JavaDoc {
165         return (Pool) FractalHelper.getSubComponent(
166                         speedo, poolpath, logger).getFcInterface("pool");
167     }
168     
169     private JormFactory getJormFactory() throws Exception JavaDoc {
170         return (JormFactory) FractalHelper.getSubComponent(
171             speedo, Speedo.JORM_FACTORY_PATH, logger)
172                 .getFcInterface("jorm-factory");
173     }
174 }
175
Popular Tags