1
|
package eu.dnetlib.clients.utils.ws;
|
2
|
|
3
|
import eu.dnetlib.common.rmi.BaseService;
|
4
|
import eu.dnetlib.enabling.is.store.rmi.ISStoreService;
|
5
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
6
|
import eu.dnetlib.utils.resolver.TransportConfiguration;
|
7
|
import org.apache.log4j.Logger;
|
8
|
|
9
|
import eu.dnetlib.api.DriverService;
|
10
|
import eu.dnetlib.utils.resolver.ServiceClientFactory;
|
11
|
import gr.uoa.di.driver.util.ServiceLocator;
|
12
|
|
13
|
/**
|
14
|
* This is an implementation of the service locator that uses a CNR service
|
15
|
* locator. The CNR service locator returns endpoints to services, so the job of
|
16
|
* this locator is to use the CNR locator to get service endpoint and use a
|
17
|
* ServiceClientFactory to create a client for this endpoint.
|
18
|
*
|
19
|
* It holds no cache of the located service. Any subsequent call to getService()
|
20
|
* will produce a new client. It is up to the caller to cache and refresh the
|
21
|
* result.
|
22
|
*
|
23
|
* @author <a href="mailto:antleb@di.uoa.gr">Antonis Lempesis</a>
|
24
|
*
|
25
|
* @param <S>
|
26
|
*/
|
27
|
public class CompatibilityServiceLocator<S extends DriverService> implements
|
28
|
ServiceLocator<S> {
|
29
|
|
30
|
private static Logger logger = Logger.getLogger(CompatibilityServiceLocator.class);
|
31
|
|
32
|
private UniqueServiceLocator serviceLocator;
|
33
|
|
34
|
/** The service class */
|
35
|
private Class<S> serviceClass = null;
|
36
|
|
37
|
TransportConfiguration transportConfiguration = null;
|
38
|
|
39
|
/** The factory used to create service clients */
|
40
|
private ServiceClientFactory<S> clientFactory = null;
|
41
|
|
42
|
@Override
|
43
|
public S getService() {
|
44
|
logger.debug("Locating service of type : "
|
45
|
+ this.serviceClass.getName());
|
46
|
S service = null;
|
47
|
|
48
|
try {
|
49
|
Class<? extends BaseService> endpointClass = (Class<? extends BaseService>) transportConfiguration.getEndpointClass(serviceClass);
|
50
|
|
51
|
Object endpoint = serviceLocator.getService(endpointClass);
|
52
|
|
53
|
logger.debug("Found service endpoint of type: "
|
54
|
+ endpoint.getClass().getName());
|
55
|
|
56
|
service = clientFactory.newClient(endpoint);
|
57
|
} catch (Exception e) {
|
58
|
logger.debug("Failed to find service", e);
|
59
|
}
|
60
|
|
61
|
return service;
|
62
|
}
|
63
|
|
64
|
public UniqueServiceLocator getServiceLocator() {
|
65
|
return serviceLocator;
|
66
|
}
|
67
|
|
68
|
public void setServiceLocator(UniqueServiceLocator serviceLocator) {
|
69
|
this.serviceLocator = serviceLocator;
|
70
|
}
|
71
|
|
72
|
public Class<S> getServiceClass() {
|
73
|
return serviceClass;
|
74
|
}
|
75
|
|
76
|
public void setServiceClass(Class<S> serviceClass) {
|
77
|
this.serviceClass = serviceClass;
|
78
|
}
|
79
|
|
80
|
public void setClientFactory(ServiceClientFactory<S> clientFactory) {
|
81
|
this.clientFactory = clientFactory;
|
82
|
}
|
83
|
|
84
|
public TransportConfiguration getTransportConfiguration() {
|
85
|
return transportConfiguration;
|
86
|
}
|
87
|
|
88
|
public void setTransportConfiguration(TransportConfiguration transportConfiguration) {
|
89
|
this.transportConfiguration = transportConfiguration;
|
90
|
}
|
91
|
}
|