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.notification;
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: import mx4j.tools.naming.NamingService;
19:
20: /**
21: * This example shows how to setup a JSR 160 connector server.
22: * The client counterpart of this example will register a remote NotificationListener
23: * and receive notifications over the wire.
24: * Nothing special is needed in the server side, if not registering an MBean
25: * that implements {@link javax.management.NotificationEmitter}.
26: * Every JMX implementation already has such an MBean registered, the MBeanServerDelegate.
27: * The client will register a NotificationListener to the MBeanServerDelegate MBean,
28: * that emits notifications when other MBeans are registered or unregistered.
29: *
30: * @version $Revision: 1.1 $
31: * @see Client
32: */
33: public class Server {
34: public static void main(String[] args) throws Exception {
35: // The address of the connector server
36: JMXServiceURL url = new JMXServiceURL("rmi", "localhost", 0,
37: "/jndi/jmx");
38:
39: // No need of environment variables or the MBeanServer at this point
40: JMXConnectorServer cntorServer = JMXConnectorServerFactory
41: .newJMXConnectorServer(url, null, null);
42: ObjectName cntorServerName = ObjectName.getInstance(":service="
43: + JMXConnectorServer.class.getName() + ",protocol="
44: + url.getProtocol());
45:
46: MBeanServer server = MBeanServerFactory
47: .createMBeanServer("remote.notification.example");
48: // Register the connector server as MBean
49: server.registerMBean(cntorServer, cntorServerName);
50:
51: // The rmiregistry needed to bind the RMI stub
52: NamingService naming = new NamingService();
53: ObjectName namingName = ObjectName.getInstance(":service="
54: + NamingService.class.getName());
55: server.registerMBean(naming, namingName);
56: naming.start();
57:
58: // Start the connector server
59: cntorServer.start();
60:
61: System.out.println("Server up and running");
62: }
63: }
|