KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > examples > remote > notification > Server


1 /*
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package mx4j.examples.remote.notification;
10
11 import javax.management.MBeanServer JavaDoc;
12 import javax.management.MBeanServerFactory JavaDoc;
13 import javax.management.ObjectName JavaDoc;
14 import javax.management.remote.JMXConnectorServer JavaDoc;
15 import javax.management.remote.JMXConnectorServerFactory JavaDoc;
16 import javax.management.remote.JMXServiceURL JavaDoc;
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 {
35    public static void main(String JavaDoc[] args) throws Exception JavaDoc
36    {
37       // The address of the connector server
38
JMXServiceURL JavaDoc url = new JMXServiceURL JavaDoc("rmi", "localhost", 0, "/jndi/jmx");
39
40       // No need of environment variables or the MBeanServer at this point
41
JMXConnectorServer JavaDoc cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, null);
42       ObjectName JavaDoc cntorServerName = ObjectName.getInstance(":service=" + JMXConnectorServer JavaDoc.class.getName() + ",protocol=" + url.getProtocol());
43
44       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer("remote.notification.example");
45       // Register the connector server as MBean
46
server.registerMBean(cntorServer, cntorServerName);
47
48       // The rmiregistry needed to bind the RMI stub
49
NamingService naming = new NamingService();
50       ObjectName JavaDoc namingName = ObjectName.getInstance(":service=" + NamingService.class.getName());
51       server.registerMBean(naming, namingName);
52       naming.start();
53
54       // Start the connector server
55
cntorServer.start();
56
57       System.out.println("Server up and running");
58    }
59 }
60
Popular Tags