1 23 24 package com.sun.enterprise.admin.mbeans; 25 26 import javax.management.ObjectName ; 27 import javax.management.NotificationBroadcasterSupport ; 28 import javax.management.Notification ; 29 import javax.management.NotificationListener ; 30 import javax.management.MBeanServerConnection ; 31 32 import java.util.Map ; 33 import java.util.HashMap ; 34 import java.util.Collections ; 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 import com.sun.enterprise.admin.server.core.AdminService; 42 import com.sun.enterprise.config.serverbeans.ServerHelper; 43 import com.sun.enterprise.config.ConfigContext; 44 import com.sun.enterprise.admin.common.MBeanServerFactory; 45 46 import com.sun.appserv.management.j2ee.StateManageable; 47 48 54 55 public class DomainStatus extends NotificationBroadcasterSupport 56 implements DomainStatusMBean { 57 58 59 62 private static final Logger sLogger = 63 Logger.getLogger(AdminConstants.kLoggerName); 64 private static final StringManager localStrings = 65 StringManager.getManager( DomainStatus.class ); 66 private Map m; 67 68 71 public DomainStatus() { 72 m = Collections.synchronizedMap(new HashMap ()); 73 } 74 75 79 public int getstate(String serverName) throws Exception { 80 sLogger.log(Level.FINE, "DomainStatus.getstate for " + serverName); 81 if ((serverName != null) && (serverName.length() > 0)) { 83 if (m.containsKey(serverName)) { 84 return ((Integer ) m.get(serverName)).intValue(); 85 } else { 86 throw new Exception ( 87 localStrings.getString( 88 "admin.mbeans.domainStatus.serverNotFound", 89 serverName)); 90 } 91 } 92 return StateManageable.STATE_FAILED; 93 } 94 95 98 public void setstate(String serverName, Integer state) throws Exception { 99 sLogger.log(Level.FINE, "DomainStatus.setstate for " + serverName); 100 if ((serverName != null) && (serverName.length() > 0)) { 102 m.put(serverName, state); 103 sendServerStatusChangedNotification(serverName); 105 } else { 106 throw new Exception ( 107 localStrings.getString( 108 "admin.mbeans.domainStatus.serverNotFound", 109 serverName)); 110 } 111 } 112 113 116 public MBeanServerConnection getServerMBeanServerConnection(String serverName) 117 throws Exception { 118 119 sLogger.log(Level.FINE, 120 "DomainStatus.getServerMBeanServerConnection for " + serverName); 121 ConfigContext configContext = 123 AdminService.getAdminService().getAdminContext().getAdminConfigContext(); 124 MBeanServerConnection mbsc = null; 125 126 if (ServerHelper.isDAS(configContext, serverName)) { 128 mbsc = MBeanServerFactory.getMBeanServer(); 129 } else { 130 mbsc = ServerHelper.connect(configContext, serverName); 131 } 132 133 return mbsc; 134 } 135 136 139 private void sendServerStatusChangedNotification(final String serverName) { 140 141 sLogger.log(Level.FINE, 142 "DomainStatus.sendServerStatusChangedNotification for " + serverName); 143 144 Map m = Collections.synchronizedMap(new HashMap ()); 145 m.put(DomainStatusMBean.SERVER_NAME_KEY, serverName); 146 Notification notification = new Notification ( 147 DomainStatusMBean.SERVER_STATUS_NOTIFICATION_TYPE, 148 this, 149 0, 150 serverName); 151 notification.setUserData(m); 152 sendNotification(notification); 153 } 154 155 } 156 | Popular Tags |