类javax.management.remote.JMXServiceURL源码实例Demo

下面列出了怎么用javax.management.remote.JMXServiceURL的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: TencentKona-8   文件: SecurityTest.java
private JMXServiceURL createServerSide(Map<String, Object> serverMap)
throws Exception {
    final int NINETY_SECONDS = 90;

    System.out.println("SecurityTest::createServerSide: Start") ;

    // Prepare server side security env
    HashMap<String, Object> env = setServerSecurityEnv(serverMap);

    // Create and start mbean server and connector server
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
    cs.start();

    // Waits availibility of connector server
    Utils.waitReady(cs, NINETY_SECONDS);

    JMXServiceURL addr = cs.getAddress();

    System.out.println("SecurityTest::createServerSide: Done.") ;

    return addr;
}
 
源代码2 项目: openjdk-8   文件: ProviderTest.java
private static void dotest(JMXServiceURL url, MBeanServer mbs)
    throws Exception {
    JMXConnectorServer server = null;
    JMXConnector client = null;

    server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    server.start();
    JMXServiceURL outputAddr = server.getAddress();
    System.out.println("Server started ["+ outputAddr+ "]");

    client = JMXConnectorFactory.newJMXConnector(outputAddr, null);

    client.connect();
    System.out.println("Client connected");

    MBeanServerConnection connection
        = client.getMBeanServerConnection();

    System.out.println(connection.getDefaultDomain());
}
 
源代码3 项目: jdk1.8-source-analysis   文件: RMIConnector.java
private RMIServer findRMIServer(JMXServiceURL directoryURL,
        Map<String, Object> environment)
        throws NamingException, IOException {
    final boolean isIiop = RMIConnectorServer.isIiopURL(directoryURL,true);
    if (isIiop) {
        // Make sure java.naming.corba.orb is in the Map.
        environment.put(EnvHelp.DEFAULT_ORB,resolveOrb(environment));
    }

    String path = directoryURL.getURLPath();
    int end = path.indexOf(';');
    if (end < 0) end = path.length();
    if (path.startsWith("/jndi/"))
        return findRMIServerJNDI(path.substring(6,end), environment, isIiop);
    else if (path.startsWith("/stub/"))
        return findRMIServerJRMP(path.substring(6,end), environment, isIiop);
    else if (path.startsWith("/ior/")) {
        if (!IIOPHelper.isAvailable())
            throw new IOException("iiop protocol not available");
        return findRMIServerIIOP(path.substring(5,end), environment, isIiop);
    } else {
        final String msg = "URL path must begin with /jndi/ or /stub/ " +
                "or /ior/: " + path;
        throw new MalformedURLException(msg);
    }
}
 
源代码4 项目: ankush   文件: JmxUtil.java
/**
 * Jmx connection.
 * 
 * @param nodeIp
 *            the node ip
 * @param jmxPort
 *            the jmx port
 * @return the jMX connector
 * @throws Exception
 */
private JMXConnector jmxConnection(String nodeIp, int jmxPort) {
	JMXConnector connector = null;
	try {
		JMXServiceURL address = new JMXServiceURL(
				"service:jmx:rmi:///jndi/rmi://" + nodeIp + ":" + jmxPort
						+ "/jmxrmi");
		connector = JMXConnectorFactory.connect(address);
	} catch (Exception e) {
		if (e.getMessage().contains("java.net.ConnectException")) {
			logger.info("Host unavailable at Node..." + nodeIp);
			logger.error(e.getMessage());
			// throw new AnkushException("Host unavailable-" + nodeIp);
		}
	}
	return connector;
}
 
源代码5 项目: jdk8u-jdk   文件: RMIConnector.java
private RMIServer findRMIServer(JMXServiceURL directoryURL,
        Map<String, Object> environment)
        throws NamingException, IOException {
    final boolean isIiop = RMIConnectorServer.isIiopURL(directoryURL,true);
    if (isIiop) {
        // Make sure java.naming.corba.orb is in the Map.
        environment.put(EnvHelp.DEFAULT_ORB,resolveOrb(environment));
    }

    String path = directoryURL.getURLPath();
    int end = path.indexOf(';');
    if (end < 0) end = path.length();
    if (path.startsWith("/jndi/"))
        return findRMIServerJNDI(path.substring(6,end), environment, isIiop);
    else if (path.startsWith("/stub/"))
        return findRMIServerJRMP(path.substring(6,end), environment, isIiop);
    else if (path.startsWith("/ior/")) {
        if (!IIOPHelper.isAvailable())
            throw new IOException("iiop protocol not available");
        return findRMIServerIIOP(path.substring(5,end), environment, isIiop);
    } else {
        final String msg = "URL path must begin with /jndi/ or /stub/ " +
                "or /ior/: " + path;
        throw new MalformedURLException(msg);
    }
}
 
源代码6 项目: brooklyn-server   文件: JmxmpAgent.java
/** optionally starts a normal JMXRMI connector in addition */
public JMXConnectorServer startNormalJmxRmiConnectorIfRequested(Properties properties) {
    try {
        String rmiPortS = properties.getProperty(RMI_REGISTRY_PORT_PROPERTY);
        if (rmiPortS==null || rmiPortS.length()==0)
            return null;

        int rmiPort = Integer.parseInt(rmiPortS);
        LocateRegistry.createRegistry(rmiPort);
        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        String svc =
            "service:jmx:rmi:///jndi/rmi://localhost:"+rmiPort+"/jmxrmi";

        JMXServiceURL url = new JMXServiceURL(svc);
        RMIConnectorServer rmiServer = new RMIConnectorServer(url, null, mbeanServer);
        rmiServer.start();
        return rmiServer;
    } catch (Exception e) {
        System.err.println("Unable to start JmxmpAgent: "+e);
        throw new RuntimeException(e);
    }
}
 
源代码7 项目: dragonwell8_jdk   文件: ProviderTest.java
private static void dotest(JMXServiceURL url, MBeanServer mbs)
    throws Exception {
    JMXConnectorServer server = null;
    JMXConnector client = null;

    server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    server.start();
    JMXServiceURL outputAddr = server.getAddress();
    System.out.println("Server started ["+ outputAddr+ "]");

    client = JMXConnectorFactory.newJMXConnector(outputAddr, null);

    client.connect();
    System.out.println("Client connected");

    MBeanServerConnection connection
        = client.getMBeanServerConnection();

    System.out.println(connection.getDefaultDomain());
}
 
源代码8 项目: spring-init   文件: VirtualMachineMetrics.java
public static Map<String, Long> fetch(String pid) {
	if (pid == null) {
		return Collections.emptyMap();
	}
	try {
		VirtualMachine vm = VirtualMachine.attach(pid);
		vm.startLocalManagementAgent();
		String connectorAddress = vm.getAgentProperties()
				.getProperty(CONNECTOR_ADDRESS);
		JMXServiceURL url = new JMXServiceURL(connectorAddress);
		JMXConnector connector = JMXConnectorFactory.connect(url);
		MBeanServerConnection connection = connector.getMBeanServerConnection();
		gc(connection);
		Map<String, Long> metrics = new HashMap<>(
				new BufferPools(connection).getMetrics());
		metrics.putAll(new Threads(connection).getMetrics());
		metrics.putAll(new Classes(connection).getMetrics());
		vm.detach();
		return metrics;
	}
	catch (Exception e) {
		return Collections.emptyMap();
	}
}
 
源代码9 项目: jdk8u_jdk   文件: RMIConnectorLogAttributesTest.java
private JMXConnectorServer startServer(int rmiPort) throws Exception {
    System.out.println("DEBUG: Create RMI registry on port " + rmiPort);
    LocateRegistry.createRegistry(rmiPort);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

    HashMap<String,Object> env = new HashMap<String,Object>();

    JMXServiceURL url =
            new JMXServiceURL("service:jmx:rmi:///jndi/rmi://127.0.0.1:" + rmiPort + "/jmxrmi");
    JMXConnectorServer cs =
            JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);

    cs.start();
    System.out.println("DEBUG: Started the RMI connector server");
    return cs;
}
 
源代码10 项目: jdk8u-dev-jdk   文件: TestManager.java
private static void connect(String pid, String address) throws Exception {
    if (address == null) {
        throw new RuntimeException("Local connector address for " +
                                   pid + " is null");
    }

    System.out.println("Connect to process " + pid + " via: " + address);

    JMXServiceURL url = new JMXServiceURL(address);
    JMXConnector c = JMXConnectorFactory.connect(url);
    MBeanServerConnection server = c.getMBeanServerConnection();

    System.out.println("Connected.");

    RuntimeMXBean rt = newPlatformMXBeanProxy(server,
        RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
    System.out.println(rt.getName());

    // close the connection
    c.close();
}
 
源代码11 项目: scheduling   文件: ResourceManagerJMXTest.java
private void jmxAuthInvalidCreds(JMXServiceURL jmxRmiServiceURL) {
    RMTHelper.log("Test invalid JMX auth without creds (expect SecurityException)");
    try {
        JMXConnectorFactory.connect(jmxRmiServiceURL, new HashMap<String, Object>(0));
    } catch (Exception e) {
        assertTrue("JMX auth must throw SecurityException if a client tries to connect without creds in the " +
                   "env", e instanceof SecurityException);
    }
}
 
源代码12 项目: JCoz   文件: JCozClient.java
/**
 * Connect to the profiler on the attached VM.
 *
 * @throws MalformedURLException
 */
private void connectToProfiler() throws IOException {

    Properties props = this.vm.getAgentProperties();
    String connectorAddress = props.getProperty(JCozClient.CONNECTOR_ADDR_PROPERTY);

    JMXServiceURL url = new JMXServiceURL(connectorAddress);
    this.connector = JMXConnectorFactory.connect(url);
    MBeanServerConnection mbeanConn = this.connector.getMBeanServerConnection();

    this.mxbeanProxy = JMX.newMXBeanProxy(mbeanConn,
            JCozProfiler.getMBeanName(), JCozProfilerMBean.class);
}
 
源代码13 项目: openjdk-8   文件: RMIConnector.java
private RMIConnector(RMIServer rmiServer, JMXServiceURL address,
        Map<String, ?> environment) {
    if (rmiServer == null && address == null) throw new
            IllegalArgumentException("rmiServer and jmxServiceURL both null");
    initTransients();

    this.rmiServer = rmiServer;
    this.jmxServiceURL = address;
    if (environment == null) {
        this.env = Collections.emptyMap();
    } else {
        EnvHelp.checkAttributes(environment);
        this.env = Collections.unmodifiableMap(environment);
    }
}
 
源代码14 项目: jdk8u_jdk   文件: RMIConnectorLogAttributesTest.java
private JMXConnector connectToServer(JMXConnectorServer server) throws IOException, MalformedObjectNameException, NullPointerException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException, ReflectionException, MBeanException {
    JMXServiceURL url = server.getAddress();
    Map<String, Object> env = new HashMap<String, Object>();
    JMXConnector connector = JMXConnectorFactory.connect(url, env);

    System.out.println("DEBUG: Client connected to RMI at: " + url);

    return connector;
}
 
源代码15 项目: gemfirexd-oss   文件: LocalProcessController.java
/**
 * Connects to the JMX agent in the local process.
 * 
 * @throws ConnectionFailedException if there was a failure to connect to the local JMX connector in the process
 * @throws IOException if the JDK management agent cannot be found and loaded
 */
void connect() throws ConnectionFailedException, IOException {
  try {
    final JMXServiceURL jmxUrl = getJMXServiceURL();
    this.jmxc = JMXConnectorFactory.connect(jmxUrl);
    this.server = this.jmxc.getMBeanServerConnection();
  } catch (AttachNotSupportedException e) {
    throw new ConnectionFailedException("Failed to connect to process '" + this.pid + "'", e);
  }
}
 
源代码16 项目: cacheonix-core   文件: Server.java
public static void main(String[] args) throws Exception
{
   prepareUsersFile();

   // The address of the connector server
   JMXServiceURL url = new JMXServiceURL("rmi", "localhost", 0, "/jndi/jmx");

   // Specify the authenticator in the environment Map, using the
   // standard property JMXConnector.AUTHENTICATOR
   Map environment = new HashMap();
   JMXAuthenticator authenticator = new PasswordAuthenticator(new File(PASSWORD_FILE));
   environment.put(JMXConnectorServer.AUTHENTICATOR, authenticator);

   // Create and register the connector server
   JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, environment, null);
   ObjectName cntorServerName = ObjectName.getInstance(":service=" + JMXConnectorServer.class.getName() + ",protocol=" + url.getProtocol());
   MBeanServer server = MBeanServerFactory.createMBeanServer("remote.security.example");
   server.registerMBean(cntorServer, cntorServerName);

   // Setup the rmiregistry to bind in JNDI the RMIConnectorServer stub.
   NamingService naming = new NamingService();
   ObjectName namingName = ObjectName.getInstance(":service=" + NamingService.class.getName());
   server.registerMBean(naming, namingName);
   naming.start();

   // Setup the interception
   SubjectTrackingMBeanServer interceptor = new SubjectTrackingMBeanServer();
   cntorServer.setMBeanServerForwarder(interceptor);

   // Start the connector server
   cntorServer.start();

   System.out.println("Server up and running");
}
 
源代码17 项目: capsule   文件: ProcessUtil.java
/**
 * Connects to a child JVM process
 *
 * @param p          the process to which to connect
 * @param startAgent whether to installed the JMX agent in the target process if not already in place
 * @return an {@link MBeanServerConnection} to the process's MBean server
 */
public static MBeanServerConnection getMBeanServerConnection(Process p, boolean startAgent) {
    try {
        final JMXServiceURL serviceURL = getLocalConnectorAddress(p, startAgent);
        final JMXConnector connector = JMXConnectorFactory.connect(serviceURL);
        final MBeanServerConnection mbsc = connector.getMBeanServerConnection();
        return mbsc;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
源代码18 项目: jdk1.8-source-analysis   文件: ServerProvider.java
public JMXConnectorServer newJMXConnectorServer(JMXServiceURL serviceURL,
                                                Map<String,?> environment,
                                                MBeanServer mbeanServer)
        throws IOException {
    if (!serviceURL.getProtocol().equals("iiop")) {
        throw new MalformedURLException("Protocol not iiop: " +
                                        serviceURL.getProtocol());
    }
    return new RMIConnectorServer(serviceURL, environment, mbeanServer);
}
 
源代码19 项目: Java8CN   文件: RMIConnector.java
private RMIConnector(RMIServer rmiServer, JMXServiceURL address,
        Map<String, ?> environment) {
    if (rmiServer == null && address == null) throw new
            IllegalArgumentException("rmiServer and jmxServiceURL both null");
    initTransients();

    this.rmiServer = rmiServer;
    this.jmxServiceURL = address;
    if (environment == null) {
        this.env = Collections.emptyMap();
    } else {
        EnvHelp.checkAttributes(environment);
        this.env = Collections.unmodifiableMap(environment);
    }
}
 
源代码20 项目: openjdk-jdk8u-backup   文件: ServerProvider.java
public JMXConnectorServer newJMXConnectorServer(JMXServiceURL serviceURL,
                                                Map<String,?> environment,
                                                MBeanServer mbeanServer)
        throws IOException {
    if (!serviceURL.getProtocol().equals("rmi")) {
        throw new MalformedURLException("Protocol not rmi: " +
                                        serviceURL.getProtocol());
    }
    return new RMIConnectorServer(serviceURL, environment, mbeanServer);
}
 
源代码21 项目: jdk8u-jdk   文件: RMIConnector.java
private RMIConnector(RMIServer rmiServer, JMXServiceURL address,
        Map<String, ?> environment) {
    if (rmiServer == null && address == null) throw new
            IllegalArgumentException("rmiServer and jmxServiceURL both null");
    initTransients();

    this.rmiServer = rmiServer;
    this.jmxServiceURL = address;
    if (environment == null) {
        this.env = Collections.emptyMap();
    } else {
        EnvHelp.checkAttributes(environment);
        this.env = Collections.unmodifiableMap(environment);
    }
}
 
源代码22 项目: dragonwell8_jdk   文件: JMXConnectorProviderImpl.java
public JMXConnector newJMXConnector(JMXServiceURL url,
                                    Map<String,?> map)
    throws IOException {
    final String protocol = url.getProtocol();
    called = true;
    System.out.println("JMXConnectorProviderImpl called");

    if(protocol.equals("rmi"))
        return new RMIConnector(url, map);
    if(protocol.equals("throw-provider-exception"))
        throw new JMXProviderException("I have been asked to throw");

    throw new IllegalArgumentException("UNKNOWN PROTOCOL");
}
 
源代码23 项目: jdk8u-dev-jdk   文件: RMIConnector.java
private RMIConnector(RMIServer rmiServer, JMXServiceURL address,
        Map<String, ?> environment) {
    if (rmiServer == null && address == null) throw new
            IllegalArgumentException("rmiServer and jmxServiceURL both null");
    initTransients();

    this.rmiServer = rmiServer;
    this.jmxServiceURL = address;
    if (environment == null) {
        this.env = Collections.emptyMap();
    } else {
        EnvHelp.checkAttributes(environment);
        this.env = Collections.unmodifiableMap(environment);
    }
}
 
源代码24 项目: openjdk-jdk9   文件: ServerProvider.java
public JMXConnectorServer newJMXConnectorServer(JMXServiceURL serviceURL,
                                                Map<String,?> environment,
                                                MBeanServer mbeanServer)
        throws IOException {
    if (!serviceURL.getProtocol().equals("rmi")) {
        throw new MalformedURLException("Protocol not rmi: " +
                                        serviceURL.getProtocol());
    }
    return new RMIConnectorServer(serviceURL, environment, mbeanServer);
}
 
源代码25 项目: TencentKona-8   文件: ServerProvider.java
public JMXConnectorServer newJMXConnectorServer(JMXServiceURL serviceURL,
                                                Map<String,?> environment,
                                                MBeanServer mbeanServer)
        throws IOException {
    if (!serviceURL.getProtocol().equals("rmi")) {
        throw new MalformedURLException("Protocol not rmi: " +
                                        serviceURL.getProtocol());
    }
    return new RMIConnectorServer(serviceURL, environment, mbeanServer);
}
 
源代码26 项目: jdk8u_jdk   文件: Server.java
public static String start() throws Exception {
    int serverPort = 12345;
    ObjectName name = new ObjectName("test", "foo", "bar");
    MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
    SteMBean bean = new Ste();
    jmxServer.registerMBean(bean, name);
    boolean exported = false;
    Random rnd = new Random(System.currentTimeMillis());
    do {
        try {
            LocateRegistry.createRegistry(serverPort);
            exported = true;
        } catch (ExportException ee) {
            if (ee.getCause() instanceof BindException) {
                serverPort = rnd.nextInt(10000) + 4096;
            } else {
                throw ee;
            }
        }

    } while (!exported);
    JMXServiceURL serverUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + serverPort + "/test");
    JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(serverUrl, null, jmxServer);
    jmxConnector.start();

    return serverUrl.toString();
}
 
源代码27 项目: openjdk-8-source   文件: ClientProvider.java
public JMXConnector newJMXConnector(JMXServiceURL serviceURL,
                                    Map<String,?> environment)
        throws IOException {
    if (!serviceURL.getProtocol().equals("iiop")) {
        throw new MalformedURLException("Protocol not iiop: " +
                                        serviceURL.getProtocol());
    }
    return new RMIConnector(serviceURL, environment);
}
 
源代码28 项目: TencentKona-8   文件: SecurityTest.java
public void run(Map<String, Object> serverArgs, String clientArgs[]) {

        System.out.println("SecurityTest::run: Start") ;
        int errorCount = 0;

        try {
            // Initialise the server side
            JMXServiceURL urlToUse = createServerSide(serverArgs);

            // Run client side
            errorCount = runClientSide(clientArgs, urlToUse.toString());

            if ( errorCount == 0 ) {
                System.out.println("SecurityTest::run: Done without any error") ;
            } else {
                System.out.println(
                    "SecurityTest::run: Done with " + errorCount + " error(s)");
                throw new RuntimeException("errorCount = " + errorCount);
            }

            cs.stop();

        } catch(Exception e) {
            throw new RuntimeException(e);
        }

    }
 
源代码29 项目: openjdk-8   文件: ServerProvider.java
public JMXConnectorServer newJMXConnectorServer(JMXServiceURL serviceURL,
                                                Map<String,?> environment,
                                                MBeanServer mbeanServer)
        throws IOException {
    if (!serviceURL.getProtocol().equals("iiop")) {
        throw new MalformedURLException("Protocol not iiop: " +
                                        serviceURL.getProtocol());
    }
    return new RMIConnectorServer(serviceURL, environment, mbeanServer);
}
 
源代码30 项目: dragonwell8_jdk   文件: Server.java
public static String start() throws Exception {
    int serverPort = 12345;
    ObjectName name = new ObjectName("test", "foo", "bar");
    MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
    SteMBean bean = new Ste();
    jmxServer.registerMBean(bean, name);
    boolean exported = false;
    Random rnd = new Random(System.currentTimeMillis());
    do {
        try {
            LocateRegistry.createRegistry(serverPort);
            exported = true;
        } catch (ExportException ee) {
            if (ee.getCause() instanceof BindException) {
                serverPort = rnd.nextInt(10000) + 4096;
            } else {
                throw ee;
            }
        }

    } while (!exported);
    JMXServiceURL serverUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + serverPort + "/test");
    JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(serverUrl, null, jmxServer);
    jmxConnector.start();

    return serverUrl.toString();
}
 
 类所在包
 同包方法