1 package org.exoplatform.container.test; 2 3 import java.util.* ; 4 5 import javax.management.MBeanServer ; 6 import javax.management.MBeanServerFactory ; 7 import javax.management.ObjectInstance ; 8 import javax.management.ObjectName ; 9 import org.exoplatform.container.PortalContainer; 10 import org.exoplatform.container.RootContainer; 11 import org.exoplatform.test.BasicTestCase; 12 13 import org.exoplatform.container.mocks.MockService; 14 import org.exoplatform.container.configuration.*; 15 16 21 public class TestJMXRegistration extends BasicTestCase { 22 23 public void testJMXRegistration() throws Exception { 24 PortalContainer pcontainer = PortalContainer.getInstance() ; 25 pcontainer.getComponentInstanceOfType(ConfigurationManager.class) ; 26 assertNotNull(pcontainer.getComponentInstanceOfType(MockService.class)); 27 MBeanServer mbeanServer = pcontainer.getMBeanServer(); 28 pcontainer.printMBeanServer() ; 29 System.out.println("Default domain : " + mbeanServer.getDefaultDomain()); 30 String name = "org.exoplatform.container.mocks:type=" + MockService.class.getName(); 31 ObjectName objectName = new ObjectName (name); 32 ObjectInstance instance = mbeanServer.getObjectInstance(objectName); 33 assertNotNull(instance); 34 Object result = mbeanServer.invoke(objectName, "hello", null, null); 35 System.out.println("Result : " + result); 36 System.out.println("=================ROOT CONTAINER===================="); 37 RootContainer.getInstance().printMBeanServer() ; 38 java.util.List servers = MBeanServerFactory.findMBeanServer(null) ; 39 for (int i = 0; i < servers.size() ; i++) { 40 MBeanServer server = (MBeanServer ) servers.get(i) ; 41 System.out.println("Server with default domain : " + server.getDefaultDomain()); 42 } 43 44 Set names = mbeanServer.queryNames(null, null) ; 45 Iterator i = names.iterator() ; 46 while (i.hasNext()) { 47 ObjectName oname = (ObjectName ) i.next() ; 48 System.out.println("object name = " + oname.getCanonicalName()) ; 49 } 50 } 51 } | Popular Tags |