use of javax.management.ObjectInstance in project jdk8u_jdk by JetBrains.
the class ScanManager method createOtherConfigurationMBean.
// See ScanManagerMXBean
public ScanDirConfigMXBean createOtherConfigurationMBean(String name, String filename) throws JMException {
final ScanDirConfig profile = new ScanDirConfig(filename);
final ObjectName profName = makeScanDirConfigName(name);
final ObjectInstance moi = mbeanServer.registerMBean(profile, profName);
final ScanDirConfigMXBean proxy = JMX.newMXBeanProxy(mbeanServer, profName, ScanDirConfigMXBean.class, true);
configmap.put(moi.getObjectName(), proxy);
return proxy;
}
use of javax.management.ObjectInstance in project jdk8u_jdk by JetBrains.
the class RMINotifTest method main.
public static void main(String[] args) {
try {
// create a rmi registry
Registry reg = null;
int port = 6666;
final Random r = new Random();
while (port++ < 7000) {
try {
reg = LocateRegistry.createRegistry(++port);
System.out.println("Creation of rmi registry succeeded. Running on port " + port);
break;
} catch (RemoteException re) {
// no problem
}
}
if (reg == null) {
System.out.println("Failed to create a RMI registry, " + "the ports from 6666 to 6999 are all occupied.");
System.exit(1);
}
// create a MBeanServer
MBeanServer server = MBeanServerFactory.createMBeanServer();
// create a notif emitter mbean
ObjectName mbean = new ObjectName("Default:name=NotificationEmitter");
server.registerMBean(new NotificationEmitter(), mbean);
// create a rmi server
JMXServiceURL url = new JMXServiceURL("rmi", null, port, "/jndi/rmi://:" + port + "/server" + port);
System.out.println("RMIConnectorServer address " + url);
JMXConnectorServer sServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, null);
ObjectInstance ss = server.registerMBean(sServer, new ObjectName("Default:name=RmiConnectorServer"));
sServer.start();
// create a rmi client
JMXConnector rmiConnection = JMXConnectorFactory.newJMXConnector(url, null);
rmiConnection.connect(null);
MBeanServerConnection client = rmiConnection.getMBeanServerConnection();
// add listener at the client side
client.addNotificationListener(mbean, listener, null, null);
//ask to send notifs
Object[] params = new Object[1];
String[] signatures = new String[1];
params[0] = new Integer(nb);
signatures[0] = "java.lang.Integer";
client.invoke(mbean, "sendNotifications", params, signatures);
// waiting ...
synchronized (lock) {
if (receivedNotifs != nb) {
lock.wait(10000);
System.out.println(">>> Received notifications..." + receivedNotifs);
}
}
// check
if (receivedNotifs != nb) {
System.exit(1);
} else {
System.out.println("The client received all notifications.");
}
// remove listener
client.removeNotificationListener(mbean, listener);
// more test
NotificationFilterSupport filter = new NotificationFilterSupport();
Object o = new Object();
client.addNotificationListener(mbean, listener, filter, o);
client.removeNotificationListener(mbean, listener, filter, o);
sServer.stop();
// // clean
// client.unregisterMBean(mbean);
// rmiConnection.close();
// Thread.sleep(2000);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
use of javax.management.ObjectInstance in project lucene-solr by apache.
the class SolrJmxReporterTest method testEnabled.
@Test
public void testEnabled() throws Exception {
String root1 = TestUtil.randomSimpleString(random(), 5, 10);
PluginInfo pluginInfo1 = createReporterPluginInfo(root1, true);
metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo1, coreMetricManager.getTag());
String root2 = TestUtil.randomSimpleString(random(), 5, 10);
assertFalse(root2.equals(root1));
PluginInfo pluginInfo2 = createReporterPluginInfo(root2, false);
metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo2, coreMetricManager.getTag());
Map<String, SolrMetricReporter> reporters = metricManager.getReporters(coreMetricManager.getRegistryName());
assertTrue(reporters.containsKey(pluginInfo1.name + "@" + coreMetricManager.getTag()));
assertTrue(reporters.containsKey(pluginInfo2.name + "@" + coreMetricManager.getTag()));
String scope = SolrMetricTestUtils.getRandomScope(random(), true);
SolrInfoBean.Category category = SolrMetricTestUtils.getRandomCategory(random(), true);
Map<String, Counter> metrics = SolrMetricTestUtils.getRandomMetrics(random(), true);
SolrMetricProducer producer = SolrMetricTestUtils.getProducerOf(metricManager, category, scope, metrics);
coreMetricManager.registerMetricProducer(scope, producer);
Set<ObjectInstance> objects = mBeanServer.queryMBeans(null, null);
assertEquals(metrics.size(), objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && root1.equals(o.getObjectName().getDomain())).count());
assertEquals(0, objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && root2.equals(o.getObjectName().getDomain())).count());
}
use of javax.management.ObjectInstance in project lucene-solr by apache.
the class SolrJmxReporterTest method testReloadCore.
@Test
public void testReloadCore() throws Exception {
Random random = random();
String scope = SolrMetricTestUtils.getRandomScope(random, true);
SolrInfoBean.Category category = SolrMetricTestUtils.getRandomCategory(random, true);
Map<String, Counter> metrics = SolrMetricTestUtils.getRandomMetrics(random, true);
SolrMetricProducer producer = SolrMetricTestUtils.getProducerOf(metricManager, category, scope, metrics);
coreMetricManager.registerMetricProducer(scope, producer);
Set<ObjectInstance> objects = mBeanServer.queryMBeans(null, null);
assertEquals(metrics.size(), objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && o.getObjectName().getDomain().equals(rootName)).count());
h.getCoreContainer().reload(h.getCore().getName());
PluginInfo pluginInfo = createReporterPluginInfo(rootName, true);
metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo, String.valueOf(coreMetricManager.getCore().hashCode()));
coreMetricManager.registerMetricProducer(scope, producer);
objects = mBeanServer.queryMBeans(null, null);
assertEquals(metrics.size(), objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && rootName.equals(o.getObjectName().getDomain())).count());
}
use of javax.management.ObjectInstance in project lucene-solr by apache.
the class TestJmxIntegration method testJmxRegistration.
@Test
public void testJmxRegistration() throws Exception {
assertTrue("No MBeans found in server", mbeanServer.getMBeanCount() > 0);
Set<ObjectInstance> objects = mbeanServer.queryMBeans(null, null);
assertFalse("No objects found in mbean server", objects.isEmpty());
int numDynamicMbeans = 0;
for (ObjectInstance o : objects) {
ObjectName name = o.getObjectName();
assertNotNull("Null name on: " + o.toString(), name);
MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(name);
if (name.getDomain().equals("solr")) {
numDynamicMbeans++;
MBeanAttributeInfo[] attrs = mbeanInfo.getAttributes();
if (name.getKeyProperty("name").equals("fetcher")) {
// no attributes without active replication
continue;
}
assertTrue("No Attributes found for mbean: " + o.getObjectName() + ", " + mbeanInfo, 0 < attrs.length);
for (MBeanAttributeInfo attr : attrs) {
// ensure every advertised attribute is gettable
try {
Object trash = mbeanServer.getAttribute(o.getObjectName(), attr.getName());
} catch (javax.management.AttributeNotFoundException e) {
throw new RuntimeException("Unable to featch attribute for " + o.getObjectName() + ": " + attr.getName(), e);
}
}
}
}
assertTrue("No MBeans found", 0 < numDynamicMbeans);
}
Aggregations