To use, install the WarmUpModule in your Guice injector. To initiate the warm up, get the warm up stager and call the stage() method.
Injector injector = Guice.createInjector( WarmUpModule().newWarmUpModule() ); // ... Stager<WarmUp> warmUpStager = injector.get( LifeCycleStageModule.key(WarmUp.class) ); warmUpStager.stage(); // causes all injected object's @WarmUp methods to get called
Of course, instead of getting the stager from the injector you can declare it as a dependency:
public class MyClass
{
private final Stager<WarmUp> stager;
@Inject
public MyClass(Stager<WarmUp> stager)
{
this.stager = stager;
}
@AfterInjection
public void start()
{
stager.stage();
}
}