當前位置: 首頁>>代碼示例>>Java>>正文


Java JMXConnector類代碼示例

本文整理匯總了Java中javax.management.remote.JMXConnector的典型用法代碼示例。如果您正苦於以下問題:Java JMXConnector類的具體用法?Java JMXConnector怎麽用?Java JMXConnector使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JMXConnector類屬於javax.management.remote包,在下文中一共展示了JMXConnector類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: dotest

import javax.management.remote.JMXConnector; //導入依賴的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.JMXConnector; //導入依賴的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.JMXConnector; //導入依賴的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.JMXConnector; //導入依賴的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.JMXConnector; //導入依賴的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: MBeanWrapper

import javax.management.remote.JMXConnector; //導入依賴的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

示例7: t3testStartSingleReader

import javax.management.remote.JMXConnector; //導入依賴的package包/類
@Test
public void t3testStartSingleReader() throws IOException {
    //create a test case file
    TestCaseHelper.createTestCaseFile(testSpaceDir,"test-file.test",10000,100);
    //connect to client
    final JMXConnector connection = getConnection();
    final MBeanServerConnection mbs = getMbeanServer(connection);
    final ObjectName readerObject = getReaderObjectName(mbs);
    //set params
    JmxClientReaderHelper.setFilePath(mbs,readerObject,testSpaceDir);
    JmxClientReaderHelper.setFileName(mbs,readerObject,"test-file.test");
    JmxClientReaderHelper.setChunkSize(mbs,readerObject,16000);
    JmxClientReaderHelper.setTakeMeasurements(mbs,readerObject,false);
    JmxClientReaderHelper.setMeasurementVolume(mbs,readerObject,-1);
    JmxClientReaderHelper.setReaderType(mbs,readerObject,ReaderType.rafr.getType());
    JmxClientReaderHelper.startSingleReader(mbs,readerObject);
    ThreadManager.nap(2500);//let the reader read a bit :)
    Assert.assertEquals(1,JmxClientReaderHelper.getReaderPoolSize(mbs,readerObject));
    final String response = JmxClientReaderHelper.stopServicePool(mbs,readerObject);
    log.log(Level.INFO, response);
}
 
開發者ID:deB4SH,項目名稱:Byter,代碼行數:22,代碼來源:ReaderJmxTest.java

示例8: t1testClientNetworkStandardAttributes

import javax.management.remote.JMXConnector; //導入依賴的package包/類
/**
 * read standard attributes at first!
 * @throws IOException ioe
 */
@Test
public void t1testClientNetworkStandardAttributes() throws IOException {
    //connect to server
    final JMXConnector connection = JmxConnectionHelper.buildJmxMPConnector(JMXSERVERIP,clientObj.getConnectorSystemPort());
    MBeanServerConnection mbs = JmxServerHelper.getMBeanServer(connection);
    Assert.assertNotSame(0,mbs.getMBeanCount());
    ObjectName network = JmxServerHelper.findObjectName(mbs,"de.b4sh.byter","Network");
    Assert.assertNotNull(network);
    //assert the attributes
    final boolean executorStatus = JmxClientNetworkHelper.getExecutorServiceStatus(mbs,network);
    Assert.assertEquals(false,executorStatus);
    final int networkBufferSize = JmxClientNetworkHelper.getNetworkBufferSize(mbs,network);
    Assert.assertEquals(8192,networkBufferSize);
    final String hostaddress = JmxClientNetworkHelper.getServerHostAddress(mbs,network);
    Assert.assertEquals("localhost",hostaddress);
    final int hostport = JmxClientNetworkHelper.getServerHostPort(mbs,network);
    Assert.assertEquals(0,hostport);
    final int targetPregenChunkSize = JmxClientNetworkHelper.getTargetPregenChunkSize(mbs,network);
    Assert.assertEquals(8192,targetPregenChunkSize);
    final long transmitTarget = JmxClientNetworkHelper.getTransmitTarget(mbs,network);
    Assert.assertEquals(8192,transmitTarget);
}
 
開發者ID:deB4SH,項目名稱:Byter,代碼行數:27,代碼來源:JmxClientNetworkTest.java

示例9: createJMXConnection

import javax.management.remote.JMXConnector; //導入依賴的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:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:25,代碼來源:JMXAccessorTask.java

示例10: createJMXConnection

import javax.management.remote.JMXConnector; //導入依賴的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:how2j,項目名稱:lazycat,代碼行數:22,代碼來源:JMXAccessorTask.java

示例11: connect

import javax.management.remote.JMXConnector; //導入依賴的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

示例12: tryConnect

import javax.management.remote.JMXConnector; //導入依賴的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

示例13: main

import javax.management.remote.JMXConnector; //導入依賴的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

示例14: testRoutine

import javax.management.remote.JMXConnector; //導入依賴的package包/類
@Test
public void testRoutine() throws IOException {
    //connect to server
    final JMXConnector connection = JmxConnectionHelper.buildJmxMPConnector(JMXSERVERIP,clientObj.getConnectorSystemPort());
    MBeanServerConnection mbs = JmxServerHelper.getMBeanServer(connection);
    Assert.assertNotSame(0,mbs.getMBeanCount());
    ObjectName disc = JmxServerHelper.findObjectName(mbs,"de.b4sh.byter","Disc");
    Assert.assertNotNull(disc);
    //set up env.
    JmxClientDiscHelper.setByteTarget(mbs,disc, (long) (10* TransformValues.MEGABYTE));
    JmxClientDiscHelper.setChunkSize(mbs,disc,64000);
    JmxClientDiscHelper.setFileName(mbs,disc, StringGenerator.nextRandomString(5));
    JmxClientDiscHelper.setOutputPath(mbs,disc,testSpaceDir);
    JmxClientDiscHelper.setWriterBufferSize(mbs,disc,64000);
    JmxClientDiscHelper.setWriterImplementation(mbs,disc, WriterType.BufferedWriter.getKey());
    //start runtime
    JmxClientDiscHelper.invokeDiscTest(mbs,disc);
}
 
開發者ID:deB4SH,項目名稱:Byter,代碼行數:19,代碼來源:JmxClientDiscTest.java

示例15: doTest

import javax.management.remote.JMXConnector; //導入依賴的package包/類
private void doTest(JMXConnector connector) throws IOException,
MalformedObjectNameException, ReflectionException,
InstanceAlreadyExistsException, MBeanRegistrationException,
MBeanException, NotCompliantMBeanException, InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException {
    MBeanServerConnection  mbsc = connector.getMBeanServerConnection();


    ObjectName objName = new ObjectName("com.redhat.test.jmx:type=NameMBean");
    System.out.println("DEBUG: Calling createMBean");
    mbsc.createMBean(Name.class.getName(), objName);

    System.out.println("DEBUG: Calling setAttributes");
    AttributeList attList = new AttributeList();
    attList.add(new Attribute("FirstName", ANY_NAME));
    attList.add(new Attribute("LastName", ANY_NAME));
    mbsc.setAttributes(objName, attList);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:RMIConnectorLogAttributesTest.java


注:本文中的javax.management.remote.JMXConnector類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。