Skip to content

Commit 2c6e6a8

Browse files
committed
refactor
remove some low-value code ceremony and simplify
1 parent 7639add commit 2c6e6a8

File tree

5 files changed

+21
-338
lines changed

5 files changed

+21
-338
lines changed

src/main/java/de/rwth/idsg/steve/Application.java

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,25 @@
1818
*/
1919
package de.rwth.idsg.steve;
2020

21+
import de.rwth.idsg.steve.utils.LogFileRetriever;
2122
import lombok.extern.slf4j.Slf4j;
2223
import org.joda.time.DateTime;
2324
import org.joda.time.DateTimeZone;
2425

26+
import java.nio.file.Path;
27+
import java.util.Optional;
2528
import java.util.TimeZone;
2629

2730
/**
2831
* @author Sevket Goekay <[email protected]>
2932
* @since 14.01.2015
3033
*/
3134
@Slf4j
32-
public class Application implements ApplicationStarter, AutoCloseable {
35+
public class Application {
3336

34-
private final ApplicationStarter delegate;
37+
private final JettyServer server = new JettyServer();
3538

36-
public Application() {
39+
public static void main(String[] args) throws Exception {
3740
// For Hibernate validator
3841
System.setProperty("org.jboss.logging.provider", "slf4j");
3942

@@ -44,50 +47,38 @@ public Application() {
4447
DateTimeZone.setDefault(DateTimeZone.forID(sc.getTimeZoneId()));
4548
log.info("Date/time zone of the application is set to {}. Current date/time: {}", sc.getTimeZoneId(), DateTime.now());
4649

47-
switch (sc.getProfile()) {
48-
case DEV:
49-
case TEST:
50-
delegate = new SteveDevStarter();
51-
break;
52-
case PROD:
53-
delegate = new SteveProdStarter();
54-
break;
55-
default:
56-
throw new RuntimeException("Unexpected profile");
50+
Optional<Path> path = LogFileRetriever.INSTANCE.getPath();
51+
boolean loggingToFile = path.isPresent();
52+
if (loggingToFile) {
53+
System.out.println("Log file: " + path.get().toAbsolutePath());
5754
}
58-
}
5955

60-
public static void main(String[] args) throws Exception {
61-
Application app = null;
56+
Application app = new Application();
57+
6258
try {
63-
app = new Application();
6459
app.start();
6560
app.join();
6661
} catch (Exception e) {
6762
log.error("Application failed to start", e);
68-
if (app != null) {
69-
app.stop();
63+
64+
if (loggingToFile) {
65+
System.err.println("Application failed to start");
66+
e.printStackTrace();
7067
}
68+
69+
app.stop();
7170
}
7271
}
7372

74-
@Override
7573
public void start() throws Exception {
76-
delegate.start();
74+
server.start();
7775
}
7876

79-
@Override
8077
public void join() throws Exception {
81-
delegate.join();
78+
server.join();
8279
}
8380

84-
@Override
8581
public void stop() throws Exception {
86-
delegate.stop();
87-
}
88-
89-
@Override
90-
public void close() throws Exception {
91-
stop();
82+
server.stop();
9283
}
9384
}

src/main/java/de/rwth/idsg/steve/ApplicationStarter.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/main/java/de/rwth/idsg/steve/SteveDevStarter.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/main/java/de/rwth/idsg/steve/SteveProdCondition.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)