01: /*
02: * BEGIN_HEADER - DO NOT EDIT
03: *
04: * The contents of this file are subject to the terms
05: * of the Common Development and Distribution License
06: * (the "License"). You may not use this file except
07: * in compliance with the License.
08: *
09: * You can obtain a copy of the license at
10: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
11: * See the License for the specific language governing
12: * permissions and limitations under the License.
13: *
14: * When distributing Covered Code, include this CDDL
15: * HEADER in each file and include the License file at
16: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
17: * If applicable add the following below this CDDL HEADER,
18: * with the fields enclosed by brackets "[]" replaced with
19: * your own identifying information: Portions Copyright
20: * [year] [name of copyright owner]
21: */
22:
23: /*
24: * @(#)TestAdminService.java
25: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
26: *
27: * END_HEADER - DO NOT EDIT
28: */
29: package java4ant;
30:
31: import javax.management.remote.*;
32: import javax.management.*;
33:
34: /**
35: */
36: public class TestAdminService {
37:
38: private MBeanServerConnection mbns;
39: private static final String RESULT_PREFIX = "##### Result of ";
40:
41: private static final String USER = "jmx.user";
42: private static final String PASSWORD = "jmx.password";
43: private static final String PROVIDER = "jmx.provider";
44: private static final String TARGET = "target";
45:
46: public void initMBeanServerConnection() throws Exception {
47: java.util.Map<String, String[]> env = new java.util.HashMap();
48: String user = System.getProperty(USER);
49: String pass = System.getProperty(PASSWORD);
50: String[] credentials = new String[] { user, pass };
51: env.put("jmx.remote.credentials", credentials);
52:
53: String jmxProvider = System.getProperty(PROVIDER);
54:
55: JMXConnector connector = JMXConnectorFactory.connect(
56: new JMXServiceURL(jmxProvider), env);
57:
58: mbns = connector.getMBeanServerConnection();
59: }
60:
61: public ObjectName getAdminServiceName() throws Exception {
62: String admin = "com.sun.jbi:Target="
63: + System.getProperty(TARGET, "domain")
64: + ",ServiceName=AdminService,ServiceType=Admin";
65: return new ObjectName(admin);
66: }
67:
68: public void getEngineComponents() throws Exception {
69: ObjectName[] objNames = (ObjectName[]) mbns.invoke(
70: getAdminServiceName(), "getEngineComponents",
71: new Object[0], new String[0]);
72:
73: System.out.println(RESULT_PREFIX + " getEngineComponents =");
74: for (ObjectName mbnName : objNames) {
75: System.out.println(mbnName.toString());
76: }
77: }
78:
79: public void getBindingComponents() throws Exception {
80: ObjectName[] objNames = (ObjectName[]) mbns.invoke(
81: getAdminServiceName(), "getBindingComponents",
82: new Object[0], new String[0]);
83:
84: System.out.println(RESULT_PREFIX + " getBindingComponents =");
85: for (ObjectName mbnName : objNames) {
86: System.out.println(mbnName.toString());
87: }
88: }
89:
90: public static void main(String[] params) throws Exception {
91: TestAdminService test = new TestAdminService();
92:
93: test.initMBeanServerConnection();
94: test.getEngineComponents();
95: test.getBindingComponents();
96: }
97:
98: }
|