Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-3496

Support injection via container types

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 3.0.0
    • Plugins
    • None

    Description

      Plugin system should support the injection via container types. Since this is not currently the case, whenever a, for instance, collection of plugins need to be injected (e.g., Pattern and JSON Template Layouts), ad-hoc access to PluginManager or PluginUtils is needed. This approach has certain drawbacks:

      • Duplication of ad-hoc code
      • Not aligned with the way plugins are loaded, that is, via @Inject
      • Impossible to test

      Container types

      Ideally, the plugin system should support injection via the following container types:

      • Optional<P>
      • Collection<P>
      • Iterable<P>
      • Set<P>
      • Stream<P>
      • List<P>
      • Map<N, P>

      Above P denotes the type the plugin is assignable from and N denotes the plugin name.

      Ordering problem

      A @PluginOrder annotation needs to be introduced to address the following corner cases:

      • In the case of Optional<P>, if there are multiple matches, the first one needs to be picked.
      • In the case of collection and map types, elements need to be sorted.

      Sorting can be done in the following way:

      • If one or more of the matches are annotated with @PluginOrder, they will have the precedence and get sorted according to @PluginOrder values.
      • The rest will be sorted according to their discovery order.

      The order in collection types can be preserved using the following implementations:

      • Set -> LinkedHashSet
      • Map -> LinkedHashMap
      • Collection, Iterable, Stream -> List

      Attachments

        Issue Links

          Activity

            People

              mattsicker Matt Sicker
              vy Volkan Yazici
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: