Skip to content

Commit 23c3561

Browse files
committed
Enhance connection management by adding dynamic port handling; update Request and RouteInfo classes to include port information
1 parent 202a624 commit 23c3561

4 files changed

Lines changed: 40 additions & 6 deletions

File tree

src/main/java/fr/sandro642/github/spring/Application.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.springframework.boot.Banner;
55
import org.springframework.boot.SpringApplication;
66
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.web.reactive.config.WebFluxConfigurer;
78
import reactor.core.publisher.ConnectableFlux;
89
import reactor.core.publisher.Mono;
910
import reactor.core.scheduler.Schedulers;
@@ -16,13 +17,20 @@
1617
*/
1718

1819
@SpringBootApplication
19-
public class Application {
20+
public class Application implements WebFluxConfigurer {
2021

2122
// Singleton instance
2223
private static Application instance;
2324

25+
/**
26+
* ConnectLib instance for managing connections.
27+
*/
2428
private static final ConnectLib connectLib = new ConnectLib();
2529

30+
/**
31+
* Determines the port to use for the server, checking for a dynamic port first.
32+
* @return the port number as a string
33+
*/
2634
private String Dyn_Port() {
2735
if (connectLib.StoreAndRetrieve().get(connectLib.StoreAndRetrieve().DYNAMIC_PORT) != null) {
2836
return connectLib.StoreAndRetrieve().get(connectLib.StoreAndRetrieve().DYNAMIC_PORT).toString();
@@ -31,6 +39,18 @@ private String Dyn_Port() {
3139
}
3240
}
3341

42+
/**
43+
* Checks if the application is using a static port.
44+
* @return true if using a static port, false if using a dynamic port
45+
*/
46+
private boolean isStatic() {
47+
if (connectLib.StoreAndRetrieve().get(connectLib.StoreAndRetrieve().DYNAMIC_PORT) != null) {
48+
return false;
49+
} else {
50+
return true;
51+
}
52+
}
53+
3454
/**
3555
* Starts the Spring Boot application in a non-blocking manner.
3656
* @return a Mono that completes when the application has started
@@ -42,7 +62,7 @@ public Mono<Void> startApplication() {
4262
app.setLogStartupInfo(false); // désactive l'info de démarrage
4363
Map<String, Object> props = new HashMap<>();
4464
props.put("server.port", Dyn_Port()); // définit le port du serveur
45-
props.put("logging.level.root", "OFF"); // coupe l'affichage des logs
65+
props.put("logging.level.root", "OFF");
4666
app.setDefaultProperties(props);
4767
app.run();
4868

src/main/java/fr/sandro642/github/spring/controller/DataController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public static DataController getInstance() {
5858
@GetMapping("/status")
5959
public Map<String, Object> getStatus() {
6060
Map<String, Object> status = new HashMap<>();
61+
status.put("portInfo", connectLib.StoreAndRetrieve().get(connectLib.StoreAndRetrieve().DYNAMIC_PORT));
6162
status.put("isInitialized", connectLib.isInitialized());
6263
status.put("resourceType", connectLib.HookManager().getResourceType());
6364
return status;
@@ -73,7 +74,7 @@ public List<RouteInfo> getRoutes() {
7374
List<RouteInfo> result = new ArrayList<>();
7475
if (map != null) {
7576
for (Map.Entry<String, String> e : map.entrySet()) {
76-
result.add(new RouteInfo(e.getKey(), e.getValue()));
77+
result.add(new RouteInfo(connectLib.StoreAndRetrieve().get(connectLib.StoreAndRetrieve().DYNAMIC_PORT).toString(), e.getKey(), e.getValue()));
7778
}
7879
}
7980
return result;
@@ -108,7 +109,7 @@ public Request createRequest(String route, String branch) {
108109
}
109110
long id = requestIdCounter.incrementAndGet();
110111

111-
Request req = new Request(id, route, branch, "pending");
112+
Request req = new Request(connectLib.StoreAndRetrieve().get(connectLib.StoreAndRetrieve().DYNAMIC_PORT).toString(), id, route, branch, "pending");
112113
requestsMap.put(id, req);
113114
return req;
114115
}

src/main/java/fr/sandro642/github/spring/dto/Request.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
@JsonIgnoreProperties(ignoreUnknown = true)
1010
public class Request {
1111

12+
/**
13+
* Port information of the request.
14+
*/
15+
private String infoPort;
16+
1217
/**
1318
* Unique identifier for the request
1419
*/
@@ -36,12 +41,14 @@ public Request() {}
3641

3742
/**
3843
* Parameterized constructor
44+
* @param infoPort Port information of the request
3945
* @param id Unique identifier for the request
4046
* @param route Route associated with the request
4147
* @param branch Branch associated with the request
4248
* @param status Status of the request
4349
*/
44-
public Request(Long id, String route, String branch, String status) {
50+
public Request(String infoPort, Long id, String route, String branch, String status) {
51+
this.infoPort = infoPort;
4552
this.id = id;
4653
this.route = route;
4754
this.branch = branch;

src/main/java/fr/sandro642/github/spring/dto/RouteInfo.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
public class RouteInfo {
88

9+
/**
10+
* Port information of the route.
11+
*/
12+
private String infoPort;
13+
914
/**
1015
* Name of the route.
1116
*/
@@ -26,7 +31,8 @@ public RouteInfo() {}
2631
* @param name Name of the route
2732
* @param url URL of the route
2833
*/
29-
public RouteInfo(String name, String url) {
34+
public RouteInfo(String infoPort, String name, String url) {
35+
this.infoPort = infoPort;
3036
this.name = name;
3137
this.url = url;
3238
}

0 commit comments

Comments
 (0)