Search in sources :

Example 91 with ObjectInstance

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;
}
Also used : ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName)

Example 92 with ObjectInstance

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);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) ObjectInstance(javax.management.ObjectInstance) Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry) RemoteException(java.rmi.RemoteException) ObjectName(javax.management.ObjectName) JMXConnectorServer(javax.management.remote.JMXConnectorServer) Random(java.util.Random) JMXConnector(javax.management.remote.JMXConnector) NotificationFilterSupport(javax.management.NotificationFilterSupport) RemoteException(java.rmi.RemoteException) MBeanServerConnection(javax.management.MBeanServerConnection) MBeanServer(javax.management.MBeanServer)

Example 93 with ObjectInstance

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());
}
Also used : Counter(com.codahale.metrics.Counter) SolrInfoBean(org.apache.solr.core.SolrInfoBean) SolrMetricProducer(org.apache.solr.metrics.SolrMetricProducer) ObjectInstance(javax.management.ObjectInstance) PluginInfo(org.apache.solr.core.PluginInfo) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) Test(org.junit.Test)

Example 94 with ObjectInstance

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());
}
Also used : Counter(com.codahale.metrics.Counter) Random(java.util.Random) SolrInfoBean(org.apache.solr.core.SolrInfoBean) SolrMetricProducer(org.apache.solr.metrics.SolrMetricProducer) ObjectInstance(javax.management.ObjectInstance) PluginInfo(org.apache.solr.core.PluginInfo) Test(org.junit.Test)

Example 95 with ObjectInstance

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);
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanInfo(javax.management.MBeanInfo) ObjectInstance(javax.management.ObjectInstance) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

ObjectInstance (javax.management.ObjectInstance)172 ObjectName (javax.management.ObjectName)102 Test (org.junit.Test)38 MBeanServer (javax.management.MBeanServer)36 InstanceNotFoundException (javax.management.InstanceNotFoundException)28 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)16 MBeanInfo (javax.management.MBeanInfo)16 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)15 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)15 HashMap (java.util.HashMap)13 Attribute (javax.management.Attribute)13 HashSet (java.util.HashSet)12 JmxResultProcessor (com.googlecode.jmxtrans.model.JmxResultProcessor)11 Result (com.googlecode.jmxtrans.model.Result)11 Set (java.util.Set)11 ReflectionException (javax.management.ReflectionException)11 MalformedObjectNameException (javax.management.MalformedObjectNameException)10 Test (org.junit.jupiter.api.Test)10 MBeanServerConnection (javax.management.MBeanServerConnection)9