Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.englishtown.vertx.solr.streams.impl;
  
 
 
 public abstract class JsonReadStreamBase implements ReadStream<JsonObject> {
 
     private static final Logger logger = LoggerFactory.getLogger(JsonReadStreamBase.class);
     private final SolrService solrService;
 
     private VertxSolrQuery query;
     private QueryOptions options;
 
     private Handler<VoidendHandler;
     private Handler<JsonObjectdataHandler;
     private Handler<ThrowableexceptionHandler;
 
     private boolean queryRunning;
     private boolean paused;
     private boolean completed;
 
     @Inject
     protected JsonReadStreamBase(SolrService solrService) {
         this. = solrService;
     }

    
This is a required parameter.

Parameters:
query SolrQuery object which holds the query data
Returns:
Returns this
 
     public JsonReadStreamBase solrQuery(VertxSolrQuery query) {
         this. = query;
         return this;
     }

    
Optional param

Parameters:
options Optional query options
Returns:
Returns this
 
     public JsonReadStreamBase queryOptions(QueryOptions options) {
         this. = options;
         return this;
     }

    

Parameters:
endHandler Handler called when the pump has finished
Returns:
Returns this
 
     @Override
     public JsonReadStreamBase endHandler(Handler<VoidendHandler) {
         this. = endHandler;
         return this;
     }

    
This method starts the SolrPump. It takes a dataHandler, which is passed in from the Pump, sets this class's dataHandler equal to the one passed in and starts the Solr query and begins running through the pagination loops

Parameters:
handler Handler responsible for writing data to the stream
Returns:
Returns this
 
     @Override
     public JsonReadStreamBase handler(Handler<JsonObjecthandler) {
         this. = handler;
         if (!) {
             if ( != null) {
                 doQuery();
             }
         }
         return this;
     }
 
     @Override
     public JsonReadStreamBase pause() {
         this. = true;
         return this;
     }
 
     @Override
     public JsonReadStreamBase resume() {
         if () {
              = false;
            if ( != null) {
                doQuery();
            }
        }
        return this;
    }
    @Override
        this. = handler;
        return this;
    }


    
Set the query start point for pagination. Typically either the start or cursorMark param.

Parameters:
query SolrQuery object
Returns:
ReadJsonStreamBase object
    protected abstract JsonReadStreamBase setQueryStart(SolrQuery query);
    private void doQuery() {
        if ( == null) {
            handleException(new IllegalStateException("Please ensure you have set the query object"));
        }
        // Don't send a second query if already running or completed
        if ( || ) {
            return;
        }
         = true;
        setQueryStart();
        // send this json message over the event bus with a reply handler.
        .query(result -> {
             = false;
            try {
                if (result.succeeded()) {
                    handleResults(result.result());
                } else {
                    handleException(result.cause());
                }
            } catch (Throwable t) {
                handleException(t);
            }
        });
    }
    private void handleException(Throwable t) {
        if ( != null) {
            .handle(t);
        } else {
            .error("Unhandled Exception"t);
        }
    }
    protected abstract boolean isComplete(JsonObject reply);

    
Pagination looping logic - continuously runs through a doQuery loop until all results have been streamed

Parameters:
results JsonObject query reply from Solr
    protected void handleResults(JsonObject results) {
        if ( != null) {
            .handle(results);
        }
        if (isComplete(results)) {
             = true;
            if ( != null) {
                .handle(null);
            }
        } else {
            if (! &&  != null) {
                doQuery();
            }
        }
    }
New to GrepCode? Check out our FAQ X