/** * Create a server for the given router. * <p> * The server will be running in TEST mode. * * @param router The router for the server to serve. * @param port The port the server will run on. * @return The running server. */ public static Server forRouter(Router router, int port) { return forRouter(router, Mode.TEST, port); }
/** * Create a server for the given router. * * @param router The router for the server to serve. * @param mode The mode the server will run on. * @param port The port the server will run on. * @return The running server. */ public static Server forRouter(Router router, Mode mode, int port) { return new Server(JavaServerHelper.forRouter(router, JavaModeConverter.asScalaMode(mode), port)); }
/** * Stop the server */ public void stop() { if (server != null) server.stop(); }
public static void main(String[] args) throws Exception { try { File root = new File(System.getProperty("application.path", ".")); if (System.getProperty("precompiled", "false").equals("true")) { Play.usePrecompiled = true; } if (System.getProperty("writepid", "false").equals("true")) { writePID(root); } Play.init(root, System.getProperty("play.id", "")); if (System.getProperty("precompile") == null) { new Server(args); } else { Logger.info("Done."); } } catch (Throwable e) { Logger.fatal(e, "Failed to start"); System.exit(1); } } }
@Override public String getAddress() { String addr = server.mainAddress().toString(); if (addr.startsWith("/0:0:0:0:0:0:0:0")) { int last = addr.lastIndexOf(':'); if (last > 0) { addr = "http://localhost:" + addr.substring(last + 1); } } return addr; }
@Override public void stop() { if (server != null) server.stop(); }
@Override public String getAddress() { String addr = server.mainAddress().toString(); if (addr.startsWith("/0:0:0:0:0:0:0:0")) { int last = addr.lastIndexOf(':'); if (last > 0) { addr = "http://localhost:" + addr.substring(last + 1); } } return addr; }
/** * Create a server for the given router. * <p> * The server will be running on a randomly selected ephemeral port, which can be checked using the httpPort * property. * * @param router The router for the server to serve. * @param mode The mode the server will run on. * @return The running server. */ public static Server forRouter(Router router, Mode mode) { return forRouter(router, mode, 0); }
@Override public void stop() { if (server != null) server.stop(); }
/** * Build the server and begin serving the provided routes as configured. * * @param block the router to use. * @return the actively running server. */ public Server build(Function<BuiltInComponents, Router> block) { Server.Config config = _buildConfig(); return new Server( JavaServerHelper.forRouter( JavaModeConverter.asScalaMode(config.mode()), OptionConverters.toScala(config.maybeHttpPort()), OptionConverters.toScala(config.maybeHttpsPort()), block ) ); }
@Override public String getAddress() { String addr = server.mainAddress().toString(); if (addr.startsWith("/0:0:0:0:0:0:0:0")) { int last = addr.lastIndexOf(':'); if (last > 0) { addr = "http://localhost:" + addr.substring(last + 1); } } return addr; }
/** * Create a server for the given router. * <p> * The server will be running on a randomly selected ephemeral port, which can be checked using the httpPort * property. * <p> * The server will be running in TEST mode. * * @param mode The mode the server will run on. * @param block The block that creates the router. * @return The running server. */ public static Server forRouter(Mode mode, Function<BuiltInComponents, Router> block) { return forRouter(mode, 0, block); }
@Override public void stop() { if (server != null) server.stop(); }
/** * Build the server and begin serving the provided routes as configured. * * @param block the router to use. * @return the actively running server. */ public Server build(Function<BuiltInComponents, Router> block) { Server.Config config = _buildConfig(); return new Server( JavaServerHelper.forRouter( JavaModeConverter.asScalaMode(config.mode()), OptionConverters.toScala(config.maybeHttpPort()), OptionConverters.toScala(config.maybeHttpsPort()), block ) ); }
/** * Create a server for the given router. * <p> * The server will be running on a randomly selected ephemeral port, which can be checked using the httpPort * property. * <p> * The server will be running in TEST mode. * * @param block The block that creates the router. * @return The running server. */ public static Server forRouter(Function<BuiltInComponents, Router> block) { return forRouter(Mode.TEST, 0, block); }
/** * Stop the server * @throws Exception */ @Override public void close() throws Exception { if (subscriber != null) { for (int i = 0; i < subscriber.length; i++) { if (subscriber[i] != null) { subscriber[i].close(); } } } if (server != null) server.stop(); if (mediaDriver != null) CloseHelper.quietClose(mediaDriver); if (aeron != null) CloseHelper.quietClose(aeron); }
/** * Create a server for the given router. * <p> * The server will be running on a randomly selected ephemeral port, which can be checked using the httpPort * property. * <p> * The server will be running in TEST mode. * * @param router The router for the server to serve. * @return The running server. */ public static Server forRouter(Router router) { return forRouter(router, Mode.TEST, 0); }
/** * Stop the server * @throws Exception */ @Override public void close() throws Exception { if (subscriber != null) { for (int i = 0; i < subscriber.length; i++) { if (subscriber[i] != null) { subscriber[i].close(); } } } if (server != null) server.stop(); if (mediaDriver != null) CloseHelper.quietClose(mediaDriver); if (aeron != null) CloseHelper.quietClose(aeron); }
/** * Create a server for the given router. * <p> * The server will be running on a randomly selected ephemeral port, which can be checked using the httpPort * property. * <p> * The server will be running in TEST mode. * * @param block The block that creates the router. * @return The running server. */ public static Server forRouter(Function<BuiltInComponents, Router> block) { return forRouter(Mode.TEST, 0, block); }
/** * Create a server for the given router. * <p> * The server will be running on a randomly selected ephemeral port, which can be checked using the httpPort * property. * <p> * The server will be running in TEST mode. * * @param mode The mode the server will run on. * @param block The block that creates the router. * @return The running server. */ public static Server forRouter(Mode mode, Function<BuiltInComponents, Router> block) { return forRouter(mode, 0, block); }