use of javax.management.JMException in project alfresco-repository by Alfresco.
the class JmxDumpUtil method dumpConnection.
/**
* Dumps a local or remote MBeanServer's entire object tree for support purposes. Nested arrays and CompositeData
* objects in MBean attribute values are handled.
*
* @param connection
* the server connection (or server itself)
* @param out
* PrintWriter to write the output to
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void dumpConnection(MBeanServerConnection connection, PrintWriter out) throws IOException {
JmxDumpUtil.showStartBanner(out);
// Get all the object names
Set<ObjectName> objectNames = connection.queryNames(null, null);
// Sort the names (don't assume ObjectName implements Comparable in JDK 1.5)
Set<ObjectName> newObjectNames = new TreeSet<ObjectName>(new Comparator<ObjectName>() {
public int compare(ObjectName o1, ObjectName o2) {
return o1.toString().compareTo(o2.toString());
}
});
newObjectNames.addAll(objectNames);
objectNames = newObjectNames;
// Dump each MBean
for (ObjectName objectName : objectNames) {
try {
printMBeanInfo(connection, objectName, out);
} catch (JMException e) {
// Sometimes beans can disappear while we are examining them
}
}
}
use of javax.management.JMException in project alfresco-repository by Alfresco.
the class JmxDumpUtil method printMBeanInfo.
/**
* Dumps the details of a single MBean.
*
* @param connection
* the server connection (or server itself)
* @param objectName
* the object name
* @param out
* PrintWriter to write the output to
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws JMException
* Signals a JMX error
*/
private static void printMBeanInfo(MBeanServerConnection connection, ObjectName objectName, PrintWriter out) throws IOException, JMException {
Map<String, Object> attributes = new TreeMap<String, Object>();
MBeanInfo info = connection.getMBeanInfo(objectName);
attributes.put("** Object Name", objectName.toString());
attributes.put("** Object Type", info.getClassName());
for (MBeanAttributeInfo element : info.getAttributes()) {
Object value;
if (element.isReadable()) {
try {
value = connection.getAttribute(objectName, element.getName());
} catch (Exception e) {
value = JmxDumpUtil.PROTECTED_VALUE;
}
} else {
value = JmxDumpUtil.PROTECTED_VALUE;
}
attributes.put(element.getName(), value);
}
if (objectName.getCanonicalName().equals("Alfresco:Name=SystemProperties")) {
String osName = (String) attributes.get(OS_NAME);
if (osName != null && osName.toLowerCase().startsWith("linux")) {
attributes.put(OS_NAME, updateOSNameAttributeForLinux(osName));
}
}
if (objectName.getCanonicalName().equals("java.lang:type=Runtime")) {
String[] commandInputs = (String[]) attributes.get(INPUT_ARGUMENTS);
if (commandInputs != null) {
try {
attributes.put(INPUT_ARGUMENTS, cleanPasswordsFromInputArguments(commandInputs, REDACTED_INPUTS));
} catch (IllegalArgumentException e) {
attributes.put(INPUT_ARGUMENTS, commandInputs);
}
}
}
tabulate(JmxDumpUtil.NAME_HEADER, JmxDumpUtil.VALUE_HEADER, attributes, out, 0);
}
use of javax.management.JMException in project fabric8 by jboss-fuse.
the class ManagedApiFeature method initialize.
@Override
public void initialize(Server server, Bus bus) {
ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server);
InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class);
if (iMgr != null) {
try {
iMgr.register(mApi);
ServerLifeCycleManager slcMgr = bus.getExtension(ServerLifeCycleManager.class);
if (slcMgr != null) {
slcMgr.registerListener(mApi);
slcMgr.startServer(server);
}
} catch (JMException jmex) {
jmex.printStackTrace();
LOG.log(Level.WARNING, "Registering ManagedApi failed.", jmex);
}
}
}
use of javax.management.JMException in project fabric8 by jboss-fuse.
the class EnableJMXFeature method initialize.
@Override
public void initialize(Bus bus) {
List<Server> servers = new ArrayList<Server>();
ServerRegistry serverRegistry = bus.getExtension(ServerRegistry.class);
servers.addAll(serverRegistry.getServers());
for (Iterator<Server> iter = servers.iterator(); iter.hasNext(); ) {
Server server = (Server) iter.next();
ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server);
ManagedEndpoint mEndpoint = new ManagedEndpoint(bus, server.getEndpoint(), server);
InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class);
if (iMgr == null) {
iMgr = new InstrumentationManagerImpl(bus);
}
((InstrumentationManagerImpl) iMgr).setUsePlatformMBeanServer(true);
((InstrumentationManagerImpl) iMgr).setCreateMBServerConnectorFactory(false);
((InstrumentationManagerImpl) iMgr).setEnabled(true);
((InstrumentationManagerImpl) iMgr).init();
if (iMgr != null) {
try {
iMgr.register(mApi);
iMgr.register(mEndpoint);
} catch (JMException jmex) {
jmex.printStackTrace();
LOG.log(Level.WARNING, "Registering ManagedApi failed.", jmex);
}
}
}
}
use of javax.management.JMException in project nhin-d by DirectProject.
the class FileAuditor method registerMBean.
/*
* Register the MBean
*/
private void registerMBean() {
LOGGER.info("Registering FileAuditor MBean");
try {
itemNames = new String[] { "Event Id", "Event Time", "Event Principal", "Event Name", "Event Type", "Contexts" };
OpenType<?>[] types = { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, ArrayType.getArrayType(SimpleType.STRING) };
eventType = new CompositeType("AuditEvent", "Direct Auditable Event", itemNames, itemNames, types);
} catch (OpenDataException e) {
LOGGER.error("Failed to create settings composite type: " + e.getLocalizedMessage(), e);
return;
}
Class<?> clazz = this.getClass();
final StringBuilder objectNameBuilder = new StringBuilder(clazz.getPackage().getName());
objectNameBuilder.append(":type=").append(clazz.getSimpleName());
objectNameBuilder.append(",name=").append(UUID.randomUUID());
try {
final StandardMBean mbean = new StandardMBean(this, AuditorMBean.class);
final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
mbeanServer.registerMBean(mbean, new ObjectName(objectNameBuilder.toString()));
} catch (JMException e) {
LOGGER.error("Unable to register the FileAuditor MBean", e);
}
}
Aggregations