コード例 #1
0
ファイル: ServerThread.java プロジェクト: spring/SpringLS
  @Override
  public void started() {

    // As DateFormats are generally not-thread save,
    // we always create a new one.
    DateFormat dateTimeFormat = new SimpleDateFormat("yyyy.MM.dd 'at' hh:mm:ss z");

    LOG.info(
        "{} {} started on {}",
        new Object[] {
          Server.getApplicationName(),
          Misc.getAppVersionNonNull(),
          dateTimeFormat.format(new Date())
        });

    // add server notification
    ServerNotification sn = new ServerNotification("Server started");
    Configuration conf = getContext().getService(Configuration.class);
    int port = conf.getInt(ServerConfiguration.PORT);
    sn.addLine(
        String.format(
            "Server has been started on port %d."
                + " There are %d accounts. "
                + "See server log for more info.",
            port, context.getAccountsService().getAccountsSize()));
    context.getServerNotifications().addNotification(sn);

    createAdminIfNoUsers();
  }
コード例 #2
0
ファイル: ServerThread.java プロジェクト: spring/SpringLS
  public void run() {

    running = true;
    while (running) { // main loop

      for (Updateable updateable : updateables) {
        updateable.update();
      }

      // sleep a bit
      try {
        Thread.sleep(MAIN_LOOP_SLEEP);
      } catch (InterruptedException iex) {
      }
    }

    getContext().stopping();

    // close everything:
    getContext().getAccountsService().saveAccounts(true);
    NatHelpServer natHelpServer = getContext().getService(NatHelpServer.class);
    if ((natHelpServer != null) && natHelpServer.isRunning()) {
      natHelpServer.stopServer();
    }

    // add server notification:
    ServerNotification sn = new ServerNotification("Server stopped");
    sn.addLine("Server has just been stopped gracefully. See server log for more info.");
    getContext().getServerNotifications().addNotification(sn);

    LOG.info("Server closed gracefully!");

    getContext().stopped();
  }
コード例 #3
0
ファイル: ServerThread.java プロジェクト: spring/SpringLS
  /** Shuts down the server forcefully. */
  public void closeServerAndExit() {

    // FIXME these things do not get called on normal exit yet!
    //   see (end of) method run()

    // getContext().stopping();

    // add server notification
    if ((getContext() != null) && (getContext().getServerNotifications() != null)) {
      ServerNotification sn = new ServerNotification("Server stopped");
      sn.addLine("Server has just been stopped. See server log for more info.");
      getContext().getServerNotifications().addNotification(sn);
    }

    // getContext().stopped();
    LOG.warn("Server stopped forcefully, please see the log for details");

    System.exit(127);
  }