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