Search in sources :

Example 1 with Kernel

use of org.neo4j.jmx.Kernel in project neo4j by neo4j.

the class Dbinfo method getKernel.

private Kernel getKernel() throws ShellException {
    GraphDatabaseAPI graphDb = getServer().getDb();
    Kernel kernel = null;
    if (graphDb instanceof GraphDatabaseAPI) {
        try {
            kernel = graphDb.getDependencyResolver().resolveDependency(JmxKernelExtension.class).getSingleManagementBean(Kernel.class);
        } catch (Exception e) {
        // Ignore - the null check does the work
        }
    }
    if (kernel == null) {
        throw new ShellException(getName() + " is not available for this graph database.");
    }
    return kernel;
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Kernel(org.neo4j.jmx.Kernel) ShellException(org.neo4j.shell.ShellException) JSONException(org.neo4j.shell.util.json.JSONException) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException)

Example 2 with Kernel

use of org.neo4j.jmx.Kernel 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 3 with Kernel

use of org.neo4j.jmx.Kernel in project neo4j by neo4j.

the class ManagementBeansTest method canAccessKernelBean.

@Test
public void canAccessKernelBean() throws Exception {
    Kernel kernel = graphDb.getDependencyResolver().resolveDependency(JmxKernelExtension.class).getSingleManagementBean(Kernel.class);
    assertNotNull("kernel bean is null", kernel);
    assertNotNull("MBeanQuery of kernel bean is null", kernel.getMBeanQuery());
}
Also used : JmxKernelExtension(org.neo4j.jmx.impl.JmxKernelExtension) Kernel(org.neo4j.jmx.Kernel) Test(org.junit.Test)

Example 4 with Kernel

use of org.neo4j.jmx.Kernel in project graphdb by neo4j-attic.

the class Neo4jManager method allBeans.

@Override
public List<Object> allBeans() {
    List<Object> beans = super.allBeans();
    @SuppressWarnings("hiding") Kernel kernel = null;
    for (Object bean : beans) {
        if (bean instanceof Kernel) {
            kernel = (Kernel) bean;
        }
    }
    if (kernel != null)
        beans.remove(kernel);
    return beans;
}
Also used : Kernel(org.neo4j.jmx.Kernel)

Example 5 with Kernel

use of org.neo4j.jmx.Kernel in project graphdb by neo4j-attic.

the class ManagementBeansTest method canAccessKernelBean.

@Test
public void canAccessKernelBean() throws Exception {
    // START SNIPPET: getKernel
    Kernel kernel = graphDb.getManagementBean(Kernel.class);
    // END SNIPPET: getKernel
    assertNotNull("kernel bean is null", kernel);
    assertNotNull("MBeanQuery of kernel bean is null", kernel.getMBeanQuery());
}
Also used : Kernel(org.neo4j.jmx.Kernel) Test(org.junit.Test)

Aggregations

Kernel (org.neo4j.jmx.Kernel)7 ShellException (org.neo4j.shell.ShellException)3 ManagementFactory.getPlatformMBeanServer (java.lang.management.ManagementFactory.getPlatformMBeanServer)2 RemoteException (java.rmi.RemoteException)2 MBeanServer (javax.management.MBeanServer)2 Test (org.junit.Test)2 JSONException (org.neo4j.shell.util.json.JSONException)2 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 ObjectName (javax.management.ObjectName)1 JmxKernelExtension (org.neo4j.jmx.impl.JmxKernelExtension)1 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)1 JSONObject (org.neo4j.shell.util.json.JSONObject)1