initExceptionHandler((e) -> HABridge.theExceptionHandler(e, bridgeSettings.getBridgeSettingsDescriptor().getServerPort())); if(!bridgeSettings.getBridgeControl().isReinit()) init(); bridgeSettings.getBridgeControl().setReinit(false);
@Override public void initialize() throws ContainerInitializationException { Timer.start("SPARK_COLD_START"); log.debug("First request, getting new server instance"); // trying to call init in case the embedded server had not been initialized. Spark.init(); // adding this call to make sure that the framework is fully initialized. This should address a race // condition and solve GitHub issue #71. Spark.awaitInitialization(); embeddedServer = lambdaServerFactory.getServerInstance(); // manually add the spark filter to the chain. This should the last one and match all uris FilterRegistration.Dynamic sparkRegistration = getServletContext().addFilter("SparkFilter", embeddedServer.getSparkFilter()); sparkRegistration.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); Timer.stop("SPARK_COLD_START"); } }
public static void main(String[] args) { port(8080); webSocket("/diozero", JsonWebSocket.class); init(); // Needed if you don't define any HTTP routes after your WebSocket routes }
/** * the auto update process * * @param request * @param response * @return */ private String update(Request request, Response response) { ExecutorService exec = Executors.newSingleThreadExecutor(); exec.execute(() -> { try { logger.info("Downloading last version"); File latestVersion = updater.downloadLatestVersion(); logger.info("Latest version downloaded : [{}]", latestVersion.getAbsolutePath()); //Stopping the server so we can update peacefully if (updater.isFolderStructureOkForAutoUpdate()) { Spark.stop(); try { updater.stopHomedashAndTriggerUpdate(latestVersion.toPath().toAbsolutePath()); } catch (Exception e) { logger.error("error while updating, restarting Spark", e); Spark.init(); } } } catch (Exception e) { logger.error("Error while downloading the latest version", e); } }); return "Homedash is updating and will restart on its own, try to stay still."; }
private static void addFilter(String httpMethod, Filter filter) { init(); routeMatcher.parseValidateAddRoute( httpMethod + " '" + filter.getPath() + "'", filter.getAcceptType(), filter); }
private static void addRoute(String httpMethod, Route route) { init(); routeMatcher.parseValidateAddRoute( httpMethod + " '" + route.getPath() + "'", route.getAcceptType(), route); }
public static void main(String[] args) { staticFiles.location("/public"); //index.html is served at localhost:4567 (default port) staticFiles.expireTime(600); webSocket("/chat", ChatWebSocketHandler.class); init(); }
void initServer(final int port) throws MockServerException { logger.debug("initServer called"); try { clearState(); Spark.init(); // Blocks the current thread (using a CountDownLatch under the hood) until the server is fully initialised. Spark.awaitInitialization(); synchronized (monitor) { serverState.setRunning(true); serverState.setPort(port); } } catch (Throwable ex) { throw new MockServerException(ex); } }
public static void main(String[] args) throws SQLException { DB.init(); Spark.init();