private final List<OnStartListener> onStartListeners = new CopyOnWriteArrayList<OnStartListener>();
private final List<OnStopListener> onStopListeners = new CopyOnWriteArrayList<OnStopListener>();
@Override
public void beforeStart(final Application application) {
final Reflections reflections = new Reflections(new ConfigurationBuilder()
.filterInputsBy(new FilterBuilder.Exclude(FilterBuilder.prefix("com.google")))
.addUrls(ClasspathHelper.forClassLoader(application.classloader()))
.addScanners(
new SubTypesScanner()
));
// automatic Guice module detection
Set<Class<? extends AbstractModule>> guiceModules = reflections.getSubTypesOf(AbstractModule.class);
for (Class<? extends Module> moduleClass : guiceModules) {
try {
if (!moduleClass.isAnonymousClass()) {
modules.add(moduleClass.newInstance());
}
} catch (InstantiationException e) {
throw Throwables.propagate(e);
} catch (IllegalAccessException e) {
throw Throwables.propagate(e);
}
}
modules.add(new AbstractModule() {
@Override
protected void configure() {
bind(Application.class).toInstance(application);
bind(Reflections.class).toInstance(reflections);
Names.bindProperties(this.binder(), fromKeys(application.configuration().keys(), new Function<String, String>() {
@Override
public String apply(String key) {
if (key.contains("akka")) return null;
return application.configuration().getString(key);
}
}));
for (Class<? extends Controller> controllerClass : reflections.getSubTypesOf(Controller.class)) {
Logger.info("Static injection for " + controllerClass);
requestStaticInjection(controllerClass);
}
// bind all services
Multibinder<Service> serviceBinder = Multibinder.newSetBinder(binder(), Service.class);
for (Class<? extends Service> serviceImplClass : reflections.getSubTypesOf(AbstractService.class)) {
serviceBinder.addBinding().to(serviceImplClass).asEagerSingleton();
}
for (Class<? extends Service> serviceImplClass : reflections.getSubTypesOf(AbstractIdleService.class)) {
serviceBinder.addBinding().to(serviceImplClass).asEagerSingleton();
}
for (Class<? extends Service> serviceImplClass : reflections.getSubTypesOf(AbstractExecutionThreadService.class)) {
serviceBinder.addBinding().to(serviceImplClass).asEagerSingleton();
}
// bind actor - todo use reflections for this
bind(ActorRef.class).annotatedWith(Names.named("ProcessCPOCsvEntry"))