Persoenliche Mediazentrale
ulrich
2021-05-06 f70acbb491c6421623cca57292a75f1820efad4d
src/de/uhilger/tango/api/StopServerHandler.java
@@ -22,6 +22,7 @@
import de.uhilger.tango.App;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Logger;
@@ -41,6 +42,8 @@
  public static final String RB_SERVER_STOPPED = "serverStopped";
  public static final String RB_MEDIAZ_END = "mediazEnd";
  private ResourceBundle rb;
  /**
   * Den Server geordnet herunterfahren und 
   * dann die Anwendung beenden.
@@ -52,13 +55,13 @@
  @Override
  public void handle(HttpExchange e) throws IOException {
    Logger.getLogger(StopServerHandler.class.getName()).info(e.getRequestURI().toString());
    String response = App.getRs(RB_SERVER_STOPPED);
    String response = getResString(RB_SERVER_STOPPED);
    e.sendResponseHeaders(200, response.length());
    OutputStream os = e.getResponseBody();
    os.write(response.getBytes());
    os.flush();
    os.close();
    logger.info(App.getRs(RB_STOPPING_SERVER));
    logger.info(getResString(RB_STOPPING_SERVER));
    e.getHttpContext().getServer().stop(1);
    Timer timer = new Timer();
    timer.schedule(new AppStopper(), 2000);
@@ -72,9 +75,15 @@
    @Override
    public void run() {
      logger.info(App.getRs(RB_MEDIAZ_END));
      App.stop();
      logger.info(getResString(RB_MEDIAZ_END));
      System.exit(0);
    }
  }
  protected String getResString(String key) {
    if(rb == null) {
      rb = ResourceBundle.getBundle(App.RB_NAME);
    }
    return rb.getString(key);
  }
}