use of com.adeptj.runtime.osgi.FrameworkShutdownHandler in project adeptj-runtime by AdeptJ.
the class ContainerInitializer method onStartup.
/**
* {@inheritDoc}
*/
@Override
public void onStartup(Set<Class<?>> startupAwareClasses, ServletContext context) {
Logger logger = LoggerFactory.getLogger(ContainerInitializer.class);
if (startupAwareClasses == null || startupAwareClasses.isEmpty()) {
// We can't go ahead if StartupAware implementations are not passed by container.
logger.error("No @HandlesTypes(StartupAware) on classpath!!");
throw new IllegalStateException("No @HandlesTypes(StartupAware) on classpath!!");
} else {
ServletContextHolder.INSTANCE.setServletContext(context);
startupAwareClasses.stream().sorted(new StartupAwareComparator()).peek(startupAwareClass -> logger.info("@HandlesTypes: [{}]", startupAwareClass)).forEach(startupAwareClass -> {
try {
startupAwareClass.asSubclass(StartupAware.class).getDeclaredConstructor().newInstance().onStartup(context);
} catch (Exception ex) {
// NOSONAR
logger.error("Exception while executing StartupAware#onStartup!!", ex);
throw new InitializationException("Exception while executing StartupAware#onStartup!!", ex);
}
});
// If we are here means startup went well above, register FrameworkShutdownHandler now.
context.addListener(FrameworkShutdownHandler.class);
}
}
Aggregations