Search in sources :

Example 86 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project wildfly by wildfly.

the class DependsTestCase method testMBean.

@Test
@SuppressWarnings("unchecked")
public void testMBean() throws Exception {
    final MBeanServerConnection mbeanServer = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL(), DefaultConfiguration.credentials()).getMBeanServerConnection();
    final ObjectName a1ObjectName = new ObjectName("test:service=A1");
    final ObjectName aObjectName = (ObjectName) mbeanServer.getAttribute(a1ObjectName, "ObjectName");
    Assert.assertTrue(aObjectName.equals(new ObjectName("test:service=A")));
    final ObjectName bObjectName = new ObjectName("test:service=B");
    final List<ObjectName> objectNames = (List<ObjectName>) mbeanServer.getAttribute(bObjectName, "ObjectNames");
    Assert.assertTrue(objectNames.contains(new ObjectName("test:service=A")));
    Assert.assertTrue(objectNames.contains(new ObjectName("test:service=A1")));
}
Also used : List(java.util.List) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 87 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project wildfly by wildfly.

the class SarResourceInjectionTestCase method testMBean.

@Test
public void testMBean() throws Exception {
    final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL(), DefaultConfiguration.credentials());
    try {
        final MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
        final ObjectName objectName = new ObjectName("jboss:name=X");
        Assert.assertTrue((Boolean) mbeanServer.invoke(objectName, "resourcesInjected", null, null));
    } finally {
        IoUtils.safeClose(connector);
    }
}
Also used : JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 88 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project wildfly by wildfly.

the class SarValueFactoryInjectionTestCase method testMBean.

@Test
public void testMBean() throws Exception {
    final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL());
    try {
        final MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
        final ObjectName objectName = new ObjectName("jboss:name=TargetBean");
        Assert.assertEquals("Injection using value-factory without method arguments failed", 2, ((Integer) mbeanServer.getAttribute(objectName, "SourceCount")).intValue());
        Assert.assertEquals("Injection using value-factory with method argument failed", 4, ((Integer) mbeanServer.getAttribute(objectName, "CountWithArgument")).intValue());
    } finally {
        IoUtils.safeClose(connector);
    }
}
Also used : JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 89 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project wildfly by wildfly.

the class SarTestCase method testMBean.

@Test
public void testMBean() throws Exception {
    final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL());
    try {
        MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
        ObjectName objectName = new ObjectName("jboss:name=test,type=config");
        mbeanServer.getAttribute(objectName, "IntervalSeconds");
        mbeanServer.setAttribute(objectName, new Attribute("IntervalSeconds", 2));
    } finally {
        IoUtils.safeClose(connector);
    }
}
Also used : Attribute(javax.management.Attribute) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 90 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project Activiti by Activiti.

the class JobExecutorJMXClientTest method testJobExecutorJMXClient.

@Test
public void testJobExecutorJMXClient() throws InterruptedException, IOException, MalformedObjectNameException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException {
    String hostName = Utils.getHostName();
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + hostName + ":10111/jndi/rmi://" + hostName + ":1099/jmxrmi/activiti");
    ProcessEngineConfiguration processEngineConfig = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
    processEngineConfig.buildProcessEngine();
    // wait for jmx server to come up
    Thread.sleep(500);
    JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
    ObjectName jobExecutorBeanName = new ObjectName("org.activiti.jmx.Mbeans:type=JobExecutor");
    processEngineConfig.getJobExecutor().shutdown();
    // first check that job executor is not activated and correctly reported as being inactive
    assertFalse(processEngineConfig.isJobExecutorActivate());
    assertFalse((Boolean) mbsc.getAttribute(jobExecutorBeanName, "JobExecutorActivated"));
    // now activate it remotely
    mbsc.invoke(jobExecutorBeanName, "setJobExecutorActivate", new Boolean[] { true }, new String[] { Boolean.class.getName() });
    // check if it has the effect and correctly reported
    //    assertTrue(processEngineConfig.getJobExecutor().isActive());
    assertTrue((Boolean) mbsc.getAttribute(jobExecutorBeanName, "JobExecutorActivated"));
    //agani disable and check it    
    mbsc.invoke(jobExecutorBeanName, "setJobExecutorActivate", new Boolean[] { false }, new String[] { Boolean.class.getName() });
    // check if it has the effect and correctly reported
    assertFalse(processEngineConfig.isJobExecutorActivate());
    assertFalse((Boolean) mbsc.getAttribute(jobExecutorBeanName, "JobExecutorActivated"));
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

MBeanServerConnection (javax.management.MBeanServerConnection)125 JMXConnector (javax.management.remote.JMXConnector)84 ObjectName (javax.management.ObjectName)73 JMXServiceURL (javax.management.remote.JMXServiceURL)59 JMXConnectorServer (javax.management.remote.JMXConnectorServer)38 Test (org.junit.Test)35 IOException (java.io.IOException)31 MBeanServer (javax.management.MBeanServer)28 HashMap (java.util.HashMap)23 Attribute (javax.management.Attribute)15 NotificationListener (javax.management.NotificationListener)13 MalformedURLException (java.net.MalformedURLException)12 ArrayList (java.util.ArrayList)12 Notification (javax.management.Notification)12 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 Map (java.util.Map)10 List (java.util.List)8 RemoteException (java.rmi.RemoteException)7 LocateRegistry (java.rmi.registry.LocateRegistry)7 Registry (java.rmi.registry.Registry)7