All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kiwiproject.dropwizard.lifecycle.KiwiDropwizardLifecycles Maven / Gradle / Ivy

Go to download

Kiwi is a utility library. We really like Google's Guava, and also use Apache Commons. But if they don't have something we need, and we think it is useful, this is where we put it.

There is a newer version: 4.4.0
Show newest version
package org.kiwiproject.dropwizard.lifecycle;

import io.dropwizard.lifecycle.Managed;
import io.dropwizard.lifecycle.setup.LifecycleEnvironment;
import lombok.experimental.UtilityClass;

/**
 * Provides utilities related to the Dropwizard lifecycle.
 */
@UtilityClass
public class KiwiDropwizardLifecycles {

    /**
     * Creates a Dropwizard {@link Managed} whose start action is {@code startAction} and whose stop action
     * is {@code stopAction}, and attaches it to the given Dropwizard {@code 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 {@code PooledConnectionFactory} (which has {@code start} and {@code stop} methods) you can simply * call this method: *

* {@code KiwiDropwizardLifecycles.manage(lifecycle, () -> factory.start(), () -> factory.stop());} *

* To make the code cleaner, use method references: *

* {@code KiwiDropwizardLifecycles.manage(lifecycle, factory::start, factory::stop);} * * @param lifecycle the lifecycle to manage * @param startAction the action to run when Dropwizard starts the application * @param stopAction the action to run when Dropwizard stops the application */ public static void manage(LifecycleEnvironment lifecycle, Runnable startAction, Runnable stopAction) { lifecycle.manage(new Managed() { @Override public void start() { startAction.run(); } @Override public void stop() { stopAction.run(); } }); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy