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.interception;
10:
11: import java.util.HashMap;
12: import java.util.Map;
13: import javax.management.MBeanServerConnection;
14: import javax.management.remote.JMXConnector;
15: import javax.management.remote.JMXConnectorFactory;
16: import javax.management.remote.JMXServiceURL;
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: public static void main(String[] args) throws Exception {
27: // The address of the connector server
28: JMXServiceURL url = new JMXServiceURL("rmi", "localhost", 0,
29: "/jndi/jmx");
30:
31: // The credentials are passed via the environment Map
32: Map environment = new HashMap();
33: String[] credentials = new String[] { "guest", "guest" };
34: environment.put(JMXConnector.CREDENTIALS, credentials);
35:
36: // Connect to the server
37: JMXConnector cntor = JMXConnectorFactory.connect(url,
38: environment);
39:
40: MBeanServerConnection connection = cntor
41: .getMBeanServerConnection();
42:
43: // On the server's console, this call will be intercepted
44: String domain = connection.getDefaultDomain();
45: System.out.println("Default domain = " + domain);
46: }
47: }
|