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;
}
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;
}
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());
}
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;
}
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());
}
Aggregations