Skip to content

Commit 1acc0d7

Browse files
committed
refactor: extract method to reduce complexity
1 parent 230b015 commit 1acc0d7

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

ors-api/src/main/java/org/heigit/ors/api/servlet/listeners/ORSInitContextListener.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,35 @@ public void contextInitialized(ServletContextEvent contextEvent) {
5656
copyDefaultConfigurationToFile(outputTarget);
5757
return;
5858
}
59-
new Thread(() -> {
60-
try {
61-
LOGGER.info("Initializing ORS...");
62-
graphService.setIsActivatingGraphs(true);
63-
RoutingProfileManager routingProfileManager = new RoutingProfileManager(engineProperties, AppInfo.GRAPH_VERSION);
64-
if (Boolean.TRUE.equals(engineProperties.getPreparationMode())) {
65-
LOGGER.info("Running in preparation mode, all enabled graphs are built, job is done.");
66-
if (environment.getActiveProfiles().length == 0) { // only exit if no active profile is set (i.e., not in test mode)
67-
RoutingProfileManagerStatus.setShutdown(true);
68-
}
69-
}
70-
if (RoutingProfileManagerStatus.isShutdown()) {
71-
System.exit(RoutingProfileManagerStatus.hasFailed() ? 1 : 0);
59+
new Thread(this::initializeORS, "ORS-Init").start();
60+
}
61+
62+
private void initializeORS() {
63+
try {
64+
LOGGER.info("Initializing ORS...");
65+
graphService.setIsActivatingGraphs(true);
66+
RoutingProfileManager routingProfileManager = new RoutingProfileManager(engineProperties, AppInfo.GRAPH_VERSION);
67+
if (Boolean.TRUE.equals(engineProperties.getPreparationMode())) {
68+
LOGGER.info("Running in preparation mode, all enabled graphs are built, job is done.");
69+
if (environment.getActiveProfiles().length == 0) { // only exit if no active profile is set (i.e., not in test mode)
70+
RoutingProfileManagerStatus.setShutdown(true);
7271
}
73-
for (RoutingProfile profile : routingProfileManager.getUniqueProfiles()) {
74-
ORSGraphManager orsGraphManager = profile.getGraphhopper().getOrsGraphManager();
75-
if (orsGraphManager != null && orsGraphManager.useGraphRepository()) {
76-
LOGGER.debug("Adding orsGraphManager for profile %s with encoder %s to GraphService".formatted(profile.getProfileConfiguration().getProfileName(), profile.getProfileConfiguration().getEncoderName()));
77-
graphService.addGraphManagerInstance(orsGraphManager);
78-
}
72+
}
73+
if (RoutingProfileManagerStatus.isShutdown()) {
74+
System.exit(RoutingProfileManagerStatus.hasFailed() ? 1 : 0);
75+
}
76+
for (RoutingProfile profile : routingProfileManager.getUniqueProfiles()) {
77+
ORSGraphManager orsGraphManager = profile.getGraphhopper().getOrsGraphManager();
78+
if (orsGraphManager != null && orsGraphManager.useGraphRepository()) {
79+
LOGGER.debug("Adding orsGraphManager for profile %s with encoder %s to GraphService".formatted(profile.getProfileConfiguration().getProfileName(), profile.getProfileConfiguration().getEncoderName()));
80+
graphService.addGraphManagerInstance(orsGraphManager);
7981
}
80-
} catch (Exception e) {
81-
LOGGER.warn("Unable to initialize ORS due to an unexpected exception: " + e);
82-
} finally {
83-
graphService.setIsActivatingGraphs(false);
8482
}
85-
}, "ORS-Init").start();
83+
} catch (Exception e) {
84+
LOGGER.warn("Unable to initialize ORS due to an unexpected exception: " + e);
85+
} finally {
86+
graphService.setIsActivatingGraphs(false);
87+
}
8688
}
8789

8890
public String configurationOutputTarget(EngineProperties engineProperties) {

0 commit comments

Comments
 (0)