1
|
package gr.uoa.di.driver.app;
|
2
|
|
3
|
import javax.xml.ws.Endpoint;
|
4
|
|
5
|
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService;
|
6
|
import org.apache.log4j.Logger;
|
7
|
|
8
|
import eu.dnetlib.domain.EPR;
|
9
|
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryException;
|
10
|
import eu.dnetlib.enabling.tools.registration.ValidatingServiceRegistrationManagerImpl;
|
11
|
import eu.dnetlib.soap.EndpointReferenceBuilder;
|
12
|
import eu.dnetlib.utils.EPRUtils;
|
13
|
|
14
|
/**
|
15
|
* A service registration manager that sets the epr to the service and also
|
16
|
* calls its init() method, after registering it to the IS.
|
17
|
*
|
18
|
* @author antleb
|
19
|
*
|
20
|
*/
|
21
|
public class InitialiazingServiceRegistrationManager extends ValidatingServiceRegistrationManagerImpl {
|
22
|
private static Logger logger = Logger.getLogger(InitialiazingServiceRegistrationManager.class);
|
23
|
private EndpointReferenceBuilder<Endpoint> eprBuilder = null;
|
24
|
private boolean removeRegistration = true;
|
25
|
|
26
|
public void tick() {
|
27
|
synchronized (this.getRegistrator()) {
|
28
|
DriverServiceImpl service = (DriverServiceImpl) this.getService();
|
29
|
|
30
|
if (getState() == State.REGISTERED && !service.isInititialized()) {
|
31
|
logger.debug("Service is registered and unitialized. Initializing.");
|
32
|
|
33
|
EPR epr = this.createEPR();
|
34
|
|
35
|
epr.setParameter("serviceId", this.getProfileId());
|
36
|
service.setServiceEPR(epr);
|
37
|
|
38
|
service.init();
|
39
|
}
|
40
|
}
|
41
|
|
42
|
super.tick();
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* Removes the service registration from the IS.
|
47
|
*/
|
48
|
public void destroy() {
|
49
|
try {
|
50
|
if (removeRegistration) {
|
51
|
logger.debug("Removing service registration");
|
52
|
|
53
|
this.getRegistrator().getServiceLocator().getService(ISRegistryService.class)
|
54
|
.deleteProfile(this.getProfileId());
|
55
|
}
|
56
|
} catch (ISRegistryException e) {
|
57
|
logger.error("Error removing service registration", e);
|
58
|
}
|
59
|
}
|
60
|
|
61
|
private EPR createEPR() {
|
62
|
return EPRUtils.createEPR(this.eprBuilder, this.getEndpoint());
|
63
|
}
|
64
|
|
65
|
public EndpointReferenceBuilder<Endpoint> getEprBuilder() {
|
66
|
return eprBuilder;
|
67
|
}
|
68
|
|
69
|
public void setEprBuilder(EndpointReferenceBuilder<Endpoint> eprBuilder) {
|
70
|
this.eprBuilder = eprBuilder;
|
71
|
}
|
72
|
|
73
|
public boolean isRemoveRegistration() {
|
74
|
return removeRegistration;
|
75
|
}
|
76
|
|
77
|
public void setRemoveRegistration(boolean removeRegistration) {
|
78
|
this.removeRegistration = removeRegistration;
|
79
|
}
|
80
|
}
|