Class KiwiDropwizardLifecycles


  • public class KiwiDropwizardLifecycles
    extends Object
    Provides utilities related to the Dropwizard lifecycle.
    • Constructor Detail

      • KiwiDropwizardLifecycles

        public KiwiDropwizardLifecycles()
    • Method Detail

      • manage

        public static void manage​(io.dropwizard.lifecycle.setup.LifecycleEnvironment lifecycle,
                                  Runnable startAction,
                                  Runnable stopAction)
        Creates a Dropwizard Managed whose start action is startAction and whose stop action is stopAction, and attaches it to the given Dropwizard lifecycle.

        Useful when you have some external object that has start and stop methods, but you don't want to clutter your code by creating an anonymous inner class just to specify the start and stop actions. For example if you have an ActiveMQ PooledConnectionFactory (which has start and stop methods) you can simply call this method:

        KiwiDropwizardLifecycles.manage(lifecycle, () -> factory.start(), () -> factory.stop());

        To make the code cleaner, use method references:

        KiwiDropwizardLifecycles.manage(lifecycle, factory::start, factory::stop);

        Parameters:
        lifecycle - the lifecycle to manage
        startAction - the action to run when Dropwizard starts the application
        stopAction - the action to run when Dropwizard stops the application