View Javadoc
1 /* 2 * Created on 21.mar.2003 3 * 4 */ 5 package net.sf.panoptes.model.component; 6 7 import java.util.Hashtable; 8 9 import javax.management.ObjectName; 10 11 import net.sf.panoptes.module.jmx.DomainComponent; 12 import net.sf.panoptes.module.jmx.MBeanServerComponent; 13 import net.sf.panoptes.module.log4j.LoggerComponent; 14 import net.sf.panoptes.model.component.registry.ComponentName; 15 import net.sf.panoptes.model.component.registry.MalformedComponentNameException; 16 17 /*** 18 * @author Dag Liodden 19 * 20 */ 21 public class ComponentUtil { 22 23 public static ComponentName createQueryName(ComponentQuery query) 24 throws MalformedComponentNameException { 25 // The JBoss implementation didn't have ObjectName.quote(), so neither do we at the moment 26 Hashtable props = new Hashtable(); 27 props.put("id", String.valueOf(query.getId())); 28 props.put("query", ComponentName.quote(query.getQuery().toString())); 29 return new ComponentName(ComponentName.DOMAIN_COMPONENT_QUERY, props); 30 } 31 32 public static ComponentName createLoggerName(String host, String prefix) 33 throws MalformedComponentNameException { 34 Hashtable props = new Hashtable(); 35 if ((host != null) && (host.length() > 0)) 36 props.put("host", host); 37 if ((prefix != null) && (prefix.length() > 0)) 38 props.put("prefix", prefix); 39 return new ComponentName(ComponentName.DOMAIN_LOGGER, props); 40 } 41 42 public static ComponentName createName(LoggerComponent logger) 43 throws MalformedComponentNameException { 44 return createLoggerName(logger.getFilter().getHost(), logger.getFilter().getPrefix()); 45 } 46 47 /*** 48 * Creates a name for a <code>MBeanServerComponent</code> 49 * 50 * @param server 51 * 52 * @return 53 * @throws MalformedComponentNameException 54 */ 55 public static ComponentName createMBeanServerName(String host, String name) 56 throws MalformedComponentNameException { 57 Hashtable props = new Hashtable(); 58 props.put("host", host); 59 props.put("mbeanservername", name); 60 return new ComponentName(ComponentName.DOMAIN_MBEAN_SERVER, props); 61 } 62 63 public static ComponentName createMBeanServerName(MBeanServerComponent server) 64 throws MalformedComponentNameException { 65 return createMBeanServerName(server.getHostName(), server.getName()); 66 } 67 68 /*** 69 * Creates a name for a <code>DomainComponent</code> 70 * 71 * @param server 72 * @param domainName 73 * @return 74 * @throws MalformedComponentNameException 75 */ 76 public static ComponentName createDomainName(MBeanServerComponent server, String domainName) 77 throws MalformedComponentNameException { 78 Hashtable props = createMBeanServerName(server).getKeyPropertyList(); 79 props.put("host", server.getHostName()); 80 props.put("mbeanservername", server.getName()); 81 props.put("domain", domainName); 82 return new ComponentName(ComponentName.DOMAIN_MBEAN_DOMAIN, props); 83 84 } 85 86 /*** 87 * Creates a query that lists <code>DomainComponent</code>s in an <code>MBeanServerComponent</code> 88 * 89 * @param host host of the sever 90 * @param port port of the server 91 * @return the query 92 * @throws MalformedComponentNameException 93 */ 94 public static ComponentName createMBeanServerDomainQuery(String hostName, String name) 95 throws MalformedComponentNameException { 96 Hashtable props; 97 props = createMBeanServerName(hostName, name).getKeyPropertyList(); 98 props.put("*", "*"); 99 return new ComponentName(ComponentName.DOMAIN_MBEAN_DOMAIN, props); 100 101 } 102 103 /*** 104 * Creates a query that lists <code>MBeanComponent</code>s in a domain. 105 * 106 * @param server the <code>MBeanServerComponent</code> 107 * @param domainName the domain name 108 * @return the query 109 * @throws MalformedComponentNameException 110 */ 111 public static ComponentName createDomainMBeanQuery( 112 MBeanServerComponent server, 113 String domainName) 114 throws MalformedComponentNameException { 115 Hashtable props; 116 props = createDomainName(server, domainName).getKeyPropertyList(); 117 props.put("*", "*"); 118 return new ComponentName(ComponentName.DOMAIN_MBEAN, props); 119 120 } 121 122 /*** 123 * Creates the name of an <code>MBeanComponent</code> 124 * 125 * @param server the <code>MBeanServerComponent</code> 126 * @param domain the <code>DomainComponent</code> 127 * @param objectName the JMX <code>ObjectName</code> of the MBean 128 * @return the name 129 * @throws MalformedComponentNameException 130 * @see ObjectName 131 */ 132 public static ComponentName createMBeanName( 133 MBeanServerComponent server, 134 DomainComponent domain, 135 ObjectName objectName) 136 throws MalformedComponentNameException { 137 Hashtable props = objectName.getKeyPropertyList(); 138 props.putAll(createDomainName(server, domain.getDomainName()).getKeyPropertyList()); 139 140 return new ComponentName(ComponentName.DOMAIN_MBEAN, props); 141 } 142 }

This page was automatically generated by Maven