1
|
package eu.dnetlib.services;
|
2
|
|
3
|
import java.util.HashMap;
|
4
|
import java.util.Map;
|
5
|
|
6
|
import javax.annotation.PostConstruct;
|
7
|
|
8
|
import org.apache.commons.logging.Log;
|
9
|
import org.apache.commons.logging.LogFactory;
|
10
|
import org.springframework.context.Lifecycle;
|
11
|
import org.springframework.web.bind.annotation.RequestMapping;
|
12
|
|
13
|
import eu.dnetlib.enabling.annotations.DnetService;
|
14
|
import eu.dnetlib.enabling.annotations.DnetServiceType;
|
15
|
import eu.dnetlib.exceptions.DnetGenericException;
|
16
|
|
17
|
public abstract class BaseService implements Lifecycle {
|
18
|
|
19
|
private static final Log log = LogFactory.getLog(BaseService.class);
|
20
|
|
21
|
private boolean started = false;
|
22
|
|
23
|
private String profileId;
|
24
|
|
25
|
private Map<String, String> serviceProperties = new HashMap<>();
|
26
|
|
27
|
private Map<String, String> extraProtocols = new HashMap<>();
|
28
|
|
29
|
private DnetServiceType serviceType;
|
30
|
|
31
|
@PostConstruct
|
32
|
public void init() throws DnetGenericException {
|
33
|
if (getClass().isAnnotationPresent(DnetService.class)) {
|
34
|
serviceType = getClass().getAnnotation(DnetService.class).value();
|
35
|
} else {
|
36
|
throw new DnetGenericException("A required annotation is missing (@DnetService) in class " + getClass());
|
37
|
}
|
38
|
}
|
39
|
|
40
|
@RequestMapping("identify")
|
41
|
public String identify() {
|
42
|
return getClass().getName();
|
43
|
}
|
44
|
|
45
|
@Override
|
46
|
public void start() {
|
47
|
log.info("Starting service " + identify());
|
48
|
if (started) {
|
49
|
log.warn("Service " + this + "already started, check bean initializations!");
|
50
|
}
|
51
|
started = true;
|
52
|
}
|
53
|
|
54
|
@Override
|
55
|
public boolean isRunning() {
|
56
|
log.debug("called isRunning " + this);
|
57
|
return false;
|
58
|
}
|
59
|
|
60
|
@Override
|
61
|
public void stop() {
|
62
|
log.info("Stopping service " + this);
|
63
|
}
|
64
|
|
65
|
public String getProfileId() {
|
66
|
return profileId;
|
67
|
}
|
68
|
|
69
|
public void setProfileId(final String profileId) {
|
70
|
this.profileId = profileId;
|
71
|
}
|
72
|
|
73
|
public Map<String, String> getServiceProperties() {
|
74
|
return serviceProperties;
|
75
|
}
|
76
|
|
77
|
public void setServiceProperties(final Map<String, String> serviceProperties) {
|
78
|
this.serviceProperties = serviceProperties;
|
79
|
}
|
80
|
|
81
|
public Map<String, String> getExtraProtocols() {
|
82
|
return extraProtocols;
|
83
|
}
|
84
|
|
85
|
public void setExtraProtocols(final Map<String, String> extraProtocols) {
|
86
|
this.extraProtocols = extraProtocols;
|
87
|
}
|
88
|
|
89
|
public DnetServiceType getServiceType() {
|
90
|
return serviceType;
|
91
|
}
|
92
|
|
93
|
public void setServiceType(final DnetServiceType serviceType) {
|
94
|
this.serviceType = serviceType;
|
95
|
}
|
96
|
}
|