Issue Details (XML | Word | Printable)

Key: MULE-3976
Type: Patch submission Patch submission
Status: Open Open
Priority: Minor Minor
Assignee: Unassigned
Reporter: Dimitar Dimitrov
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Mule

Improve log4j agent to handle log4j zeroconf

Created: 20/Nov/08 10:40 PM   Updated: 28/Nov/08 06:34 AM
Component/s: Core: Agents
Affects Version/s: 2.1.0
Fix Version/s: 2.x Product Backlog

Time Tracking:
Not Specified

Includes test case?: no
Labels:
User impact: Low


 Description  « Hide
When one uses the Log4J Zeroconf module (advertising the application's SocketHub appender over mDns), and the application in question uses a custom launcher, the application does not terminate gracefully when we shutdown the Mule server.

The reason is that the log4J zeroconf module creates a number of non-daemon threads and we need to stop them explicitly.

Even though it's not a Mule problem, it would be nice if the Mule's log4j agent took care about this. The behaviur could be disabled by default with configuration param to enable it. Here is some code illustrating the idea:

public class Log4jZeroconfAgent extends Log4jAgent {
    private static final Logger logger = Logger.getLogger(Log4jZeroconfAgent.class);

    @Override
    public String getDescription() {
        return super.getDescription() + "(with Zeroconf support)";
    }

    @Override
    public void dispose() {
        disposeZeroconfAppenders(LogManager.getRootLogger());

        for (Enumeration loggers = LogManager.getCurrentLoggers(); loggers.hasMoreElements();) {
            disposeZeroconfAppenders((Logger) loggers.nextElement());
        }

        try {
            shutdownMdnsDaemon();
        } catch (ClassNotFoundException e) {
            logger.debug("Log4J zeroconf not detected.");
        } catch (Throwable e) {
            logger.warn("Error while disposing log4J zeroconf loggers.");
        }
    }

    private void shutdownMdnsDaemon() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        Class<?> zeroconfClass = Class.forName("org.apache.log4j.net.Zeroconf4log4j");
        Method zeroconfShutdownMethod = zeroconfClass.getMethod("zeroconfShutdownMethod");
        zeroconfShutdownMethod.invoke(null);
    }

    private void disposeZeroconfAppenders(Logger logger) {
        for (Enumeration appenders = logger.getAllAppenders(); appenders.hasMoreElements();) {
            Appender appender = (Appender) appenders.nextElement();
            String appenderClassname = appender.getClass().getName();
            if ("org.apache.log4j.net.ZeroConfSocketHubAppender".equals(appenderClassname)) {
                logger.removeAppender(appender);
                appender.close();
            }
        }
    }

}


 All   Comments   Work Log   Change History   Transitions   FishEye      Sort Order: Ascending order - Click to sort in descending order
Dimitar Dimitrov added a comment - 20/Nov/08 10:50 PM
Please reformat the signature of shutdownMdnsDaemon, so the page doesn't expand beyond the browser width.