KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > container > test > TestJMXRegistration


1 package org.exoplatform.container.test;
2
3 import java.util.* ;
4
5 import javax.management.MBeanServer JavaDoc;
6 import javax.management.MBeanServerFactory JavaDoc;
7 import javax.management.ObjectInstance JavaDoc;
8 import javax.management.ObjectName JavaDoc;
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 /**
17  * Created by the Exo Development team.
18  * Author : Mestrallet Benjamin
19  * benjamin.mestrallet@exoplatform.com
20  */

21 public class TestJMXRegistration extends BasicTestCase {
22
23   public void testJMXRegistration() throws Exception JavaDoc {
24     PortalContainer pcontainer = PortalContainer.getInstance() ;
25     pcontainer.getComponentInstanceOfType(ConfigurationManager.class) ;
26         assertNotNull(pcontainer.getComponentInstanceOfType(MockService.class));
27         MBeanServer JavaDoc mbeanServer = pcontainer.getMBeanServer();
28         pcontainer.printMBeanServer() ;
29         System.out.println("Default domain : " + mbeanServer.getDefaultDomain());
30         String JavaDoc name = "org.exoplatform.container.mocks:type=" + MockService.class.getName();
31         ObjectName JavaDoc objectName = new ObjectName JavaDoc(name);
32         ObjectInstance JavaDoc instance = mbeanServer.getObjectInstance(objectName);
33         assertNotNull(instance);
34         Object JavaDoc 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 JavaDoc servers = MBeanServerFactory.findMBeanServer(null) ;
39     for (int i = 0; i < servers.size() ; i++) {
40         MBeanServer JavaDoc server = (MBeanServer JavaDoc) 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 JavaDoc oname = (ObjectName JavaDoc) i.next() ;
48       System.out.println("object name = " + oname.getCanonicalName()) ;
49     }
50     }
51 }
Popular Tags