KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > tools > remote > local > LocalConnector


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