1 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 ; 45 import javax.management.ObjectName ; 46 47 52 public class JMXConfigurator { 53 private MBeanServer server; 54 private Component speedo; 55 private Logger logger; 56 57 private final static String EXPOSED_ITFS = "*:*"; 58 59 public JMXConfigurator(Component speedo, Logger logger) throws Exception { 60 this.speedo = speedo; 61 this.logger = logger; 62 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 { 70 addConnectionMBeans(); 71 addPMFMBeans(); 72 addQueryMBean(); 73 addCacheMBeans(); 74 addTxMBeans(); 75 addLoggingMBeans(); 76 exposeMBeans(); 77 } 78 79 public void exposeMBeans() throws Exception { 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 { 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 ("speedo:name=connection")); 94 } 95 96 public void addPMFMBeans() throws Exception { 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 ("speedo:name=pmf")); 108 } 109 110 public void addQueryMBean() throws Exception { 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 ("speedo:name=query")); 124 } 125 126 public void addCacheMBeans() throws Exception { 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 ("speedo:name=cache")); 136 } 137 138 public void addTxMBeans() throws Exception { 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 ("speedo:name=tx")); 144 } 145 146 public void addLoggingMBeans() throws Exception { 147 server.registerMBean(new Logging(), new ObjectName ("speedo:name=log")); 148 } 149 150 private ProxyManagerFactory getPMF() throws Exception { 151 return(ProxyManagerFactory) 152 FractalHelper.getSubComponent( 153 speedo, Speedo.PMF_PATH, logger) 154 .getFcInterface("proxy-manager-factory"); 155 } 156 157 public PoolAttributes getPoolAttributes(String poolpath) throws Exception { 158 return (PoolAttributes) 159 Fractal.getAttributeController( 160 FractalHelper.getSubComponent( 161 speedo, poolpath, logger)); 162 } 163 164 public Pool getPoolItf(String poolpath) throws Exception { 165 return (Pool) FractalHelper.getSubComponent( 166 speedo, poolpath, logger).getFcInterface("pool"); 167 } 168 169 private JormFactory getJormFactory() throws Exception { 170 return (JormFactory) FractalHelper.getSubComponent( 171 speedo, Speedo.JORM_FACTORY_PATH, logger) 172 .getFcInterface("jorm-factory"); 173 } 174 } 175 | Popular Tags |