1 8 9 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 26 public class LocalConnector extends AbstractJMXConnector 27 { 28 private transient Connection connection; 29 30 public LocalConnector(JMXServiceURL url, Map environment) throws IOException 31 { 32 super(url); 33 } 34 35 protected void doConnect(Map environment) throws IOException , SecurityException 36 { 37 JMXServiceURL address = getAddress(); 38 String protocol = address.getProtocol(); 39 ConnectionResolver resolver = ConnectionResolver.newConnectionResolver(protocol, environment); 40 if (resolver == null) throw new MalformedURLException ("Unsupported protocol: " + protocol); 41 42 ConnectionManager server = (ConnectionManager)resolver.lookupClient(address, environment); 43 server = (ConnectionManager)resolver.bindClient(server, environment); 44 45 Object credentials = environment == null ? null : environment.get(CREDENTIALS); 46 connection = server.connect(credentials); 47 } 48 49 protected void doClose() throws IOException 50 { 51 connection.close(); 52 } 53 54 protected MBeanServerConnection doGetMBeanServerConnection(Subject delegate) throws IOException 55 { 56 return new LocalConnectionMBeanServerConnection((LocalConnection)connection, delegate); 57 } 58 59 public String getConnectionId() throws IOException 60 { 61 return connection.getConnectionId(); 62 } 63 } 64 | Popular Tags |