示例#1
0
  public final ServerStarter start(Stage stage, Consumer<ServerBuilder> consumer) {
    notNull(consumer, "Null ServerBuilder consumer");

    /* Create a new injector and set up the module */
    final Injector injector =
        Guice.createInjector(stage, (binder) -> consumer.accept(new ServerBuilder(binder)));

    /* Get a hold on our HttpServer instance */
    final HttpServer server = injector.getInstance(HttpServer.class);
    final String serverName = server.getServerConfiguration().getName();

    /* Attempt to start our server */
    try {
      log.info("Starting server %s", serverName);
      server.start();
    } catch (IOException exception) {
      log.error(exception, "Exception starting server %s", serverName);
      System.exit(1);
    }

    /* Add a shutdown hook terminating the server on exit */
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              @Override
              public void run() {
                log.info("Shutting down server %s", serverName);
                server.shutdown();
              }
            });

    /* Return self for chaining */
    this.server = server;
    return this;
  }
 @Inject
 private void setup(Injector injector, HttpServer server) {
   final ServerConfiguration configuration = server.getServerConfiguration();
   configuration.setDefaultErrorPageGenerator(
       generator != null ? generator : injector.getInstance(key));
   log.info("Configured default error page generator on server \"%s\"", configuration.getName());
 }
示例#3
0
  public final void stop() {
    if (server == null) throw new IllegalStateException("Not started");

    final String serverName = server.getServerConfiguration().getName();
    log.info("Shutting down server %s", serverName);
    server.shutdown();
    server = null;
  }
  @Inject
  private void setup(HttpServer server) {
    final ServerConfiguration configuration = server.getServerConfiguration();
    configuration.getMonitoringConfig().getWebServerConfig().addProbes(probe);

    log.info(
        "Configured access log writing to \"%s\" on server \"%s\"",
        accessLog, configuration.getName());
  }
示例#5
0
  public final void join() {
    if (server == null) throw new IllegalStateException("Not started");

    /* Wait forever until the server is shut down */
    try {
      Thread.sleep(Long.MAX_VALUE);
    } catch (InterruptedException exception) {
      log.warn("Interrupted while waiting server shutdown");
      if (server != null) stop();
    }
  }