1 23 24 27 28 package com.sun.enterprise.admin.mbeans; 29 30 import javax.management.AttributeNotFoundException ; 32 import javax.management.ReflectionException ; 33 import javax.management.MBeanException ; 34 35 import com.sun.enterprise.admin.jmx.remote.server.rmi.JmxServiceUrlFactory; 36 import javax.management.remote.JMXServiceURL ; 37 38 import com.sun.enterprise.util.i18n.StringManager; 40 41 import com.sun.enterprise.admin.config.BaseConfigMBean; 43 import com.sun.enterprise.admin.config.MBeanConfigException; 44 45 import com.sun.enterprise.config.serverbeans.JmxConnector; 47 import com.sun.enterprise.config.ConfigException; 48 49 import java.net.InetAddress ; 51 import java.net.UnknownHostException ; 52 53 public class JmxConnectorMBean extends BaseConfigMBean 54 { 55 final private static String HOST_HOLDER_VALUE = "<host-name>"; 56 final private static int PORT_HOLDER_VALUE = 12345; 57 58 private static final StringManager localStrings = 59 StringManager.getManager(DomainMBean.class); 60 61 private String getJMXServiceURL() 62 throws UnknownHostException 63 { 64 65 JMXServiceURL url = 67 JmxServiceUrlFactory.forJconsoleOverRmiWithJndiInAppserver( 68 HOST_HOLDER_VALUE, PORT_HOLDER_VALUE); 69 String strUrl = url.toString(); 70 JmxConnector bean = (JmxConnector)this.getBaseConfigBean(); 72 String host = bean.getAddress(); 73 if(host!=null && host.trim().equals("0.0.0.0")) 74 { 75 host = null; } 78 if(host!=null) 79 strUrl = strUrl.replaceAll(HOST_HOLDER_VALUE, host); 80 try { 81 int port = Integer.parseInt(bean.getPort()); 82 strUrl = strUrl.replaceAll(String.valueOf(PORT_HOLDER_VALUE), 83 String.valueOf(port)); 84 } catch (Exception e) 85 { 86 strUrl = strUrl.replaceAll(String.valueOf(PORT_HOLDER_VALUE), 87 "<port>"); 88 } 89 90 return strUrl; 91 } 92 93 96 public Object getAttribute(String name) 97 throws AttributeNotFoundException , MBeanException , ReflectionException { 98 99 if(name.equals(JMX_SERVICE_URL_ATTRNAME)) 100 { 101 try { 102 return getJMXServiceURL(); 103 } catch (UnknownHostException uhe) { 104 throw new MBeanException (uhe); 105 } 106 } 107 return super.getAttribute(name); 108 } 109 110 public static final String JMX_SERVICE_URL_ATTRNAME = "JMXServiceURL"; 111 } 112 | Popular Tags |