Search in sources :

Example 61 with JMException

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
        }
    }
}
Also used : TreeSet(java.util.TreeSet) JMException(javax.management.JMException) ObjectName(javax.management.ObjectName)

Example 62 with JMException

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);
}
Also used : MBeanInfo(javax.management.MBeanInfo) TreeMap(java.util.TreeMap) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) IOException(java.io.IOException) JMException(javax.management.JMException)

Example 63 with JMException

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);
        }
    }
}
Also used : ServerLifeCycleManager(org.apache.cxf.endpoint.ServerLifeCycleManager) JMException(javax.management.JMException) InstrumentationManager(org.apache.cxf.management.InstrumentationManager)

Example 64 with JMException

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);
            }
        }
    }
}
Also used : InstrumentationManagerImpl(org.apache.cxf.management.jmx.InstrumentationManagerImpl) Server(org.apache.cxf.endpoint.Server) ArrayList(java.util.ArrayList) JMException(javax.management.JMException) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry) ManagedEndpoint(org.apache.cxf.endpoint.ManagedEndpoint) InstrumentationManager(org.apache.cxf.management.InstrumentationManager)

Example 65 with JMException

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);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) StandardMBean(javax.management.StandardMBean) JMException(javax.management.JMException) CompositeType(javax.management.openmbean.CompositeType) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

JMException (javax.management.JMException)116 ObjectName (javax.management.ObjectName)66 MBeanServer (javax.management.MBeanServer)33 IOException (java.io.IOException)22 InstrumentationManager (org.apache.cxf.management.InstrumentationManager)13 MBeanInfo (javax.management.MBeanInfo)11 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)9 SnmpStatusException (com.sun.management.snmp.SnmpStatusException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 StandardMBean (javax.management.StandardMBean)7 RequiredModelMBean (javax.management.modelmbean.RequiredModelMBean)6 Date (java.util.Date)5 Attribute (javax.management.Attribute)5 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)5 Element (org.w3c.dom.Element)5 PostConstruct (javax.annotation.PostConstruct)4 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)4