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.tools.remote.local;
10:
11: import java.io.IOException;
12: import java.net.MalformedURLException;
13: import java.util.Map;
14: import javax.management.MBeanServerConnection;
15: import javax.management.remote.JMXServiceURL;
16: import javax.security.auth.Subject;
17:
18: import mx4j.remote.ConnectionResolver;
19: import mx4j.tools.remote.AbstractJMXConnector;
20: import mx4j.tools.remote.Connection;
21: import mx4j.tools.remote.ConnectionManager;
22:
23: /**
24: * @version $Revision: 1.9 $
25: */
26: public class LocalConnector extends AbstractJMXConnector {
27: private transient Connection connection;
28:
29: public LocalConnector(JMXServiceURL url, Map environment)
30: throws IOException {
31: super (url);
32: }
33:
34: protected void doConnect(Map environment) throws IOException,
35: SecurityException {
36: JMXServiceURL address = getAddress();
37: String protocol = address.getProtocol();
38: ConnectionResolver resolver = ConnectionResolver
39: .newConnectionResolver(protocol, environment);
40: if (resolver == null)
41: throw new MalformedURLException("Unsupported protocol: "
42: + protocol);
43:
44: ConnectionManager server = (ConnectionManager) resolver
45: .lookupClient(address, environment);
46: server = (ConnectionManager) resolver.bindClient(server,
47: environment);
48:
49: Object credentials = environment == null ? null : environment
50: .get(CREDENTIALS);
51: connection = server.connect(credentials);
52: }
53:
54: protected void doClose() throws IOException {
55: connection.close();
56: }
57:
58: protected MBeanServerConnection doGetMBeanServerConnection(
59: Subject delegate) throws IOException {
60: return new LocalConnectionMBeanServerConnection(
61: (LocalConnection) connection, delegate);
62: }
63:
64: public String getConnectionId() throws IOException {
65: return connection.getConnectionId();
66: }
67: }
|