本文整理汇总了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());
}
示例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 ///---");
}
示例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);
}
}
示例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;
}
示例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 );
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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");
}
}
示例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();
}
}
示例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);
}
示例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);
}