1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.maxur.perfmodel.backend.service;
17
18 import org.jvnet.hk2.annotations.Contract;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 import javax.annotation.PostConstruct;
23 import javax.inject.Inject;
24
25
26
27
28
29
30
31
32 @Contract
33 public abstract class Application {
34
35 private static final Logger LOGGER = LoggerFactory.getLogger(Application.class);
36
37 @Inject
38 private WebServer webServer;
39
40 @Inject
41 private Database db;
42
43 @PostConstruct
44 public final void init() {
45 onInit();
46 }
47
48 public final void start() {
49 webServer.start();
50 onStart();
51 LOGGER.info("Performance Model Calculator Server is started");
52 }
53
54 public final void stop() {
55 webServer.stop();
56 db.stop();
57 onStop();
58 LOGGER.info("Performance Model Calculator Server is stopped");
59 }
60
61 public String version() {
62 return this.getClass().getPackage().getImplementationVersion();
63 }
64
65
66 protected final WebServer webServer() {
67 return webServer;
68 }
69
70
71
72
73
74
75 public abstract boolean isApplicable();
76
77
78
79
80 protected void onInit() {
81 }
82
83
84
85
86 protected void onStart() {
87 }
88
89
90
91
92 protected void onStop() {
93 }
94 }