Skip to content

Commit f353abe

Browse files
committed
DEV-85 add try to run gRPC server from alternative path in ConsensysApps
1 parent e9a1969 commit f353abe

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

ShimmerDriver/src/main/java/com/shimmerresearch/grpc/GrpcBLERadioByteTools.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ public class GrpcBLERadioByteTools {
1616

1717
private Process runningProcess;
1818
String mExeName = "ShimmerBLEGrpc.exe";
19+
String mExePathAltWindows = System.getProperty("user.dir") + "/libs/ShimmerBLEGrpcWindows/" + mExeName;
1920
String mExePath = "C:\\Github\\Shimmer-C-API\\ShimmerAPI\\ShimmerBLEGrpc\\bin\\Debug\\" + mExeName; // Replace with the path to your .exe file
20-
//String exePath = "C:\\Users\\JC\\Desktop\\testgrpc\\ShimmerBLEGrpc.exe"; // Replace with the path to your .exe file
21+
// String exePath = "C:\\Users\\JC\\Desktop\\testgrpc\\ShimmerBLEGrpc.exe"; // Replace with the path to your .exe file
2122

2223
public GrpcBLERadioByteTools() {
2324

@@ -68,8 +69,6 @@ public boolean isExeRunning(String exeName) {
6869
}
6970
}
7071
public int startServer() throws Exception {
71-
72-
7372
int port = getFreePort();
7473

7574
System.out.println(port + " is free");
@@ -80,7 +79,23 @@ public int startServer() throws Exception {
8079
command.add(Integer.toString(port));
8180
ProcessBuilder processBuilder = new ProcessBuilder(command);
8281
processBuilder.redirectErrorStream(true); // Redirect standard error to the input stream
83-
runningProcess = processBuilder.start();
82+
83+
try {
84+
runningProcess = processBuilder.start();
85+
} catch(Exception e) {
86+
System.err.println("Failed to start gRPC server at default path -> " + mExePath);
87+
e.printStackTrace();
88+
89+
//Try alternative gRPC server path
90+
System.err.println("Trying alternative gRPC server path -> " + mExePathAltWindows);
91+
command = new ArrayList<>();
92+
command.add(mExePathAltWindows);
93+
command.add(Integer.toString(port));
94+
processBuilder = new ProcessBuilder(command);
95+
processBuilder.redirectErrorStream(true);
96+
runningProcess = processBuilder.start();
97+
}
98+
8499
Thread processThread = new Thread(() -> {
85100
try (BufferedReader reader = new BufferedReader(new InputStreamReader(runningProcess.getInputStream()))) {
86101
String line;
@@ -96,7 +111,6 @@ public int startServer() throws Exception {
96111
processThread.start();
97112
return port;
98113
// You can continue with other tasks here
99-
100114
}
101115

102116
public void stopServer() {

0 commit comments

Comments
 (0)