Example usage for org.apache.solr.client.solrj.response QueryResponse QueryResponse

List of usage examples for org.apache.solr.client.solrj.response QueryResponse QueryResponse

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.response QueryResponse QueryResponse.

Prototype

public QueryResponse(SolrClient solrClient) 

Source Link

Usage

From source file:com.ngdata.hbaseindexer.indexer.FusionPipelineClient.java

License:Apache License

public QueryResponse queryFusion(SolrQuery query) throws Exception {

    int requestId = requestCounter.incrementAndGet();

    ArrayList<String> mutable = getAvailableEndpoints();
    String endpoint = mutable.get(0);

    FusionSession fusionSession = null;/*from w  w w . j av a  2  s  . c  om*/
    long currTime = System.nanoTime();
    synchronized (this) {
        fusionSession = sessions.get(endpoint);

        // ensure last request within the session timeout period, else reset the session
        if (fusionSession == null || (currTime - fusionSession.sessionEstablishedAt) > maxNanosOfInactivity) {
            log.info("Fusion session is likely expired (or soon will be) for endpoint " + endpoint + ", "
                    + "pre-emptively re-setting this session before processing request " + requestId);
            fusionSession = resetSession(endpoint);
            if (fusionSession == null)
                throw new IllegalStateException("Failed to re-connect to " + endpoint
                        + " after session loss when processing request " + requestId);
        }
    }

    if (fusionSession.solrClient == null) {
        fusionSession.solrClient = new HttpSolrClient(endpoint, httpClient);
    }
    QueryRequest qreq = new QueryRequest(query);
    qreq.setResponseParser(new XMLResponseParser());
    QueryResponse qr = new QueryResponse((SolrClient) fusionSession.solrClient);
    qr.setResponse(fusionSession.solrClient.request(qreq));
    return qr;
}