1 /*
2 * File: JMXServer.java
3 * Date: Dec 8, 2003
4 */
5 package com.rhi.architecture.resource.jmx;
6
7 import com.rhi.architecture.resource.InitializationException;
8 import com.rhi.architecture.resource.Resource;
9
10 import java.util.Properties;
11
12 import javax.management.*;
13 import javax.naming.*;
14
15 import mx4j.util.*;
16 import mx4j.adaptor.rmi.jrmp.*;
17
18 /***
19 * JMXServer
20 *
21 * @author <a href="mailto:pete_mckinstry@yahoo.com">Pete McKinstry</a>
22 * @copyright 2003, All rights reserved.
23 */
24 public class JMXServer implements Resource {
25
26 /***
27 * constructor
28 *
29 */
30 public JMXServer() {
31 super();
32 }
33
34 /***
35 * @param p
36 * @throws InitializationException
37 * @see com.rhi.architecture.resource.Resource#init(java.util.Properties)
38 */
39 public void init(Properties p) throws InitializationException {
40 // Create a MBeanServer
41 MBeanServer server = MBeanServerFactory.createMBeanServer();
42
43 // Create and start the naming service
44 ObjectName naming = new ObjectName("Naming:type=rmiregistry");
45 server.createMBean(
46 "mx4j.tools.naming.NamingService",
47 naming,
48 null,
49 new Object[] { new Integer(2099)}, // port
50 new String[] { "int" });
51 server.invoke(naming, "start", null, null);
52
53 // Create the JRMP adaptor
54 ObjectName adapter = new ObjectName("Adaptor:protocol=JRMP");
55 server.createMBean("mx4j.adaptor.rmi.jrmp.JRMPAdaptor", adapter, null);
56 JRMPAdaptorMBean mbean =
57 (JRMPAdaptorMBean)StandardMBeanProxy.create(
58 JRMPAdaptorMBean.class,
59 server,
60 adapter);
61
62 // Set the JNDI name with which will be registered
63 String jndiName = "jrmp";
64 mbean.setJNDIName(jndiName);
65
66 // Optionally, you can specify the JNDI properties,
67 // instead of having in the classpath a jndi.properties file
68 mbean.putJNDIProperty(
69 Context.INITIAL_CONTEXT_FACTORY,
70 "com.sun.jndi.rmi.registry.RegistryContextFactory");
71 mbean.putJNDIProperty(Context.PROVIDER_URL, "rmi://localhost:2099");
72
73 // Registers the JRMP adaptor in JNDI and starts it
74 mbean.start();
75
76 // // Register the mbean
77 // String className = Statistics.class.getName();
78 // ObjectName objectName = new ObjectName("PARC:name=Statistics");
79 // server.createMBean(className, objectName, null);
80 // mbean.start();
81 }
82
83 /***
84 *
85 * @see com.rhi.architecture.resource.Resource#close()
86 */
87 public void close() {
88 // TODO Auto-generated method stub
89
90 }
91
92 }
This page was automatically generated by Maven