Commit e250c784 authored by Stefan Michel's avatar Stefan Michel

Server wird jetzt sauber runtergefahren

parent 29159520
#role=tutor or student
role=student
role=tutor
tutorhost=localhost
tutorport=3579
\ No newline at end of file
......@@ -4,11 +4,13 @@ import controller.HamsterController;
import controller.IOController;
import controller.TerrainController;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.stage.Stage;
import model.DatabaseManager;
import model.Terrain;
import model.ThreadManager;
import network.NetworkManager;
import view.MainViewCreationFX;
import javax.sound.sampled.AudioInputStream;
......@@ -25,7 +27,8 @@ public class Main extends Application {
private DatabaseManager databaseManager;
public static final List<String> activePrograms = new ArrayList<>();
private IOController ioController;
ThreadManager threadManager;
private ThreadManager threadManager;
private NetworkManager networkManager = NetworkManager.getInstance();
public static void main(String[] args) {
launch(args);
......@@ -83,6 +86,7 @@ public class Main extends Application {
primaryStage.setOnCloseRequest(event -> {
activePrograms.remove(terrain.getHamsterName());
ioController.saveFile(terrain.getHamsterName());
networkManager.unbind();
});
activePrograms.add(terrain.getHamsterName());
ioController.compile(terrain.getHamsterName());
......
......@@ -2,6 +2,7 @@ package network;
import controller.PropertiesManager;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
......@@ -17,6 +18,7 @@ public class NetworkManager {
private final PropertiesManager propertiesManager = PropertiesManager.getInstance();
private Student student;
private Tutor tutor;
private Registry registry;
private NetworkManager() {
String role = propertiesManager.getString("role");
......@@ -42,7 +44,7 @@ public class NetworkManager {
try {
this.tutor = new Tutor();
LocateRegistry.createRegistry(port);
Registry registry = LocateRegistry.getRegistry(port);
registry = LocateRegistry.getRegistry(port);
registry.rebind("Tutor", tutor);
} catch (RemoteException e) {
e.printStackTrace();
......@@ -69,4 +71,17 @@ public class NetworkManager {
tutor.addAnswer(codeTerrain);
}
// clean server shutdown
public void unbind() {
if (tutor != null) {
try {
registry.unbind("Tutor");
Tutor.unexportObject(tutor, true);
} catch (RemoteException e) {
e.printStackTrace();
} catch (NotBoundException e) {
e.printStackTrace();
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment