Skip to content

Commit 9031aa7

Browse files
authored
Log when HTTP server can't be started (also shows alert in UI) (#758)
* Log when HTTP server can't be started (also shows alert in UI) Change default port from 8080 to 2084 * Ask user to continue without HTTP functionality
1 parent a8db0fa commit 9031aa7

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

core/src/main/java/edu/wpi/grip/core/Main.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import edu.wpi.grip.core.events.ExceptionClearedEvent;
44
import edu.wpi.grip.core.events.ExceptionEvent;
5+
import edu.wpi.grip.core.exception.GripServerException;
56
import edu.wpi.grip.core.http.GripServer;
67
import edu.wpi.grip.core.http.HttpPipelineSwitcher;
78
import edu.wpi.grip.core.operations.CVOperations;
@@ -10,6 +11,7 @@
1011
import edu.wpi.grip.core.serialization.Project;
1112
import edu.wpi.grip.core.settings.SettingsProvider;
1213
import edu.wpi.grip.core.sources.GripSourcesHardwareModule;
14+
import edu.wpi.grip.core.util.SafeShutdown;
1315

1416
import com.google.common.eventbus.EventBus;
1517
import com.google.common.eventbus.Subscribe;
@@ -75,7 +77,12 @@ public void start(String[] args) throws IOException, InterruptedException {
7577
// argument is already taken. Since we have to have the server running to handle remotely
7678
// loading pipelines and uploading images, as well as potential HTTP publishing operations,
7779
// this will cause the program to exit.
78-
gripServer.start();
80+
try {
81+
gripServer.start();
82+
} catch (GripServerException e) {
83+
logger.log(Level.SEVERE, "The HTTP server could not be started", e);
84+
SafeShutdown.exit(1);
85+
}
7986

8087
if (pipelineRunner.state() == Service.State.NEW) {
8188
// Loading a project will start the pipeline, so only start it if a project wasn't specified

core/src/main/java/edu/wpi/grip/core/http/GripServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public enum State {
109109
/**
110110
* The default port the server should run on.
111111
*/
112-
public static final int DEFAULT_PORT = 8080;
112+
public static final int DEFAULT_PORT = 2084;
113113

114114
/**
115115
* The lowest valid TCP port number.

core/src/main/java/edu/wpi/grip/core/util/SafeShutdown.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
44

5+
import java.util.logging.Logger;
6+
57
import javax.annotation.Nullable;
68

79
/**
@@ -45,6 +47,7 @@ public static void exit(int statusCode, @Nullable PreSystemExitHook hook) {
4547
hook.run();
4648
}
4749
} finally {
50+
Logger.getLogger(SafeShutdown.class.getName()).info("Exiting GRIP");
4851
System.exit(statusCode);
4952
}
5053

ui/src/main/java/edu/wpi/grip/ui/Main.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import edu.wpi.grip.core.GripFileModule;
55
import edu.wpi.grip.core.PipelineRunner;
66
import edu.wpi.grip.core.events.UnexpectedThrowableEvent;
7+
import edu.wpi.grip.core.exception.GripServerException;
78
import edu.wpi.grip.core.http.GripServer;
89
import edu.wpi.grip.core.http.HttpPipelineSwitcher;
910
import edu.wpi.grip.core.operations.CVOperations;
@@ -35,6 +36,8 @@
3536
import javafx.fxml.FXMLLoader;
3637
import javafx.scene.Parent;
3738
import javafx.scene.Scene;
39+
import javafx.scene.control.Alert;
40+
import javafx.scene.control.ButtonType;
3841
import javafx.scene.image.Image;
3942
import javafx.scene.text.Font;
4043
import javafx.stage.Stage;
@@ -145,7 +148,20 @@ public void start(Stage stage) throws IOException {
145148
// argument is already taken. Since we have to have the server running to handle remotely
146149
// loading pipelines and uploading images, as well as potential HTTP publishing operations,
147150
// this will cause the program to exit.
148-
server.start();
151+
try {
152+
server.start();
153+
} catch (GripServerException e) {
154+
logger.log(Level.SEVERE, "The HTTP server could not be started", e);
155+
Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "", ButtonType.YES, ButtonType.NO);
156+
alert.setTitle("The HTTP server could not be started");
157+
alert.setHeaderText("The HTTP server could not be started");
158+
alert.setContentText(
159+
"This is normally caused by the network port being used by another process.\n\n"
160+
+ "HTTP sources and operations will not work until GRIP is restarted. "
161+
+ "Continue without HTTP functionality anyway?"
162+
);
163+
alert.showAndWait().filter(ButtonType.NO::equals).ifPresent(bt -> SafeShutdown.exit(1));
164+
}
149165
}
150166

151167
public void stop() {

0 commit comments

Comments
 (0)