I've started to use the RoutingAppender to record messages being transmitted to/from our apps port. The messages are categorized in bins and routed to separate rolling logfiles. Wanting to extend this mechanism to generate different operations logs (manually or time triggered batch maintenance operations), I figured the number of route appenders could grow indefinitely, without any mechanism to curb the unused ones. This could also be a problem in cases where routing is used with usernames as routing key, only a portion of route appenders end being in use at any time, with thousands of other just taking up resources.
After looking at the code, I came up with a solution that I believe is not too invasive nor prescriptive. Because there a lot of ways one would want to control the appender instances, some very simple (Single Active Instance) and some rather costly in performance (MaxCount / LRU, Time-to-Live tracking), I think it would be best to delegate any implementation to the user, at least until some common pattern(s) crop up. So, in short, I defined a new Interface "RoutingAppenderListener" that one can register to a routing appender and which get notified at initialization and everytime an appenderControl is created or used. The interface is completely optional and its use does not change the existing flow of the RoutingAppender - all notifications are strictly informational. Lifecycle control is achieved by a new "removeAppender" method on the RoutingAppender, which may be called at any time by the listener (which could be driven by an async cleanup scheduler). The listener would take care of stop()ping any removed appender. The appenders ConcurrentHashMap then effectively becomes a dynamic pool of appenders, which may get stopped and recreated as required. If you think this is valuable, I have a working implementation that I could send a PR for. I worked in a branch off 2.5-SNAPSHOT from an apache github clone. Not sure what the process is after that, but I am willing to follow instructions :) Suggestions, critics and flames all appreciated - any feedback is better than none at all. Francis
