01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08:
09: package mx4j.examples.remote.simple;
10:
11: import javax.management.MBeanServer;
12: import javax.management.MBeanServerFactory;
13: import javax.management.ObjectName;
14: import javax.management.remote.JMXConnectorServer;
15: import javax.management.remote.JMXConnectorServerFactory;
16: import javax.management.remote.JMXServiceURL;
17:
18: /**
19: * This example shows the simplest way to setup a JSR 160 connector server.
20: * It uses the standard JSR 160 RMIConnectorServer, and if you're familiar with
21: * RMI, you'll know that a JNDI server like the rmiregistry is needed
22: * in order to register the server stub that will be looked up by the client.
23: *
24: * @version $Revision: 1.1 $
25: */
26: public class Server {
27: public static void main(String[] args) throws Exception {
28: // The MBeanServer
29: MBeanServer server = MBeanServerFactory.createMBeanServer();
30:
31: // Register and start the rmiregistry MBean, needed by JSR 160 RMIConnectorServer
32: ObjectName namingName = ObjectName
33: .getInstance("naming:type=rmiregistry");
34: server.createMBean("mx4j.tools.naming.NamingService",
35: namingName, null);
36: server.invoke(namingName, "start", null, null);
37: int namingPort = ((Integer) server.getAttribute(namingName,
38: "Port")).intValue();
39:
40: String jndiPath = "/jmxconnector";
41: JMXServiceURL url = new JMXServiceURL(
42: "service:jmx:rmi://localhost/jndi/rmi://localhost:"
43: + namingPort + jndiPath);
44:
45: // Create and start the RMIConnectorServer
46: JMXConnectorServer connectorServer = JMXConnectorServerFactory
47: .newJMXConnectorServer(url, null, server);
48: connectorServer.start();
49:
50: System.out.println("Server up and running");
51: }
52: }
|