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