/** * Convenience function that {@link ServerConfigBuilder#build() builds} the config from the given builder and delegates to {@link #serverConfig(ServerConfig)}. * * @param builder the server configuration (as a builder) * @return {@code this} */ default RatpackServerSpec serverConfig(ServerConfigBuilder builder) { return serverConfig(builder.build()); }
/** * Creates a builder configured for development mode and an ephemeral port. * * @return a server config builder */ static ServerConfigBuilder embedded() { return builder().development(true).port(0); }
/** * Convenience method to {@link #of(Action) define} and {@link #start()} the server in one go. * * @param definition the server definition * @return the newly created and started server * @throws Exception any thrown by {@link #of(Action)} or {@link #start()} */ static RatpackServer start(Action<? super RatpackServerSpec> definition) throws Exception { RatpackServer server = of(definition); server.start(); return server; }
public EmbeddedRatpackServerSpec(RatpackServerSpec delegate) { super(delegate); delegate.serverConfig(ServerConfig.embedded()); }
@Override public RatpackServerSpec serverConfig(ServerConfig serverConfig) { delegate.serverConfig(serverConfig); return this; }
default RatpackServerSpec serverConfig(Action<? super ServerConfigBuilder> action) throws Exception { return serverConfig(ServerConfig.of(action)); }
/** * Sets the user registry to exactly the given registry. * * @param registry the user registry * @return {@code this} */ default RatpackServerSpec registry(Registry registry) { return registry(r -> registry); }
/** * Creates an embedded application with a default launch config (no base dir, ephemeral port) and the given handler. * <p> * If you need to tweak the server config, use {@link #fromServer(ServerConfig, Action)}. * * @param handler the application handler * @return a newly created embedded application */ static EmbeddedApp fromHandler(Handler handler) { return fromServer(ServerConfig.embedded().build(), b -> b.handler(r -> handler)); }
/** * Finds the “directory” on the classpath that contains a file called {@code .ratpack}. * <p> * Calling this method is equivalent to calling {@link #find(String) findBaseDir(".ratpack")}. * * @return a base dir * @see #find(String) */ public static Path find() { return find(DEFAULT_BASE_DIR_MARKER_FILE_PATH); }
@Override public void destroy() throws Exception { server.stop(); }
@Override public GroovyRatpackServerSpec handler(Function<? super Registry, ? extends Handler> handlerFactory) { delegate.handler(handlerFactory); return this; } }
@Override public String getName() { return delegate.getName(); }
@Override public GroovyRatpackServerSpec serverConfig(ServerConfig serverConfig) { delegate.serverConfig(serverConfig); return this; }
@Override public RatpackServerSpec registry(Function<? super Registry, ? extends Registry> function) { delegate.registry(function); return this; }
/** * Creates an embedded application with a default launch config (no base dir, ephemeral port) and the given handler. * <p> * If you need to tweak the server config, use {@link #fromServer(ServerConfig, Action)}. * * @param handlerFactory a handler factory * @return a newly created embedded application */ static EmbeddedApp fromHandlerFactory(Function<? super Registry, ? extends Handler> handlerFactory) { return fromServer(ServerConfig.embedded().build(), b -> b.handler(handlerFactory)); }
@Override public RatpackServerSpec handler(Function<? super Registry, ? extends Handler> handlerFactory) { delegate.handler(handlerFactory); return this; } }
@Override public GroovyRatpackServerSpec serverConfig(Action<? super ServerConfigBuilder> action) throws Exception { delegate.serverConfig(action); return this; }
@Override public GroovyRatpackServerSpec registry(Function<? super Registry, ? extends Registry> function) { delegate.registry(function); return this; }