1 | /* |
---|
2 | * To change this template, choose Tools | Templates |
---|
3 | * and open the template in the editor. |
---|
4 | */ |
---|
5 | package eu.clarin.sru.fcs.aggregator.sparam2; |
---|
6 | |
---|
7 | import eu.clarin.sru.client.SRUSearchRetrieveResponse; |
---|
8 | import eu.clarin.sru.client.fcs.DataViewKWIC; |
---|
9 | import java.util.ArrayList; |
---|
10 | import java.util.List; |
---|
11 | import java.util.concurrent.Future; |
---|
12 | import java.util.logging.Level; |
---|
13 | import java.util.logging.Logger; |
---|
14 | |
---|
15 | /** |
---|
16 | * Represents the results of a SRU search-retrieve operation request. It |
---|
17 | * contains the endpoint and corpus (if specified in the request) to which a |
---|
18 | * request was sent, and the corresponding SRU search-retrieve response. |
---|
19 | * |
---|
20 | * @author Yana Panchenko |
---|
21 | */ |
---|
22 | public class SearchResult2 { |
---|
23 | |
---|
24 | //private Endpoint endpoint; |
---|
25 | private Corpus2 corpus; |
---|
26 | private Future<SRUSearchRetrieveResponse> futureResponse; |
---|
27 | private SRUSearchRetrieveResponse response; |
---|
28 | private List<DataViewKWIC> dataKWIC = new ArrayList<DataViewKWIC>(); |
---|
29 | |
---|
30 | private static final Logger logger = Logger.getLogger(SearchResult2.class.getName()); |
---|
31 | |
---|
32 | public List<DataViewKWIC> getDataKWIC() { |
---|
33 | return dataKWIC; |
---|
34 | } |
---|
35 | |
---|
36 | public void addKWIC(DataViewKWIC kw) { |
---|
37 | this.dataKWIC.add(kw); |
---|
38 | } |
---|
39 | |
---|
40 | |
---|
41 | public SearchResult2(Corpus2 corpus) { |
---|
42 | this.corpus = corpus; |
---|
43 | } |
---|
44 | |
---|
45 | public Corpus2 getCorpus() { |
---|
46 | return corpus; |
---|
47 | } |
---|
48 | |
---|
49 | public void setFutureResponse(Future<SRUSearchRetrieveResponse> futureResponse) { |
---|
50 | this.futureResponse = futureResponse; |
---|
51 | } |
---|
52 | |
---|
53 | public void setResponse(SRUSearchRetrieveResponse response) { |
---|
54 | this.response = response; |
---|
55 | } |
---|
56 | |
---|
57 | public SRUSearchRetrieveResponse getResponse() { |
---|
58 | return response; |
---|
59 | } |
---|
60 | |
---|
61 | public boolean hasCorpusHandler() { |
---|
62 | if (corpus != null && corpus.getHandle() != null) { |
---|
63 | return true; |
---|
64 | } |
---|
65 | return false; |
---|
66 | } |
---|
67 | |
---|
68 | public void cancelWaitingForResponse() { |
---|
69 | futureResponse.cancel(true); |
---|
70 | } |
---|
71 | |
---|
72 | public boolean isWaitingForResponse() { |
---|
73 | if (futureResponse == null) { |
---|
74 | return false; |
---|
75 | } else if (futureResponse.isDone()) { |
---|
76 | return false; |
---|
77 | } else { |
---|
78 | return true; |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | public void consumeResponse() { |
---|
83 | |
---|
84 | try { |
---|
85 | if (futureResponse != null) { |
---|
86 | response = futureResponse.get(); |
---|
87 | } |
---|
88 | } catch (Exception ex) { |
---|
89 | logger.log(Level.SEVERE, "Error consuming response from {0} {1} {2} {3}", |
---|
90 | new Object[]{corpus.getEndpointUrl(), corpus, ex.getClass().getName(), ex.getMessage()}); |
---|
91 | } |
---|
92 | } |
---|
93 | } |
---|