KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > examples > remote > interception > Client


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.interception;
10
11 import java.util.HashMap JavaDoc;
12 import java.util.Map JavaDoc;
13 import javax.management.MBeanServerConnection JavaDoc;
14 import javax.management.remote.JMXConnector JavaDoc;
15 import javax.management.remote.JMXConnectorFactory JavaDoc;
16 import javax.management.remote.JMXServiceURL JavaDoc;
17
18 /**
19  * This example shows how to setup a JSR 160 connector client that connects to
20  * a JSR 160 connector server that intercepts calls directed to it.
21  *
22  * @version $Revision: 1.1 $
23  * @see Server
24  */

25 public class Client
26 {
27    public static void main(String JavaDoc[] args) throws Exception JavaDoc
28    {
29       // The address of the connector server
30
JMXServiceURL JavaDoc url = new JMXServiceURL JavaDoc("rmi", "localhost", 0, "/jndi/jmx");
31
32       // The credentials are passed via the environment Map
33
Map JavaDoc environment = new HashMap JavaDoc();
34       String JavaDoc[] credentials = new String JavaDoc[]{"guest", "guest"};
35       environment.put(JMXConnector.CREDENTIALS, credentials);
36
37       // Connect to the server
38
JMXConnector JavaDoc cntor = JMXConnectorFactory.connect(url, environment);
39
40       MBeanServerConnection JavaDoc connection = cntor.getMBeanServerConnection();
41
42       // On the server's console, this call will be intercepted
43
String JavaDoc domain = connection.getDefaultDomain();
44       System.out.println("Default domain = " + domain);
45    }
46 }
47
Popular Tags