spark.Spark.init()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(3.7k)|赞(0)|评价(0)|浏览(293)

本文整理了Java中spark.Spark.init()方法的一些代码示例,展示了Spark.init()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Spark.init()方法的具体详情如下:
包路径:spark.Spark
类名称:Spark
方法名:init

Spark.init介绍

[英]Initializes the Spark server. SHOULD just be used when using the Websockets functionality.
[中]初始化Spark服务器。应仅在使用Websockets功能时使用。

代码示例

代码示例来源:origin: bwssytems/ha-bridge

initExceptionHandler((e) -> HABridge.theExceptionHandler(e, bridgeSettings.getBridgeSettingsDescriptor().getServerPort()));
if(!bridgeSettings.getBridgeControl().isReinit())
  init();
bridgeSettings.getBridgeControl().setReinit(false);

代码示例来源:origin: awslabs/aws-serverless-java-container

@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");
  }
}

代码示例来源:origin: mattjlewis/diozero

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
}

代码示例来源:origin: lamarios/Homedash2

/**
 * 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.";
}

代码示例来源:origin: cinchapi/concourse

private static void addFilter(String httpMethod, Filter filter) {
  init();
  routeMatcher.parseValidateAddRoute(
      httpMethod + " '" + filter.getPath() + "'",
      filter.getAcceptType(), filter);
}

代码示例来源:origin: cinchapi/concourse

private static void addRoute(String httpMethod, Route route) {
  init();
  routeMatcher.parseValidateAddRoute(
      httpMethod + " '" + route.getPath() + "'",
      route.getAcceptType(), route);
}

代码示例来源:origin: tipsy/spark-websocket

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();
}

代码示例来源:origin: mgtechsoftware/smockin

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);
  }
}

代码示例来源:origin: ikidou/Retrofit2Demo

public static void main(String[] args) throws SQLException {
  DB.init();
  Spark.init();

相关文章