当前位置: 首页>>代码示例>>Java>>正文


Java JMXConnectorFactory类代码示例

本文整理汇总了Java中javax.management.remote.JMXConnectorFactory的典型用法代码示例。如果您正苦于以下问题:Java JMXConnectorFactory类的具体用法?Java JMXConnectorFactory怎么用?Java JMXConnectorFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JMXConnectorFactory类属于javax.management.remote包,在下文中一共展示了JMXConnectorFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dotest

import javax.management.remote.JMXConnectorFactory; //导入依赖的package包/类
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());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:ProviderTest.java

示例2: changeExportedFolderRemotely

import javax.management.remote.JMXConnectorFactory; //导入依赖的package包/类
@Test
public void changeExportedFolderRemotely() throws MalformedURLException, IOException, MalformedObjectNameException, IntrospectionException {
    // connect through RMI and get the proxy
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/server");
    JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
    ObjectName agentName = ObjectName.getInstance("myDomain:name=Alice,type=tutorial");
    /*DynamicMBean proxy = JMX.newMBeanProxy(mbs, 
            agentName,
            DynamicMBean.class);
    */
    DynamicProxy proxy = new DynamicProxy(agentName, mbsc);
     // convert the proxy to standard Folder
    
    Folder jmxFolder = new DynamicMBeanToFolderAdapter(proxy);
    //jmxFolder.getProperty("name").setValue("Cecil Corn");
    String newName = "Cecil Corn";
    jmxFolder.getFolder("knows").getProperty("name").setValue(newName);
    //mbsc.setAttribute(agentName, new Attribute("name", "Bob"));

   // waitForEnterPressed();
    assertTrue(person.knows.name.equals(newName));
    System.out.println("---/// TEST OK ///---");
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:25,代码来源:Test01_Jmx.java

示例3: AgentJMXProxy

import javax.management.remote.JMXConnectorFactory; //导入依赖的package包/类
public AgentJMXProxy(String agentJmxAddress) {
    // connect through RMI and get the proxy
    String[] strs = agentJmxAddress.split("\\" + AgentJMXComponents.JMX_SERVER_AGENT_NAME_DELIM);
    String jmxService = strs[0];
    String objectName = strs[1];
    try {
     JMXServiceURL url = new JMXServiceURL(jmxService);
     JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
     mbsc = jmxc.getMBeanServerConnection();
     agentName = ObjectName.getInstance(objectName);
     proxy = new DynamicProxy(agentName, mbsc);
     agentFlag = new FlagJMXProxy<IAgentState>(agentName, mbsc, AgentMBeanAdapter.AGENT_STATE_FLAG_NAME);
     agentId = new AgentIdJMXProxy(this);
    } catch (Exception e) {
    	throw new PogamutJMXException("Can't create AgentJMXProxy.", e, this);
    }
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:18,代码来源:AgentJMXProxy.java

示例4: initMBeanServerConnection

import javax.management.remote.JMXConnectorFactory; //导入依赖的package包/类
private static MBeanServerConnection initMBeanServerConnection() {
    try {
        String ip = Config.getProperty("jmx_ip");
        String port = Config.getProperty("jmx_port");
        String jmxURL = "service:jmx:rmi:///jndi/rmi://" + ip + ":" + port + "/jmxrmi";
        JMXServiceURL serviceURL = new JMXServiceURL(jmxURL);
        Map map = new HashMap();
        String[] credentials = Config.getProperty("credentials").split(",");
        map.put("jmx.remote.credentials", credentials);
        JMXConnector connector = JMXConnectorFactory.connect(serviceURL, map);
        mbsconnector = connector.getMBeanServerConnection();
    } catch (IOException e) {
        logger.error("get connector error" + e);
    }
    return mbsconnector;
}
 
开发者ID:Zephery,项目名称:newblog,代码行数:17,代码来源:JMXClient.java

示例5: main

import javax.management.remote.JMXConnectorFactory; //导入依赖的package包/类
public static void main(String[] args) {
		try {
			String host = "localhost"; host = "csseredapp-dev-03";
			String port = "8356"; //port = "8356";
			String mbeanName = "java.lang:type=Memory";
			String attributeName = "HeapMemoryUsage";
			
			
			
			JMXServiceURL jmxUrl = new JMXServiceURL(
					"service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi" );
//			jmxUrl = new JMXServiceURL(
//					"service:jmx:rmi://localhost/jndi/rmi://" + host + ":" + port + "/jmxrmi" );
			
			logger.info("Target: " + jmxUrl ) ;
			
			JMXConnector jmxConnection = JMXConnectorFactory.connect( jmxUrl );
			
			logger.info("Got connections") ;
			
			CompositeData resultData = (CompositeData) jmxConnection.getMBeanServerConnection()
					.getAttribute( new ObjectName(mbeanName), attributeName) ;
			
			logger.log(Level.INFO, "Got mbean: heapUsed: {0}", resultData.get( "used")) ;
			
			Thread.sleep( 5000 );
		} catch ( Exception ex ) {
			logger.log( Level.SEVERE, "Failed connection", ex );
		} 
	}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:31,代码来源:TestRawJmx.java

示例6: createJMXConnection

import javax.management.remote.JMXConnectorFactory; //导入依赖的package包/类
/**
 * create a new JMX Connection with auth when username and password is set.
 */
public static MBeanServerConnection createJMXConnection(String url,
        String host, String port, String username, String password)
        throws MalformedURLException, IOException {
    String urlForJMX;
    if (url != null)
        urlForJMX = url;
    else
        urlForJMX = JMX_SERVICE_PREFIX + host + ":" + port
                + JMX_SERVICE_SUFFIX;
    Map<String, String[]> environment = null;
    if (username != null && password != null) {
        String[] credentials = new String[2];
        credentials[0] = username;
        credentials[1] = password;
        environment = new HashMap<String, String[]>();
        environment.put(JMXConnector.CREDENTIALS, credentials);
    }
    return JMXConnectorFactory.connect(new JMXServiceURL(urlForJMX),
            environment).getMBeanServerConnection();

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:25,代码来源:JMXAccessorTask.java

示例7: MBeanWrapper

import javax.management.remote.JMXConnectorFactory; //导入依赖的package包/类
MBeanWrapper( int jvmPort ) throws MonitorConfigurationException {

        this.jvmPort = jvmPort;
        try {
            JMXConnector connector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:"
                                                                                           + this.jvmPort
                                                                                           + "/jmxrmi"),
                                                                         null);
            connector.connect();

            this.connection = connector.getMBeanServerConnection();
        } catch (Exception e) {
            final String msg = "Error initializing the JMV monitor. Unable to connect to JVM at port "
                               + this.jvmPort;
            log.error(msg, e);
            throw new MonitorConfigurationException(msg, e);
        }
    }
 
开发者ID:Axway,项目名称:ats-framework,代码行数:19,代码来源:MBeanWrapper.java

示例8: connect

import javax.management.remote.JMXConnectorFactory; //导入依赖的package包/类
/**
 * Connects to the remote {@code MBeanServer} using the configured {@code JMXServiceURL}:
 * to the specified JMX service, or to a local MBeanServer if no service URL specified.
 * @param serviceUrl the JMX service URL to connect to (may be {@code null})
 * @param environment the JMX environment for the connector (may be {@code null})
 * @param agentId the local JMX MBeanServer's agent id (may be {@code null})
 */
public MBeanServerConnection connect(JMXServiceURL serviceUrl, Map<String, ?> environment, String agentId)
		throws MBeanServerNotFoundException {

	if (serviceUrl != null) {
		if (logger.isDebugEnabled()) {
			logger.debug("Connecting to remote MBeanServer at URL [" + serviceUrl + "]");
		}
		try {
			this.connector = JMXConnectorFactory.connect(serviceUrl, environment);
			return this.connector.getMBeanServerConnection();
		}
		catch (IOException ex) {
			throw new MBeanServerNotFoundException("Could not connect to remote MBeanServer [" + serviceUrl + "]", ex);
		}
	}
	else {
		logger.debug("Attempting to locate local MBeanServer");
		return JmxUtils.locateMBeanServer(agentId);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:ConnectorDelegate.java

示例9: test_simple

import javax.management.remote.JMXConnectorFactory; //导入依赖的package包/类
@Test
public void test_simple() {
    MBeanServer mBeanServer = exporter.getServer();

    try {
        ObjectName objectName = new ObjectName("bean:name=otterControllor");
        MBeanInfo nodeInfo = mBeanServer.getMBeanInfo(objectName);
        System.out.println(nodeInfo);
        Object result = mBeanServer.getAttribute(objectName, "HeapMemoryUsage");
        System.out.println(result);

        JMXServiceURL address = new JMXServiceURL("service:jmx:rmi://127.0.0.1/jndi/rmi://127.0.0.1:1099/mbean");
        Map environment = null;

        JMXConnector cntor = JMXConnectorFactory.connect(address, environment);
        MBeanServerConnection mbsc = cntor.getMBeanServerConnection();
        String domain = mbsc.getDefaultDomain();
        System.out.println(domain);

        result = mbsc.getAttribute(objectName, "HeapMemoryUsage");
        System.out.println(result);
    } catch (Exception e) {
        want.fail(e.getMessage());
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:26,代码来源:JmxLoaderIntegration.java

示例10: connect

import javax.management.remote.JMXConnectorFactory; //导入依赖的package包/类
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();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:TestManager.java

示例11: tryConnect

import javax.management.remote.JMXConnectorFactory; //导入依赖的package包/类
private static void tryConnect(int port, boolean shouldSucceed) throws Exception {
    String jmxUrlStr =
        String.format(
            "service:jmx:rmi:///jndi/rmi://localhost:%d/jmxrmi",
            port);
    JMXServiceURL url = new JMXServiceURL(jmxUrlStr);
    HashMap<String, ?> env = new HashMap<>();

    boolean succeeded;
    try {
        JMXConnector c = JMXConnectorFactory.connect(url, env);
        c.getMBeanServerConnection();
        succeeded = true;
    } catch(Exception ex) {
        succeeded = false;
    }
    if (succeeded && !shouldSucceed) {
        throw new Exception("Could connect to agent, but should not have been possible");
    }
    if (!succeeded && shouldSucceed) {
        throw new Exception("Could not connect to agent");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:StartManagementAgent.java

示例12: main

import javax.management.remote.JMXConnectorFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    Sender sender = new Sender();
    mbs.registerMBean(sender, testObjectName);
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    try {
        test(mbs, cs, cc);
    } finally {
        cc.close();
        cs.stop();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:ListenerScaleTest.java

示例13: start

import javax.management.remote.JMXConnectorFactory; //导入依赖的package包/类
@Override
public int start() {

    try {
        this.mbscConnector = JMXConnectorFactory.connect(this.JMXConnectionURL);

        this.mbsc = mbscConnector.getMBeanServerConnection();

        return 1;
    }
    catch (Exception e) {

        log.err(this,
                "Worker[" + this.cName + "] Connect to JMXURL[" + this.JMXConnectionURL.toString() + "] FAIL:", e);

        return -1;
    }
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:19,代码来源:BaseJMXMonitorDataCatchWorker.java

示例14: main

import javax.management.remote.JMXConnectorFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    if (Platform.isDebugBuild()) {
        System.out.println("Running on a debug build. Performance test not applicable. Skipping.");
        return;
    }
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    Sender sender = new Sender();
    mbs.registerMBean(sender, testObjectName);
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
    JMXConnectorServer cs =
        JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL addr = cs.getAddress();
    JMXConnector cc = JMXConnectorFactory.connect(addr);
    try {
        test(mbs, cs, cc);
    } finally {
        cc.close();
        cs.stop();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ListenerScaleTest.java

示例15: JMXExecutor

import javax.management.remote.JMXConnectorFactory; //导入依赖的package包/类
/**
 * Instantiates a new JMXExecutor targeting the VM indicated by the given host/port combination or a full JMX
 * Service URL
 *
 * @param target a host/port combination on the format "host:port" or a full JMX Service URL of the target VM
 */
public JMXExecutor(String target) {
    String urlStr;

    if (target.matches("^\\w[\\w\\-]*(\\.[\\w\\-]+)*:\\d+$")) {
        /* Matches "hostname:port" */
        urlStr = String.format("service:jmx:rmi:///jndi/rmi://%s/jmxrmi", target);
    } else if (target.startsWith("service:")) {
        urlStr = target;
    } else {
        throw new IllegalArgumentException("Could not recognize target string: " + target);
    }

    try {
        JMXServiceURL url = new JMXServiceURL(urlStr);
        JMXConnector c = JMXConnectorFactory.connect(url, new HashMap<>());
        mbs = c.getMBeanServerConnection();
    } catch (IOException e) {
        throw new CommandExecutorException("Could not initiate connection to target: " + target, e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:JMXExecutor.java


注:本文中的javax.management.remote.JMXConnectorFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。