1 25 package org.objectweb.jonas.jmx; 26 27 import javax.management.MBeanServer ; 29 import javax.management.MBeanServerConnection ; 30 31 import org.objectweb.jonas.common.Log; 32 import org.objectweb.jonas.service.ServiceException; 33 import org.objectweb.jonas.service.ServiceManager; 34 import org.objectweb.util.monolog.api.BasicLevel; 35 import org.objectweb.util.monolog.api.Logger; 36 37 41 public class ManagementReprFactory { 42 45 private ManagementReprFactory() { 46 } 47 48 51 private static Logger logger = Log.getLogger("org.objectweb.jonas.jmx"); 52 53 56 private static JmxService jmxService = null; 57 58 63 public static ManagementRepr getManagementRepr() { 64 ManagementRepr representative = null; 65 ClassLoader classLoader = ManagementReprFactory.class.getClassLoader(); 66 try { 67 Class managemntRepClass = classLoader.loadClass("org.objectweb.jonas.jmx.ManagementReprImpl"); 68 if (logger.isLoggable(BasicLevel.DEBUG)) { 69 logger.log(BasicLevel.DEBUG, "ManagemntReprImp class loaded"); 70 } 71 representative = (ManagementRepr) managemntRepClass.newInstance(); 72 if (logger.isLoggable(BasicLevel.DEBUG)) { 73 logger.log(BasicLevel.DEBUG, "ManagemntRepr created"); 74 } 75 } catch (Exception e) { 76 if (logger.isLoggable(BasicLevel.DEBUG)) { 77 logger.log(BasicLevel.DEBUG, "ManagementReprFactory exception : " + e.toString()); 78 } 79 } 80 return representative; 81 } 82 83 88 public static ManagementRepr getManagementRepr(String serverName) { 89 ManagementRepr representative = null; 90 ClassLoader classLoader = ManagementReprFactory.class.getClassLoader(); 91 try { 92 Class managemntRepClass = classLoader.loadClass("org.objectweb.jonas.jmx.ManagementReprImplJSR160"); 93 if (logger.isLoggable(BasicLevel.DEBUG)) { 94 logger.log(BasicLevel.DEBUG, "ManagemntReprImplJSR160 class loaded"); 95 } 96 representative = (ManagementRepr) managemntRepClass.newInstance(); 97 if (logger.isLoggable(BasicLevel.DEBUG)) { 98 logger.log(BasicLevel.DEBUG, "ManagemntRepr created"); 99 } 100 MBeanServerConnection connection = null; 104 if (jmxService == null) { 105 jmxService = (JmxService) ServiceManager.getInstance().getJmxService(); 106 } 107 connection = jmxService.getServerConnection(serverName); 108 if (connection == null) { 109 if (serverName.equals(jmxService.getJonasServerName())) { 112 connection = getLocalManagementRepr(); 113 } 114 } 115 ((ManagementReprImplJSR160) representative).setMBeanServerConnection(connection); 116 if (logger.isLoggable(BasicLevel.DEBUG)) { 117 logger.log(BasicLevel.DEBUG, "ManagementRepr has set connection for server " + serverName); 118 } 119 if (connection == null) { 120 logger.log(BasicLevel.WARN, "ManagementRepr couldn't get connection for server " + serverName); 121 } 122 } catch (Exception e) { 123 logger.log(BasicLevel.WARN, "Exception when trying to create ManagementRepr: " + e.toString()); 124 } 125 return representative; 126 } 127 128 131 public static MBeanServerConnection getLocalManagementRepr() { 132 MBeanServer myMBeanServer = null; 133 JmxService jmxService = null; 134 try { 135 jmxService = (JmxService) ServiceManager.getInstance().getJmxService(); 136 myMBeanServer = jmxService.getJmxServer(); 137 } catch (ServiceException e) { 138 e.printStackTrace(); 140 } catch (Exception e) { 141 e.printStackTrace(); 143 } 144 return (MBeanServerConnection ) myMBeanServer; 145 } 146 } 147 | Popular Tags |