1 23 24 package com.sun.enterprise.management.agent; 25 26 import java.security.*; 27 import java.rmi.RemoteException ; 28 import java.util.*; 29 import java.io.ObjectInputStream ; 30 import javax.management.*; 31 import javax.management.j2ee.*; 32 import javax.naming.*; 33 import com.sun.enterprise.management.util.J2EEModuleUtil; 34 import com.sun.enterprise.admin.meta.MBeanRegistryFactory; 36 import com.sun.enterprise.admin.AdminContext; 37 import com.sun.enterprise.config.ConfigContext; 38 import com.sun.enterprise.config.serverbeans.ServerHelper; 39 import com.sun.enterprise.config.serverbeans.Server; 40 import com.sun.enterprise.config.ConfigException; 41 import java.util.logging.Logger ; 42 import java.util.logging.Level ; 43 44 45 51 public class MEJBHelper { 52 53 private MBeanServerConnection server; 55 private static MEJBHelper mejbHelper = null; 56 private ListenerRegistry listenerRegistry = null; 57 static Logger _logger = MBeanRegistryFactory.getAdminContext().getAdminLogger(); 58 59 private MEJBHelper() { 61 62 73 74 AdminContext adminContext = MBeanRegistryFactory.getAdminContext(); 75 ConfigContext configContext = adminContext.getRuntimeConfigContext(); 76 String serverName = adminContext.getServerName(); 77 78 try { 79 boolean isDas = ServerHelper.isDAS(configContext, serverName); 81 if (isDas) { 82 ArrayList mbservers = (ArrayList) AccessController.doPrivileged( 84 new PrivilegedAction() { 85 public java.lang.Object run() { 86 return MBeanServerFactory.findMBeanServer(null); 87 } 88 }); 89 if (mbservers.isEmpty()) { 90 server = null; 91 } 92 else { 93 server = (MBeanServer)mbservers.get(0); 94 } 95 } else { 96 server = null; 98 Server dasSrv = ServerHelper.getDAS(configContext); 99 String dasName = dasSrv.getName(); 100 MBeanServerConnection mbsc = ServerHelper.connect(configContext, dasName); 101 if (mbsc != null) { 102 server = mbsc; 103 } 104 } 105 } catch (Exception e) { 106 _logger.log(Level.WARNING, "MEJBHelper.exception_determining_mbean_server_connection"); 107 } 108 } 109 110 public static MEJBHelper getMEJBHelper(){ 111 if(mejbHelper == null){ 112 mejbHelper = new MEJBHelper(); 113 } 114 return mejbHelper; 115 } 116 117 132 133 public Set queryNames(ObjectName name, QueryExp query) throws Exception { 134 return server.queryNames(name, query); 135 } 136 137 138 143 public boolean isRegistered(ObjectName name) throws Exception { 144 return server.isRegistered(name); 145 } 146 147 148 149 150 public Integer getMBeanCount() throws java.io.IOException , Exception { 151 return server.getMBeanCount(); 152 } 153 154 155 163 public MBeanInfo getMBeanInfo(ObjectName name) 164 throws javax.management.InstanceNotFoundException , 165 javax.management.IntrospectionException , 166 javax.management.ReflectionException , 167 java.io.IOException , 168 RemoteException { 169 return server.getMBeanInfo(name); 170 } 171 172 173 185 public Object getAttribute(ObjectName name, String attribute) throws MBeanException, 186 javax.management.AttributeNotFoundException , javax.management.InstanceNotFoundException , 187 javax.management.ReflectionException , java.io.IOException , RemoteException { 188 return server.getAttribute(name, attribute); 189 } 190 191 201 public javax.management.AttributeList getAttributes(ObjectName name, String [] attributes) 202 throws javax.management.InstanceNotFoundException , javax.management.ReflectionException , 203 java.io.IOException , RemoteException { 204 return server.getAttributes(name, attributes); 205 } 206 207 220 public void setAttribute(ObjectName name, javax.management.Attribute attribute) 221 throws javax.management.InstanceNotFoundException , javax.management.AttributeNotFoundException , 222 javax.management.InvalidAttributeValueException , MBeanException, 223 javax.management.ReflectionException , java.io.IOException , RemoteException { 224 server.setAttribute(name, attribute); 225 } 226 227 238 public javax.management.AttributeList setAttributes(ObjectName name, javax.management.AttributeList attributes) 239 throws javax.management.InstanceNotFoundException , javax.management.ReflectionException , 240 java.io.IOException , RemoteException { 241 return server.setAttributes(name, attributes); 242 } 243 244 257 public Object invoke(ObjectName name, String operationName, Object [] params, String [] signature) 258 throws javax.management.InstanceNotFoundException , MBeanException, 259 java.io.IOException , javax.management.ReflectionException , RemoteException { 260 return server.invoke(name, operationName, params, signature); 261 } 262 263 268 public String getDefaultDomain() throws java.io.IOException { 269 return server.getDefaultDomain(); 270 } 271 272 275 public ListenerRegistration getListenerRegistry() { 276 if (listenerRegistry == null) { 277 try { 278 listenerRegistry = new ListenerRegistry(java.net.InetAddress.getLocalHost().getHostAddress()); 279 } catch (java.net.UnknownHostException e) { 280 listenerRegistry = new ListenerRegistry(J2EEModuleUtil.getDomainName()); 281 } 282 } 283 return listenerRegistry; 284 } 285 286 } 287 | Popular Tags |