Search in sources :

Example 16 with MBeanServer

use of javax.management.MBeanServer in project neo4j by neo4j.

the class Dbinfo method exec.

@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws Exception {
    Kernel kernel = getKernel();
    boolean list = parser.options().containsKey("l"), get = parser.options().containsKey("g");
    if ((list && get) || (!list && !get)) {
        StringBuilder usage = new StringBuilder();
        getUsage(usage);
        usage.append(".\n");
        out.print(usage.toString());
        return Continuation.INPUT_COMPLETE;
    }
    MBeanServer mbeans = getPlatformMBeanServer();
    String bean = null;
    String[] attributes = null;
    if (list) {
        bean = parser.options().get("l");
    } else if (get) {
        bean = parser.options().get("g");
        attributes = parser.arguments().toArray(new String[parser.arguments().size()]);
    }
    if (// list beans
    bean == null) {
        StringBuilder result = new StringBuilder();
        availableBeans(mbeans, kernel, result);
        out.print(result.toString());
        return Continuation.INPUT_COMPLETE;
    }
    ObjectName mbean;
    {
        mbean = kernel.getMBeanQuery();
        Hashtable<String, String> properties = new Hashtable<String, String>(mbean.getKeyPropertyList());
        properties.put("name", bean);
        try {
            Iterator<ObjectName> names = mbeans.queryNames(new ObjectName(mbean.getDomain(), properties), null).iterator();
            if (names.hasNext()) {
                mbean = names.next();
                if (names.hasNext()) {
                    mbean = null;
                }
            } else {
                mbean = null;
            }
        } catch (Exception e) {
            mbean = null;
        }
    }
    if (mbean == null) {
        throw new ShellException("No such management bean \"" + bean + "\".");
    }
    if (// list attributes
    attributes == null) {
        for (MBeanAttributeInfo attr : mbeans.getMBeanInfo(mbean).getAttributes()) {
            out.println(attr.getName() + " - " + attr.getDescription());
        }
    } else {
        if (// specify all attributes
        attributes.length == 0) {
            MBeanAttributeInfo[] allAttributes = mbeans.getMBeanInfo(mbean).getAttributes();
            attributes = new String[allAttributes.length];
            for (int i = 0; i < allAttributes.length; i++) {
                attributes[i] = allAttributes[i].getName();
            }
        }
        JSONObject json = new JSONObject();
        for (Object value : mbeans.getAttributes(mbean, attributes)) {
            printAttribute(json, value);
        }
        out.println(json.toString(2));
    }
    return Continuation.INPUT_COMPLETE;
}
Also used : Hashtable(java.util.Hashtable) ShellException(org.neo4j.shell.ShellException) JSONException(org.neo4j.shell.util.json.JSONException) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) JSONObject(org.neo4j.shell.util.json.JSONObject) Iterator(java.util.Iterator) JSONObject(org.neo4j.shell.util.json.JSONObject) Kernel(org.neo4j.jmx.Kernel) ManagementFactory.getPlatformMBeanServer(java.lang.management.ManagementFactory.getPlatformMBeanServer) MBeanServer(javax.management.MBeanServer)

Example 17 with MBeanServer

use of javax.management.MBeanServer in project neo4j by neo4j.

the class JMXManagementModule method start.

@Override
public void start() {
    try {
        ServerManagement serverManagement = new ServerManagement(server);
        MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
        beanServer.registerMBean(serverManagement, createObjectName());
    } catch (Exception e) {
        throw new RuntimeException("Unable to initialize jmx management, see nested exception.", e);
    }
}
Also used : ServerManagement(org.neo4j.server.enterprise.jmx.ServerManagement) MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServer(javax.management.MBeanServer)

Example 18 with MBeanServer

use of javax.management.MBeanServer in project neo4j by neo4j.

the class JMXManagementModule method stop.

@Override
public void stop() {
    try {
        MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
        beanServer.unregisterMBean(createObjectName());
    } catch (InstanceNotFoundException e) {
    // ok
    } catch (Exception e) {
        throw new RuntimeException("Unable to shut down jmx management, see nested exception.", e);
    }
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServer(javax.management.MBeanServer)

Example 19 with MBeanServer

use of javax.management.MBeanServer in project neo4j by neo4j.

the class JmxQueryProcedureTest method shouldConvertAllStandardBeansWithoutError.

@Test
public void shouldConvertAllStandardBeansWithoutError() throws Throwable {
    // given
    MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
    JmxQueryProcedure procedure = new JmxQueryProcedure(ProcedureSignature.procedureName("bob"), jmxServer);
    // when
    RawIterator<Object[], ProcedureException> result = procedure.apply(null, new Object[] { "*:*" });
    // then we verify that we respond with the expected number of beans without error
    //      .. we don't assert more than this, this is more of a smoke test to ensure
    //      that independent of platform, we never throw exceptions even when converting every
    //      single MBean into Neo4j types, and we always get the correct number of MBeans out.
    assertThat(asList(result).size(), equalTo(jmxServer.getMBeanCount()));
}
Also used : ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 20 with MBeanServer

use of javax.management.MBeanServer in project neo4j by neo4j.

the class HotspotManagementSupport method createServer.

private JMXConnectorServer createServer(int port, boolean useSSL, Log log) {
    MBeanServer server = getMBeanServer();
    final JMXServiceURL url;
    try {
        url = new JMXServiceURL("rmi", null, port);
    } catch (MalformedURLException e) {
        log.warn("Failed to start JMX Server", e);
        return null;
    }
    Map<String, Object> env = new HashMap<>();
    if (useSSL) {
        env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, new SslRMIClientSocketFactory());
        env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, new SslRMIServerSocketFactory());
    }
    try {
        return JMXConnectorServerFactory.newJMXConnectorServer(url, env, server);
    } catch (IOException e) {
        log.warn("Failed to start JMX Server", e);
        return null;
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) SslRMIClientSocketFactory(javax.rmi.ssl.SslRMIClientSocketFactory) MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) SslRMIServerSocketFactory(javax.rmi.ssl.SslRMIServerSocketFactory) IOException(java.io.IOException) MBeanServer(javax.management.MBeanServer)

Aggregations

MBeanServer (javax.management.MBeanServer)1218 ObjectName (javax.management.ObjectName)939 Test (org.junit.Test)214 MalformedObjectNameException (javax.management.MalformedObjectNameException)123 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)94 InstanceNotFoundException (javax.management.InstanceNotFoundException)87 IOException (java.io.IOException)82 JMXServiceURL (javax.management.remote.JMXServiceURL)70 Attribute (javax.management.Attribute)66 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)65 HashMap (java.util.HashMap)63 MBeanRegistrationException (javax.management.MBeanRegistrationException)56 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)54 TabularData (javax.management.openmbean.TabularData)51 ArrayList (java.util.ArrayList)47 JMXConnectorServer (javax.management.remote.JMXConnectorServer)47 JMXConnector (javax.management.remote.JMXConnector)40 Map (java.util.Map)38 JMException (javax.management.JMException)38 Test (org.junit.jupiter.api.Test)36