1
|
package eu.dnetlib.msro.openaireplus.workflows.nodes.index;
|
2
|
|
3
|
import java.util.Queue;
|
4
|
|
5
|
import com.googlecode.sarasvati.Arc;
|
6
|
import com.googlecode.sarasvati.NodeToken;
|
7
|
import eu.dnetlib.msro.rmi.MSROException;
|
8
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
9
|
import org.apache.commons.logging.Log;
|
10
|
import org.apache.commons.logging.LogFactory;
|
11
|
|
12
|
/**
|
13
|
* SwitchIndexesJobNode guides the index switches on all search services whose ids are in the queue available in the parameter named 'searchService_ids'.
|
14
|
*
|
15
|
* @author claudio, alessia
|
16
|
* @see eu.dnetlib.msro.openaireplus.workflows.nodes.index.FindSearchServicesJobNode
|
17
|
* @see eu.dnetlib.msro.openaireplus.workflows.nodes.index.SwitchIndexJobNode
|
18
|
*/
|
19
|
public class SwitchIndexesJobNode extends SimpleJobNode {
|
20
|
|
21
|
private static final Log log = LogFactory.getLog(SwitchIndexesJobNode.class);
|
22
|
|
23
|
@Override
|
24
|
protected String execute(final NodeToken token) throws Exception {
|
25
|
Queue<String> q = (Queue<String>) token.getEnv().getTransientAttribute("searchService_ids");
|
26
|
log.debug("Got the searchService_ids queue: " + q.toString());
|
27
|
if (q == null) throw new MSROException("Transient param 'searchService_ids' with queue of string could not be found");
|
28
|
if (q.isEmpty()) {
|
29
|
log.info("searchService_ids queue consumed, now ending cycle");
|
30
|
return Arc.DEFAULT_ARC;
|
31
|
} else {
|
32
|
//we have something to do: setting the xqueryForServiceIdParam for the SwitchIndexJobNode
|
33
|
String id = q.poll();
|
34
|
log.debug("Polled id: " + id);
|
35
|
log.debug("And now the queue is " + q);
|
36
|
token.getEnv().setAttribute("search_service_ID", id);
|
37
|
log.debug("Asking to switch on profile with id: " + id);
|
38
|
//updating the queue for next iteration
|
39
|
token.getEnv().setTransientAttribute("searchService_ids", q);
|
40
|
return "switch";
|
41
|
}
|
42
|
}
|
43
|
|
44
|
}
|