Package jenkins.util

Class Listeners


  • public class Listeners
    extends Object
    Utilities for working with listener interfaces.
    Since:
    2.324
    • Method Detail

      • notify

        public static <L> void notify​(Class<L> listenerType,
                                      boolean asSystem,
                                      Consumer<L> notification)
        Safely send a notification to all listeners of a given type.

        Only suitable for listener methods which do not throw checked or otherwise documented exceptions.

        Type Parameters:
        L - the type of listener
        Parameters:
        listenerType - the type of listener
        asSystem - whether to impersonate ACL.SYSTEM2. For most listener methods, this should be true, so that listener implementations can freely perform various operations without access checks. In some cases, existing listener interfaces were implicitly assumed to pass along user authentication, because they were sometimes triggered by user actions such as configuration changes; this is an antipattern (better to pass an explicit Authentication argument if relevant).
        notification - a listener method, perhaps with arguments
        Since:
        2.325