1
|
package eu.dnetlib.enabling.resultset.registry;
|
2
|
|
3
|
import java.util.UUID;
|
4
|
|
5
|
import org.springframework.beans.factory.annotation.Required;
|
6
|
|
7
|
import eu.dnetlib.enabling.resultset.listener.ResultSetListener;
|
8
|
import eu.dnetlib.rmi.common.ResultSetException;
|
9
|
import net.sf.ehcache.Cache;
|
10
|
import net.sf.ehcache.Element;
|
11
|
|
12
|
public class ResultSetRegistryImpl implements ResultSetRegistry {
|
13
|
|
14
|
private static final String RS_PREFIX = "rs-";
|
15
|
|
16
|
/**
|
17
|
* rsId -> ResultSet mappings are stored here.
|
18
|
*/
|
19
|
private Cache cache;
|
20
|
|
21
|
@Override
|
22
|
public String registerResultSet(final ResultSetListener<?> listener) {
|
23
|
final String newId = RS_PREFIX + UUID.randomUUID();
|
24
|
this.cache.put(new Element(newId, listener));
|
25
|
return newId;
|
26
|
}
|
27
|
|
28
|
@SuppressWarnings("unchecked")
|
29
|
@Override
|
30
|
public <T> ResultSetListener<T> getResultSetById(final String rsId) throws ResultSetException {
|
31
|
final Element elem = this.cache.get(rsId);
|
32
|
if (elem != null) {
|
33
|
final ResultSetListener<T> rs = (ResultSetListener<T>) elem.getObjectValue();
|
34
|
if (rs != null) { return rs; }
|
35
|
}
|
36
|
throw new ResultSetException("Missing resultset with id " + rsId);
|
37
|
}
|
38
|
|
39
|
@Override
|
40
|
public boolean contains(final String rsId) {
|
41
|
return this.cache.get(rsId) != null;
|
42
|
}
|
43
|
|
44
|
public Cache getCache() {
|
45
|
return this.cache;
|
46
|
}
|
47
|
|
48
|
@Required
|
49
|
public void setCache(final Cache cache) {
|
50
|
this.cache = cache;
|
51
|
}
|
52
|
|
53
|
}
|