use of javax.management.remote.JMXServiceURL in project flink by apache.
the class JMXServer method internalStart.
private void internalStart(int port) throws IOException {
rmiServerReference.set(null);
// this allows clients to lookup the JMX service
rmiRegistry = new JmxRegistry(port, "jmxrmi", rmiServerReference);
String serviceUrl = "service:jmx:rmi://localhost:" + port + "/jndi/rmi://localhost:" + port + "/jmxrmi";
JMXServiceURL url;
try {
url = new JMXServiceURL(serviceUrl);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Malformed service url created " + serviceUrl, e);
}
final RMIJRMPServerImpl rmiServer = new RMIJRMPServerImpl(port, null, null, null);
connector = new RMIConnectorServer(url, null, rmiServer, ManagementFactory.getPlatformMBeanServer());
connector.start();
// we can't pass the created stub directly to the registry since this would form a cyclic
// dependency:
// - you can only start the connector after the registry was started
// - you can only create the stub after the connector was started
// - you can only start the registry after the stub was created
rmiServerReference.set(rmiServer.toStub());
}
use of javax.management.remote.JMXServiceURL in project flink by apache.
the class JMXServerTest method testJMXServiceRegisterMBean.
/**
* Verifies initialize, registered mBean and retrieval via attribute.
*/
@Test
public void testJMXServiceRegisterMBean() throws Exception {
TestObject testObject = new TestObject();
ObjectName testObjectName = new ObjectName("org.apache.flink.management", "key", "value");
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
try {
Optional<JMXServer> server = JMXService.getInstance();
assertTrue(server.isPresent());
mBeanServer.registerMBean(testObject, testObjectName);
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost:" + server.get().getPort() + "/jndi/rmi://localhost:" + server.get().getPort() + "/jmxrmi");
JMXConnector jmxConn = JMXConnectorFactory.connect(url);
MBeanServerConnection mbeanConnConn = jmxConn.getMBeanServerConnection();
assertEquals(1, mbeanConnConn.getAttribute(testObjectName, "Foo"));
mBeanServer.unregisterMBean(testObjectName);
try {
mbeanConnConn.getAttribute(testObjectName, "Foo");
} catch (Exception e) {
// expected for unregistered objects.
assertTrue(e instanceof InstanceNotFoundException);
}
} finally {
JMXService.stopInstance();
}
}
use of javax.management.remote.JMXServiceURL in project flink by apache.
the class JMXReporterTest method testJMXAvailability.
/**
* Verifies that we can connect to multiple JMXReporters running on the same machine.
*/
@Test
void testJMXAvailability() throws Exception {
final JMXReporter rep1 = new JMXReporter("9040-9055");
final JMXReporter rep2 = new JMXReporter("9040-9055");
Gauge<Integer> g1 = () -> 1;
Gauge<Integer> g2 = () -> 2;
rep1.notifyOfAddedMetric(g1, "rep1", metricGroup);
rep2.notifyOfAddedMetric(g2, "rep2", metricGroup);
ObjectName objectName1 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep1", JMXReporter.generateJmxTable(metricGroup.getAllVariables()));
ObjectName objectName2 = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager.rep2", JMXReporter.generateJmxTable(metricGroup.getAllVariables()));
JMXServiceURL url1 = new JMXServiceURL("service:jmx:rmi://localhost:" + rep1.getPort().get() + "/jndi/rmi://localhost:" + rep1.getPort().get() + "/jmxrmi");
JMXConnector jmxCon1 = JMXConnectorFactory.connect(url1);
MBeanServerConnection mCon1 = jmxCon1.getMBeanServerConnection();
assertThat(mCon1.getAttribute(objectName1, "Value")).isEqualTo(1);
assertThat(mCon1.getAttribute(objectName2, "Value")).isEqualTo(2);
jmxCon1.close();
JMXServiceURL url2 = new JMXServiceURL("service:jmx:rmi://localhost:" + rep2.getPort().get() + "/jndi/rmi://localhost:" + rep2.getPort().get() + "/jmxrmi");
JMXConnector jmxCon2 = JMXConnectorFactory.connect(url2);
MBeanServerConnection mCon2 = jmxCon2.getMBeanServerConnection();
assertThat(mCon2.getAttribute(objectName1, "Value")).isEqualTo(1);
assertThat(mCon2.getAttribute(objectName2, "Value")).isEqualTo(2);
// JMX Server URL should be identical since we made it static.
assertThat(url2).isEqualTo(url1);
rep1.notifyOfRemovedMetric(g1, "rep1", null);
rep1.notifyOfRemovedMetric(g2, "rep2", null);
jmxCon2.close();
rep1.close();
rep2.close();
}
use of javax.management.remote.JMXServiceURL in project cassandra-mesos-deprecated by mesosphere.
the class ProdJmxConnect method connect.
private void connect() throws IOException {
lock.lock();
try {
if (jmxc != null) {
return;
}
final JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port));
final Map<String, Object> env = new HashMap<>();
if (username != null) {
final String[] creds = { username, password };
env.put(JMXConnector.CREDENTIALS, creds);
}
jmxc = JMXConnectorFactory.connect(jmxUrl, env);
mbeanServerConn = jmxc.getMBeanServerConnection();
} finally {
lock.unlock();
}
}
use of javax.management.remote.JMXServiceURL in project voldemort by voldemort.
the class AbstractFailureDetectorTest method assertJmxEquals.
protected void assertJmxEquals(String attributeName, Object attributeValue) throws Exception {
JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL("service:jmx:rmi://"), null, ManagementFactory.getPlatformMBeanServer());
cs.start();
JMXConnector cc = null;
try {
cc = JMXConnectorFactory.connect(cs.getAddress());
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
ObjectName objectName = JmxUtils.createObjectName(JmxUtils.getPackageName(failureDetector.getClass()), failureDetector.getClass().getSimpleName());
Object availableNodes = mbsc.getAttribute(objectName, attributeName);
assertEquals(attributeValue, availableNodes);
} finally {
if (cc != null)
cc.close();
cs.stop();
}
}
Aggregations