Search in sources :

Example 1 with AsyncLoggerContext

use of org.apache.logging.log4j.core.async.AsyncLoggerContext in project logging-log4j2 by apache.

the class Server method reregisterMBeansAfterReconfigure.

public static void reregisterMBeansAfterReconfigure(final MBeanServer mbs) {
    if (isJmxDisabled()) {
        LOGGER.debug("JMX disabled for Log4j2. Not registering MBeans.");
        return;
    }
    // LoggerConfigs and Appenders
    try {
        final ContextSelector selector = getContextSelector();
        if (selector == null) {
            LOGGER.debug("Could not register MBeans: no ContextSelector found.");
            return;
        }
        LOGGER.trace("Reregistering MBeans after reconfigure. Selector={}", selector);
        final List<LoggerContext> contexts = selector.getLoggerContexts();
        int i = 0;
        for (final LoggerContext ctx : contexts) {
            LOGGER.trace("Reregistering context ({}/{}): '{}' {}", ++i, contexts.size(), ctx.getName(), ctx);
            // first unregister the context and all nested loggers,
            // appenders, statusLogger, contextSelector, ringbuffers...
            unregisterLoggerContext(ctx.getName(), mbs);
            final LoggerContextAdmin mbean = new LoggerContextAdmin(ctx, executor);
            register(mbs, mbean, mbean.getObjectName());
            if (ctx instanceof AsyncLoggerContext) {
                final RingBufferAdmin rbmbean = ((AsyncLoggerContext) ctx).createRingBufferAdmin();
                if (rbmbean.getBufferSize() > 0) {
                    // don't register if Disruptor not started (DefaultConfiguration: config not found)
                    register(mbs, rbmbean, rbmbean.getObjectName());
                }
            }
            // register the status logger and the context selector
            // repeatedly
            // for each known context: if one context is unregistered,
            // these MBeans should still be available for the other
            // contexts.
            registerStatusLogger(ctx.getName(), mbs, executor);
            registerContextSelector(ctx.getName(), selector, mbs, executor);
            registerLoggerConfigs(ctx, mbs, executor);
            registerAppenders(ctx, mbs, executor);
        }
    } catch (final Exception ex) {
        LOGGER.error("Could not register mbeans", ex);
    }
}
Also used : ContextSelector(org.apache.logging.log4j.core.selector.ContextSelector) AsyncLoggerContext(org.apache.logging.log4j.core.async.AsyncLoggerContext) LoggerContext(org.apache.logging.log4j.core.LoggerContext) AsyncLoggerContext(org.apache.logging.log4j.core.async.AsyncLoggerContext) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException)

Aggregations

InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 LoggerContext (org.apache.logging.log4j.core.LoggerContext)1 AsyncLoggerContext (org.apache.logging.log4j.core.async.AsyncLoggerContext)1 ContextSelector (org.apache.logging.log4j.core.selector.ContextSelector)1