Need help implementing Java modules
Alex Buckley
alex.buckley at oracle.com
Tue May 9 19:54:53 UTC 2017
On 5/9/2017 11:51 AM, Ralph Goers wrote:
> I am attempting to modularize Log4j and am running into some trouble
> understanding how this can work.
>
> Log4j supports many Appenders, such as the FlumeAppender,
> KafkaAppender, CassandraAppender, and JPAAppender.
I don't know how Log4j is currently discovering Appenders, but I guess
it's through reflective means (Class.forName, classpath scanning, etc).
Services are a better approach because then the JDK does the discovery
while you focus on the type-safe protocol between Log4j and Appenders.
Consider this:
- The Log4j module should not require the FlumeAppender module et al.
- The Log4j module should export a service interface AppenderIntf.
- The FlumeAppender module should i) require the Log4j module to gain
access to AppenderIntf, and ii) provide its Flume-specific
implementation of the service interface ('provides AppenderIntf with
FlumeAppenderImpl;'). If the FlumeAppender module requires helper
modules, and they in turn require the Log4j module, that's fine.
- The Log4j module should use its own service interface ('uses
AppenderIntf;') and discover appender implementations via ServiceLoader.
Alex
More information about the jigsaw-dev
mailing list