1 17 package org.apache.servicemix.jbi.management; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.apache.servicemix.jbi.container.JBIContainer; 22 23 import javax.management.Attribute ; 24 import javax.management.AttributeList ; 25 import javax.management.MBeanAttributeInfo ; 26 import javax.management.MBeanInfo ; 27 import javax.management.MBeanServerConnection ; 28 import javax.management.ObjectName ; 29 import javax.management.remote.JMXConnector ; 30 import javax.management.remote.JMXConnectorFactory ; 31 import javax.management.remote.JMXServiceURL ; 32 33 import java.util.Iterator ; 34 import java.util.Set ; 35 36 import junit.framework.TestCase; 37 38 41 public class ManagementAttributesTest extends TestCase { 42 43 private Log log = LogFactory.getLog(getClass()); 44 45 private JBIContainer container; 46 47 private String namingHost = "localhost"; 49 private int namingPort = ManagementContext.DEFAULT_CONNECTOR_PORT; 50 private String jndiPath = ManagementContext.DEFAULT_CONNECTOR_PATH; 51 52 protected void setUp() throws Exception { 53 container = new JBIContainer(); 54 container.setRmiPort(namingPort); 55 container.setCreateMBeanServer(true); 56 container.init(); 57 } 58 59 protected void tearDown() throws Exception { 60 container.shutDown(); 61 } 62 63 public void testRemote() throws Exception { 64 JMXServiceURL url = new JMXServiceURL ("service:jmx:rmi:///jndi/rmi://" 66 + namingHost + ":" + namingPort + jndiPath); 67 JMXConnector connector = JMXConnectorFactory.connect(url); 69 MBeanServerConnection connection = connector.getMBeanServerConnection(); 72 73 log.info(connection.getMBeanCount()); 74 75 76 Set set = connection.queryNames(new ObjectName (connection.getDefaultDomain() + ":*"), null); 77 for (Iterator iter = set.iterator(); iter.hasNext();) { 78 ObjectName name = (ObjectName )iter.next(); 79 log.info(name.toString()); 80 MBeanInfo info = connection.getMBeanInfo(name); 81 MBeanAttributeInfo [] mia = info.getAttributes(); 82 String [] attrNames = new String [mia.length]; 83 for (int i = 0; i < mia.length; i++) { 84 attrNames[i] = mia[i].getName(); 85 log.info("attr " + mia[i].getName() + " " + mia[i].getType() + " " + connection.getAttribute(name,mia[i].getName())); 86 } 87 88 AttributeList attributeList = (AttributeList ) connection.getAttributes(name,attrNames); 89 for (int i = 0; i < attributeList.size(); i++) { 90 Attribute attribute = (Attribute ) attributeList.get(i); 91 log.info("bulk " + attribute.getName() + " " + attribute.getValue() + " " + attribute.toString()); 92 } 93 94 } 95 96 97 } 98 99 } 100 | Popular Tags |