Inspector | Message | Severity | Location |
---|---|---|---|
Java Inspector 048 | Copyrights information should be present in each file. | 1 | |
Java Inspector 089 | Undocumented top level type | 2 | 3:1 |
Java Inspector 089 | Undocumented exception ConfigurationException | 2 | 23:9 |
Java Inspector 089 | Undocumented method | 2 | 38:9 |
Java Inspector 089 | Undocumented exception ConfigurationException | 2 | 45:9 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 24:22 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 25:29 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 26:66 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 49:50 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 53:34 |
1package biz.hammurapi.config;
2
3public abstract class ServiceBase extends ComponentBase implements Service {
4
5 private String status;
6
7 private ThreadLocal prevServiceTL = new ThreadLocal();
8
9 ServiceBase prevService;
10 ServiceBase nextService;
11
12 /**
13 * Services shall implement initialization sequence in this method.
14 * @throws ConfigurationException
15 */
16 protected abstract void startInternal() throws ConfigurationException;
17
18 /**
19 * This implementation can be invoked multiple times. ServiceBase class maintains internal started flag to ensure
20 * that startInternal() method is invoked only once. The naming bus invokes this method every time before returning
21 * service from get() method.
22 */
23 public final synchronized void start() throws ConfigurationException {
24 if (!"Started".equals(status)) {
25 if ("Starting".equals(status)) {
26 throw new ConfigurationException("Circular dependency: start() method reentered by the same thread");
27 }
28 startInternal();
29
30 prevService = (ServiceBase) prevServiceTL.get();
31 prevServiceTL.set(this);
32 if (prevService!=null) {
33 prevService.nextService=this;
34 }
35 }
36 }
37
38 protected abstract void stopInternal() throws ConfigurationException;
39
40 /**
41 * Invokes stopInternal if all dependent services has been stopped.
42 * Otherwise goes into "stoppable" state. When stops, also stops all
43 * stoppable previous services.
44 */
45 public final synchronized void stop() throws ConfigurationException {
46 if (nextService==null || nextService.status==null) {
47 stopInternal();
48 status = null;
49 if (prevService!=null && "Stoppable".equals(prevService.status)) {
50 prevService.stop();
51 }
52 } else {
53 status = "Stoppable";
54 }
55 }
56
57}
58