Search in sources :

Example 11 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project ACS by ACS-Community.

the class GCJMXClient method connect.

public void connect() throws Exception {
    // get the connector address
    String connectorAddress = _vm.getAgentProperties().getProperty(LOCAL_CONNECTOR_ADDRESS);
    // no connector address, so we start the JMX agent
    if (connectorAddress == null) {
        String agent = _vm.getSystemProperties().getProperty("java.home") + File.separator + "lib" + File.separator + "management-agent.jar";
        _vm.loadAgent(agent);
        // agent is started, get the connector address
        connectorAddress = _vm.getAgentProperties().getProperty(LOCAL_CONNECTOR_ADDRESS);
        if (connectorAddress == null) {
            System.err.println("Cannot connect :(");
            System.exit(1);
        }
    }
    JMXServiceURL remoteURL = new JMXServiceURL(connectorAddress);
    JMXConnector connector = null;
    try {
        connector = JMXConnectorFactory.connect(remoteURL);
    } catch (IOException e) {
        System.err.println("Can't connect to the remote URL");
        System.exit(-1);
    }
    try {
        _remote = connector.getMBeanServerConnection();
    } catch (IOException e) {
        System.err.println("Can't get a connection to the remote MBeanServer");
        System.exit(-1);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException)

Example 12 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project ACS by ACS-Community.

the class RemoteThreadsClient method getServiceURL.

private void getServiceURL(InetAddress host, int port) throws MalformedURLException {
    String hostName = host.getHostName();
    String connectorAddress = "service:jmx:rmi:///jndi/rmi://" + hostName + ":" + port + "/jmxrmi";
    remoteURL = new JMXServiceURL(connectorAddress);
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL)

Example 13 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project ats-framework by Axway.

the class SystemOperations method getJvmMbeans.

/**
     * @param host the address of the host machine
     * @param jmxPort the jmx port
     * 
     * @return all MBeans with their attributes and type
     * @throws SystemOperationException
     */
@PublicAtsApi
public String getJvmMbeans(String host, String jmxPort) {
    JMXConnector jmxCon = null;
    try {
        // Connect to JMXConnector
        JMXServiceURL serviceUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + jmxPort + "/jmxrmi");
        jmxCon = JMXConnectorFactory.newJMXConnector(serviceUrl, null);
        jmxCon.connect();
        // Access the MBean
        MBeanServerConnection con = jmxCon.getMBeanServerConnection();
        Set<ObjectName> queryResults = con.queryNames(null, null);
        StringBuilder results = new StringBuilder();
        for (ObjectName theName : queryResults) {
            results.append("\n---");
            results.append("\nMBean name: " + theName.getCanonicalName());
            MBeanAttributeInfo[] attributes = con.getMBeanInfo(theName).getAttributes();
            for (MBeanAttributeInfo attribute : attributes) {
                if (attribute.getType() != null) {
                    if (!"javax.management.openmbean.CompositeData".equals(attribute.getType())) {
                        if ("java.lang.Long".equals(attribute.getType()) || "java.lang.Integer".equals(attribute.getType()) || "int".equals(attribute.getType()) || "long".equals(attribute.getType()))
                            results.append("\r   " + attribute.getName() + " | " + attribute.getType());
                    } else {
                        results.append("\r   " + attribute.getName() + " | " + attribute.getType());
                        CompositeData comdata = (CompositeData) con.getAttribute(theName, attribute.getName());
                        if (comdata != null) {
                            for (String key : comdata.getCompositeType().keySet()) {
                                Object value = comdata.get(key);
                                if (value instanceof Integer || value instanceof Double || value instanceof Long)
                                    results.append("\r      " + key + " | " + value.getClass());
                            }
                        }
                    }
                }
            }
        }
        return results.toString();
    } catch (Exception e) {
        throw new SystemOperationException("MBeans with their attributes cannot be get.", e);
    } finally {
        if (jmxCon != null)
            try {
                jmxCon.close();
            } catch (IOException e) {
                log.error("JMX connection was not closed!");
            }
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) SystemOperationException(com.axway.ats.common.system.SystemOperationException) CompositeData(javax.management.openmbean.CompositeData) IOException(java.io.IOException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) IOException(java.io.IOException) SystemOperationException(com.axway.ats.common.system.SystemOperationException) ObjectName(javax.management.ObjectName) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 14 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project Activiti by Activiti.

the class DeploymentsJMXClientTest method testDeploymentsJmxClient.

@SuppressWarnings("unchecked")
@Test
public void testDeploymentsJmxClient() throws IOException, InterruptedException, MalformedObjectNameException, AttributeNotFoundException, MBeanException, ReflectionException, InstanceNotFoundException, IntrospectionException {
    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");
    ProcessEngine processEngine = processEngineConfig.buildProcessEngine();
    // wait for jmx server to come up
    Thread.sleep(500);
    JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
    ObjectName deploymentsBeanName = new ObjectName("org.activiti.jmx.Mbeans:type=Deployments");
    Thread.sleep(500);
    // no process deployed yet
    List<List<String>> deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
    assertEquals(0, deployments.size());
    // deploy process remotely
    URL fileName = Thread.currentThread().getContextClassLoader().getResource("org/activiti/management/jmx/trivialProcess.bpmn");
    mbsc.invoke(deploymentsBeanName, "deployProcessDefinition", new String[] { "trivialProcess.bpmn", fileName.getFile() }, new String[] { String.class.getName(), String.class.getName() });
    // one process is there now, test remote deployments
    deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
    assertNotNull(deployments);
    assertEquals(1, deployments.size());
    assertEquals(3, deployments.get(0).size());
    String firstDeploymentId = deployments.get(0).get(0);
    // test remote process definition
    List<List<String>> pdList = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "ProcessDefinitions");
    assertNotNull(pdList);
    assertEquals(1, pdList.size());
    assertEquals(5, pdList.get(0).size());
    assertNotNull(pdList.get(0).get(0));
    assertEquals("My process", pdList.get(0).get(1));
    // version
    assertEquals("1", pdList.get(0).get(2));
    // not suspended
    assertEquals("false", pdList.get(0).get(3));
    assertEquals("This process to test JMX", pdList.get(0).get(4));
    // redeploy the same process
    mbsc.invoke(deploymentsBeanName, "deployProcessDefinition", new String[] { "trivialProcess.bpmn", fileName.getFile() }, new String[] { String.class.getName(), String.class.getName() });
    // now there should be two deployments
    deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
    assertNotNull(deployments);
    assertEquals(2, deployments.size());
    assertEquals(3, deployments.get(0).size());
    assertEquals(3, deployments.get(1).size());
    // there should be two process definitions, one with version equals to two
    pdList = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "ProcessDefinitions");
    assertNotNull(pdList);
    assertEquals(2, pdList.size());
    assertEquals(5, pdList.get(0).size());
    assertEquals(5, pdList.get(1).size());
    // check there is one with version= = 1 and another one with version == 2, other attributed are the same
    String pidV2 = null;
    String pidV1 = null;
    if (pdList.get(0).get(2).equals("1") && pdList.get(1).get(2).equals("2")) {
        pidV2 = pdList.get(1).get(0);
        pidV1 = pdList.get(0).get(0);
    } else if (pdList.get(1).get(2).equals("1") && pdList.get(0).get(2).equals("2")) {
        pidV2 = pdList.get(0).get(0);
        pidV1 = pdList.get(1).get(0);
    } else
        fail("there should one process definition with version == 1 and another one with version == 2. It is not the case");
    assertNotNull(pdList.get(0).get(0));
    assertNotNull(pdList.get(1).get(0));
    assertEquals("My process", pdList.get(0).get(1));
    assertEquals("My process", pdList.get(1).get(1));
    // not suspended
    assertEquals("false", pdList.get(0).get(3));
    // not suspended
    assertEquals("false", pdList.get(1).get(3));
    assertEquals("This process to test JMX", pdList.get(0).get(4));
    assertEquals("This process to test JMX", pdList.get(1).get(4));
    //suspend the one with version == 2    
    mbsc.invoke(deploymentsBeanName, "suspendProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
    RepositoryService repositoryService = processEngine.getRepositoryService();
    // test if it is realy suspended and not the other one
    assertTrue(repositoryService.getProcessDefinition(pidV2).isSuspended());
    assertFalse(repositoryService.getProcessDefinition(pidV1).isSuspended());
    // test if it is reported as suspended and not the other one
    List<String> pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
    assertNotNull(pd);
    assertEquals(5, pd.size());
    assertEquals("true", pd.get(3));
    pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV1 }, new String[] { String.class.getName() });
    assertNotNull(pd);
    assertEquals(5, pd.size());
    assertEquals("false", pd.get(3));
    // now reactivate the same suspended process 
    mbsc.invoke(deploymentsBeanName, "activatedProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
    // test if both processes are active again
    assertFalse(repositoryService.getProcessDefinition(pidV2).isSuspended());
    assertFalse(repositoryService.getProcessDefinition(pidV1).isSuspended());
    // test if they are properly reported as activated
    pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV2 }, new String[] { String.class.getName() });
    assertNotNull(pd);
    assertEquals(5, pd.size());
    assertEquals("false", pd.get(3));
    pd = (List<String>) mbsc.invoke(deploymentsBeanName, "getProcessDefinitionById", new String[] { pidV1 }, new String[] { String.class.getName() });
    assertNotNull(pd);
    assertEquals(5, pd.size());
    assertEquals("false", pd.get(3));
    // now undeploy the one with version == 1
    mbsc.invoke(deploymentsBeanName, "deleteDeployment", new String[] { firstDeploymentId }, new String[] { String.class.getName() });
    // now there should be only one deployment and only one process definition with version 2, first check it with API
    assertEquals(1, repositoryService.createDeploymentQuery().count());
    assertTrue(!repositoryService.createDeploymentQuery().singleResult().getId().equals(firstDeploymentId));
    // check if it is also affected in returned results.
    deployments = (List<List<String>>) mbsc.getAttribute(deploymentsBeanName, "Deployments");
    assertNotNull(deployments);
    assertEquals(1, deployments.size());
    assertEquals(3, deployments.get(0).size());
    assertTrue(!deployments.get(0).get(0).equals(firstDeploymentId));
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) JMXConnector(javax.management.remote.JMXConnector) List(java.util.List) MBeanServerConnection(javax.management.MBeanServerConnection) URL(java.net.URL) JMXServiceURL(javax.management.remote.JMXServiceURL) ProcessEngine(org.activiti.engine.ProcessEngine) ObjectName(javax.management.ObjectName) RepositoryService(org.activiti.engine.RepositoryService) Test(org.junit.Test)

Example 15 with JMXServiceURL

use of javax.management.remote.JMXServiceURL in project opennms by OpenNMS.

the class Jsr160DetectorTest method setUp.

@Before
public void setUp() throws IOException {
    MockLogAppender.setupLogging();
    m_detector = m_detectorFactory.createDetector();
    assertNotNull(m_detector);
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9123/server");
    m_connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, m_beanServer);
    m_connectorServer.start();
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) Before(org.junit.Before)

Aggregations

JMXServiceURL (javax.management.remote.JMXServiceURL)273 JMXConnector (javax.management.remote.JMXConnector)146 MBeanServerConnection (javax.management.MBeanServerConnection)107 ObjectName (javax.management.ObjectName)90 IOException (java.io.IOException)75 HashMap (java.util.HashMap)75 MBeanServer (javax.management.MBeanServer)70 JMXConnectorServer (javax.management.remote.JMXConnectorServer)64 MalformedURLException (java.net.MalformedURLException)45 RemoteException (java.rmi.RemoteException)22 Test (org.junit.Test)20 Map (java.util.Map)16 UnknownHostException (java.net.UnknownHostException)14 Notification (javax.management.Notification)14 NotificationListener (javax.management.NotificationListener)14 Properties (java.util.Properties)13 MalformedObjectNameException (javax.management.MalformedObjectNameException)13 LocateRegistry (java.rmi.registry.LocateRegistry)12 Registry (java.rmi.registry.Registry)12 ArrayList (java.util.ArrayList)11