/*
|
Calypso - Media Player Remote Control via HTTP for Raspberry Pi
|
Copyright (C) 2021-2023 Ulrich Hilger
|
|
This program is free software: you can redistribute it and/or modify
|
it under the terms of the GNU Affero General Public License as
|
published by the Free Software Foundation, either version 3 of the
|
License, or (at your option) any later version.
|
|
This program is distributed in the hope that it will be useful,
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
GNU Affero General Public License for more details.
|
|
You should have received a copy of the GNU Affero General Public License
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
*/
|
|
package de.uhilger.calypso.actor;
|
|
import com.sun.net.httpserver.HttpContext;
|
import java.util.Timer;
|
import java.util.TimerTask;
|
import java.util.logging.Logger;
|
|
/**
|
* Ein HTTP-Handler zum Stoppen der Anwendung
|
*
|
* @author Ulrich Hilger
|
*/
|
public class StopServerActor {
|
|
public void run(HttpContext thisContext) {
|
Logger.getLogger(StopServerActor.class.getName()).info("Server wird gestoppt..");
|
thisContext.getServer().stop(1); // diesen Server stoppen
|
Timer timer = new Timer();
|
timer.schedule(new AppStopper(), 1500); // die App auch beenden
|
}
|
|
/**
|
* Die Klasse AppStopper ermöglicht das asnychrone bzw.
|
* zeitgesteuerte Stoppen der Anwendung.
|
*/
|
class AppStopper extends TimerTask {
|
|
@Override
|
public void run() {
|
Logger.getLogger(StopServerActor.class.getName()).info("Calypso beendet.");
|
System.exit(0);
|
}
|
}
|
|
}
|