com.pennassurancesoftware.dropwizard.stop.StopBundle Maven / Gradle / Ivy
The newest version!
package com.pennassurancesoftware.dropwizard.stop;
import io.dropwizard.Configuration;
import io.dropwizard.ConfiguredBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.dropwizard.util.Generics;
/**
* Optional functionality to coordinate a graceful stop of the service.
* To add this functionality, you should add this bundle during the Service initialization.
* And make sure that you 'initialize' the bundle too.
* Here is a code snippet:
*
public void initialize(Bootstrap{@code } bootstrap) {
....
StopBundle{@code } stopBundle = new StopBundle{@code }() {
{@literal @}Override
public StopConfiguration getStopConfiguration(YourAppConfiguration configuration) {
return configuration.getStopConfiguration();
}
};
bootstrap.addBundle(stopBundle);
// This seems like a bug to me. I.e. some bundles are initialized and others are not.
stopBundle.initialize(bootstrap);
....
}
* }
*
* Don't forget to add a {@link StopConfiguration} to YourAppConfiguration.
*
*/
public abstract class StopBundle implements ConfiguredBundle, ConfigurationStrategy {
@Override
public final void initialize( Bootstrap> bootstrap ) {
final Class klass = Generics.getTypeParameter( getClass(), Configuration.class );
bootstrap.addCommand( new StopCommand( this, klass ) );
}
@Override
public void run( T configuration, Environment environment ) throws Exception {
final StopConfiguration stopConfig = getStopConfiguration( configuration );
environment.lifecycle().addServerLifecycleListener( new StopMonitor( stopConfig ) );
}
}