1 23 24 29 30 package com.sun.enterprise.admin.monitor.jndi; 31 32 import com.sun.enterprise.admin.common.constant.AdminConstants; 33 import com.sun.enterprise.util.i18n.StringManager; 34 import java.util.logging.Logger ; 35 import javax.management.MBeanServer ; 36 import javax.management.MBeanServerFactory ; 37 import javax.management.ObjectName ; 38 39 45 public class JndiMBeanManager { 46 47 48 private MBeanServer server; 49 private static final Logger logger = 50 Logger.getLogger(AdminConstants.kLoggerName); 51 private static final StringManager sm = 52 StringManager.getManager(JndiMBeanManager.class); 53 54 55 public JndiMBeanManager() { 56 server = this.getMBeanServer(); 57 } 58 59 64 public void registerMBean(ObjectName objectName) { 65 try { 66 if (server.isRegistered(objectName)) { 67 logger.fine(sm.getString("monitor.jndi.already_registered", 68 new Object [] {objectName.toString()})); 69 return; 70 } 71 server.registerMBean(new JndiMBeanImpl(), objectName); 72 logger.finer(sm.getString("monitor.jndi.registered", 73 new Object []{objectName.toString()})); 74 } catch(Exception e) { 75 logger.fine(sm.getString("monitor.jndi.register_exception", 76 new Object []{objectName})); 77 logger.throwing(JndiMBeanManager.class.getName(), 78 "registerMBean()", e); 79 } 80 } 81 82 87 public void unregisterMBean(ObjectName objectName) { 88 try { 89 if (server.isRegistered(objectName)) { 90 server.unregisterMBean(objectName); 91 logger.fine(sm.getString("monitor.jndi.unregistered", 92 new Object []{objectName.toString()})); 93 } else { 94 logger.fine(sm.getString("monitor.jndi.never_registered", 95 new Object []{objectName.toString()})); 96 } 97 } catch(Exception e) { 98 logger.fine(sm.getString("monitor.jndi.register_failed", 99 new Object []{objectName.toString()})); 100 } 101 } 102 103 108 MBeanServer getMBeanServer() { 109 MBeanServer server = null; 110 java.util.ArrayList servers = MBeanServerFactory.findMBeanServer(null); 111 if(!servers.isEmpty()){ 112 server = (MBeanServer )servers.get(0); 113 } 114 return server; 115 } 116 } 117 | Popular Tags |