@Override protected void finishRefresh() { super.finishRefresh(); WebServer webServer = startReactiveWebServer(); if (webServer != null) { publishEvent(new ReactiveWebServerInitializedEvent(webServer, this)); } }
private void createWebServer() { ServerManager serverManager = this.serverManager; if (serverManager == null) { this.serverManager = ServerManager.get(getWebServerFactory()); } initPropertySources(); }
@Override protected void onClose() { super.onClose(); stopAndReleaseReactiveWebServer(); }
/** * Create a new {@link AnnotationConfigReactiveWebServerApplicationContext}, deriving * bean definitions from the given annotated classes and automatically refreshing the * context. * @param annotatedClasses one or more annotated classes, e.g. {@code @Configuration} * classes */ public AnnotationConfigReactiveWebServerApplicationContext( Class<?>... annotatedClasses) { this(); register(annotatedClasses); refresh(); }
private void loadBeanDefinitions(AnnotatedBeanDefinitionReader reader, ClassPathBeanDefinitionScanner scanner) throws LinkageError { if (!this.annotatedClasses.isEmpty()) { registerAnnotatedClasses(reader); } if (!this.basePackages.isEmpty()) { scanBasePackages(scanner); } String[] configLocations = getConfigLocations(); if (configLocations != null) { registerConfigLocations(reader, scanner, configLocations); } }
/** * Create a new {@link AnnotationConfigReactiveWebServerApplicationContext}, scanning * for bean definitions in the given packages and automatically refreshing the * context. * @param basePackages the packages to check for annotated classes */ public AnnotationConfigReactiveWebServerApplicationContext(String... basePackages) { this(); scan(basePackages); refresh(); }
@Override public final void refresh() throws BeansException, IllegalStateException { try { super.refresh(); } catch (RuntimeException ex) { stopAndReleaseReactiveWebServer(); throw ex; } }
private WebServer startReactiveWebServer() { ServerManager serverManager = this.serverManager; ServerManager.start(serverManager, this::getHttpHandler); return ServerManager.getWebServer(serverManager); }
@Override protected void onRefresh() { super.onRefresh(); try { createWebServer(); } catch (Throwable ex) { throw new ApplicationContextException("Unable to start reactive web server", ex); } }
@Override protected Resource getResourceByPath(String path) { // We must be careful not to expose classpath resources return new FilteredReactiveWebContextResource(path); }
@Override protected ConfigurableEnvironment createEnvironment() { return new StandardReactiveWebEnvironment(); }
/** * Returns the {@link WebServer} that was created by the context or {@code null} if * the server has not yet been created. * @return the web server */ @Override public WebServer getWebServer() { return ServerManager.getWebServer(this.serverManager); }
private void stopAndReleaseReactiveWebServer() { ServerManager serverManager = this.serverManager; try { ServerManager.stop(serverManager); } finally { this.serverManager = null; } }
public static ServerManager get(ReactiveWebServerFactory factory) { return new ServerManager(factory); }
@Override public InputStream getInputStream() throws IOException { throw new FileNotFoundException( this.getDescription() + " cannot be opened because it does not exist"); }
@Override protected void prepareRefresh() { this.scanner.clearCache(); super.prepareRefresh(); }
/** * Build an {@link AnnotatedBeanDefinitionReader} for the given bean factory. * <p> * This should be pre-configured with the {@code Environment} (if desired) but not * with a {@code BeanNameGenerator} or {@code ScopeMetadataResolver} yet. * @param beanFactory the bean factory to load bean definitions into * @return the annotated bean definition reader * @see #getEnvironment() * @see #getBeanNameGenerator() * @see #getScopeMetadataResolver() */ protected AnnotatedBeanDefinitionReader getAnnotatedBeanDefinitionReader( DefaultListableBeanFactory beanFactory) { return new AnnotatedBeanDefinitionReader(beanFactory, getEnvironment()); }
@Override protected Resource getResourceByPath(String path) { // We must be careful not to expose classpath resources return new FilteredReactiveWebContextResource(path); }
@Override protected ConfigurableEnvironment createEnvironment() { return new StandardReactiveWebEnvironment(); }
@Override public Resource createRelative(String relativePath) throws IOException { String pathToUse = StringUtils.applyRelativePath(this.path, relativePath); return new FilteredReactiveWebContextResource(pathToUse); }