41 package com.sun.jmx.examples.scandir;
43 import java.net.InetAddress;
44 import java.net.UnknownHostException;
45 import java.util.HashMap;
47 import javax.management.MBeanServerConnection;
48 import javax.management.remote.JMXConnector;
49 import javax.management.remote.JMXConnectorFactory;
50 import javax.management.remote.JMXServiceURL;
51 import javax.rmi.ssl.SslRMIClientSocketFactory;
76 " <server-host> <rmi-port-number>";
90 public static void main(String[] args) {
94 if (args==
null || args.length!=2) {
95 System.err.println(
"Bad number of arguments: usage is: \n\t" +
100 InetAddress.getByName(args[0]);
101 }
catch (UnknownHostException x) {
102 System.err.println(
"No such host: " + args[0]+
103 "\n usage is: \n\t" +
USAGE);
105 }
catch (Exception x) {
106 System.err.println(
"Bad address: " + args[0]+
107 "\n usage is: \n\t" +
USAGE);
111 if (Integer.parseInt(args[1]) <= 0) {
112 System.err.println(
"Bad port value: " + args[1]+
113 "\n usage is: \n\t" +
USAGE);
116 }
catch (Exception x) {
117 System.err.println(
"Bad argument: " + args[1]+
118 "\n usage is: \n\t" +
USAGE);
126 System.out.println(
"\nInitialize the environment map");
127 final Map<String,Object>
env =
new HashMap<String,Object>();
132 final String[] credentials =
new String[] {
"guest" ,
"guestpasswd" };
133 env.put(
"jmx.remote.credentials", credentials);
139 env.put(
"com.sun.jndi.rmi.factory.socket",
140 new SslRMIClientSocketFactory());
147 System.out.println(
"\nCreate the RMI connector client and " +
148 "connect it to the RMI connector server");
149 final JMXServiceURL url =
new JMXServiceURL(
150 "service:jmx:rmi:///jndi/rmi://"+args[0]+
":"+args[1] +
153 System.out.println(
"Connecting to: "+url);
154 final JMXConnector jmxc = JMXConnectorFactory.connect(url,
env);
158 System.out.println(
"\nGet the MBeanServerConnection");
159 final MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
169 "\nGet ScanDirConfigMXBean from ScanManagerMXBean");
176 "\nGet 'Configuration' attribute on ScanDirConfigMXBean");
177 System.out.println(
"\nConfiguration:\n" +
185 System.out.println(
"\nInvoke 'close' on ScanManagerMXBean");
188 }
catch (SecurityException e) {
189 System.out.println(
"\nGot expected security exception: " + e);
194 System.out.println(
"\nClose the connection to the server");
196 System.out.println(
"\nBye! Bye!");
197 }
catch (Exception e) {
198 System.out.println(
"\nGot unexpected exception: " + e);