1 23 24 package com.sun.enterprise.admin.mbeans; 25 26 import javax.management.MBeanServer ; 27 import javax.management.ObjectName ; 28 import javax.management.MalformedObjectNameException ; 29 import javax.management.MBeanServerInvocationHandler ; 30 31 import com.sun.enterprise.admin.common.MBeanServerFactory; 32 import com.sun.enterprise.server.ApplicationServer; 33 34 import com.sun.appserv.management.client.ProxyFactory; 35 36 import java.util.logging.Level ; 37 import java.util.logging.Logger ; 38 import com.sun.enterprise.util.i18n.StringManager; 39 import com.sun.enterprise.admin.common.constant.AdminConstants; 40 41 46 47 public class DomainStatusHelper { 48 49 51 private static final Logger sLogger = 52 Logger.getLogger(AdminConstants.kLoggerName); 53 54 private static final StringManager localStrings = 55 StringManager.getManager( DomainStatusHelper.class ); 56 57 private static final Class [] DOMAIN_STATUS_INTERFACES = 58 new Class [] { DomainStatusMBean.class }; 59 60 61 public DomainStatusHelper() { 63 } 64 65 public DomainStatusHelper(String serverName) { 66 } 67 68 public void setstate (String serverName, int state) { 69 sLogger.log(Level.FINE, "DomainStatusHelper setstate for " + serverName); 70 try { 71 getDomainStatus().setstate(serverName, new Integer (state)); 72 } catch (Exception e) { 73 sLogger.log(Level.WARNING, 74 "DomainStatusHelper setstate exception for server " + 75 serverName, e); 76 } 77 } 78 79 public int getstate (String serverName) throws Exception { 80 sLogger.log(Level.FINE, "DomainStatusHelper getstate for " + serverName); 81 return (getDomainStatus().getstate(serverName)); 82 } 83 84 protected DomainStatusMBean getDomainStatus() { 85 MBeanServer mbs = MBeanServerFactory.getMBeanServer(); 86 ObjectName on = null; 87 try { 88 on = getDomainStatusObjectName(); 89 } catch (MalformedObjectNameException mone) { 90 sLogger.log(Level.WARNING, 91 "DomainStatusHelper getDomainStatus ObjectName exception", mone); 92 } 93 DomainStatusMBean domainStatus = null; 94 try { 95 domainStatus = 96 (DomainStatusMBean)MBeanServerInvocationHandler.newProxyInstance( 97 mbs, on, DomainStatusMBean.class, false ); 98 } catch (Exception e) { 99 sLogger.log(Level.WARNING, 100 "DomainStatusHelper getDomainStatus io exception", e); 101 } 102 return(domainStatus); 103 } 104 105 public static ObjectName getDomainStatusObjectName() 106 throws MalformedObjectNameException { 107 108 ObjectName on = new ObjectName ( 109 ApplicationServer.getServerContext().getDefaultDomainName() + ":" + 110 DomainStatusMBean.DOMAIN_STATUS_PROPS); 111 return on; 112 } 113 114 public static ObjectName getServersConfigObjectName() 115 throws MalformedObjectNameException { 116 117 ObjectName on = new ObjectName ( 118 ApplicationServer.getServerContext().getDefaultDomainName() + ":" + 119 "type=servers,category=config"); 120 return on; 121 } 122 123 124 } 125 | Popular Tags |