Class KiwiDropwizardLifecycles
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidmanage(io.dropwizard.lifecycle.setup.LifecycleEnvironment lifecycle, Runnable startAction, Runnable stopAction) Creates a DropwizardManagedwhose start action isstartActionand whose stop action isstopAction, and attaches it to the given Dropwizardlifecycle.static voidmanageOnlyStart(io.dropwizard.lifecycle.setup.LifecycleEnvironment lifecycle, Runnable startAction) Creates a DropwizardManagedwhose start action isstartAction, and attaches it to the given Dropwizardlifecycle.static voidmanageOnlyStop(io.dropwizard.lifecycle.setup.LifecycleEnvironment lifecycle, Runnable stopAction) Creates a DropwizardManagedwhose stop action isstopAction, and attaches it to the given Dropwizardlifecycle.
-
Method Details
-
manage
public static void manage(io.dropwizard.lifecycle.setup.LifecycleEnvironment lifecycle, Runnable startAction, Runnable stopAction) Creates a DropwizardManagedwhose start action isstartActionand whose stop action isstopAction, and attaches it to the given Dropwizardlifecycle.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 hasstartandstopmethods) 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 managestartAction- the action to run when Dropwizard starts the applicationstopAction- the action to run when Dropwizard stops the application
-
manageOnlyStart
public static void manageOnlyStart(io.dropwizard.lifecycle.setup.LifecycleEnvironment lifecycle, Runnable startAction) Creates a DropwizardManagedwhose start action isstartAction, and attaches it to the given Dropwizardlifecycle.Useful when you have some external object that has a start method, but you don't want to clutter your code by creating an anonymous inner class just to specify the start action. For example, if you have a monitoring class that needs to start when the application starts, you can ensure that happens using code like:
KiwiDropwizardLifecycles.manage(lifecycle, () -> monitor.start());To make the code cleaner, use method references:
KiwiDropwizardLifecycles.manage(lifecycle, monitor::start);- Parameters:
lifecycle- the lifecycle to managestartAction- the action to run when Dropwizard starts the application
-
manageOnlyStop
public static void manageOnlyStop(io.dropwizard.lifecycle.setup.LifecycleEnvironment lifecycle, Runnable stopAction) Creates a DropwizardManagedwhose stop action isstopAction, and attaches it to the given Dropwizardlifecycle.Useful when you have some external object that has a stop method, but you don't want to clutter your code by creating an anonymous inner class just to specify the stop action. For example, if you have an HTTP
Clientclass that needs to stop when the application shuts down to ensure resources are properly closed, you can ensure that happens using code like:KiwiDropwizardLifecycles.manage(lifecycle, () -> client.close());To make the code cleaner, use method references:
KiwiDropwizardLifecycles.manage(lifecycle, client::close);- Parameters:
lifecycle- the lifecycle to managestopAction- the action to run when Dropwizard stops the application
-