Class KiwiDropwizardLifecycles

java.lang.Object
org.kiwiproject.dropwizard.lifecycle.KiwiDropwizardLifecycles

public final class KiwiDropwizardLifecycles extends Object
Provides utilities related to the Dropwizard lifecycle.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • 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