source: SRUAggregator/trunk/src/main/java/eu/clarin/sru/fcs/aggregator/data/SearchResult.java @ 2527

Last change on this file since 2527 was 2527, checked in by yana, 11 years ago

Logging organized, progress info about waiting for search results added, SRUThreadedClient is one per application now.

File size: 2.7 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package eu.clarin.sru.fcs.aggregator.data;
6
7import eu.clarin.sru.client.SRUSearchRetrieveResponse;
8import eu.clarin.sru.client.fcs.DataViewKWIC;
9import java.util.ArrayList;
10import java.util.List;
11import java.util.concurrent.Future;
12import java.util.logging.Level;
13import 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 */
22public class SearchResult {
23
24    private Endpoint endpoint;
25    private Corpus 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(SearchResult.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 SearchResult(Object nodeData) {
42        if (nodeData instanceof Endpoint) {
43            endpoint = (Endpoint) nodeData;
44        } else {
45            corpus = (Corpus) nodeData;
46            endpoint = corpus.getEndpoint();
47        }
48    }
49
50    public Endpoint getEndpoint() {
51        return endpoint;
52    }
53
54    public Corpus getCorpus() {
55        return corpus;
56    }
57
58    public void setFutureResponse(Future<SRUSearchRetrieveResponse> futureResponse) {
59        this.futureResponse = futureResponse;
60    }
61
62    public void setResponse(SRUSearchRetrieveResponse response) {
63        this.response = response;
64    }
65
66    public SRUSearchRetrieveResponse getResponse() {
67        return response;
68    }
69
70    public boolean hasCorpusHandler() {
71        if (corpus != null && corpus.getValue() != null) {
72            return true;
73        }
74        return false;
75    }
76
77    public void cancelWaitingForResponse() {
78        futureResponse.cancel(true);
79    }
80
81    public boolean isWaitingForResponse() {
82        if (futureResponse == null) {
83            return false;
84        } else if (futureResponse.isDone()) {
85            return false;
86        } else {
87            return true;
88        }
89    }
90
91    public void consumeResponse() {
92        try {
93            if (futureResponse != null) {
94                response = futureResponse.get();
95            }
96        } catch (Exception ex) {
97            logger.log(Level.SEVERE, "Error consuming response from {0} {1}\n {2}\n {3}", 
98                    new Object[]{endpoint.getUrl(), corpus, ex.getClass().getName(), ex.getMessage()});
99        }
100    }
101}
Note: See TracBrowser for help on using the repository browser.