public RpcOutcomeListener<QueryId> getWrappedListener(UserResultsListener listener){
return new SubmissionListener(listener);
}
public void batchArrived(ByteBuf pBody, ByteBuf dBody) throws RpcException {
final QueryResult result = RpcBus.get(pBody, QueryResult.PARSER);
final QueryResultBatch batch = new QueryResultBatch(result, dBody);
UserResultsListener l = resultsListener.get(result.getQueryId());
boolean failed = batch.getHeader().getQueryState() == QueryState.FAILED;
// logger.debug("For QueryId [{}], retrieved result listener {}", result.getQueryId(), l);
if (l == null) {
BufferingListener bl = new BufferingListener();
l = resultsListener.putIfAbsent(result.getQueryId(), bl);
// if we had a succesful insert, use that reference. Otherwise, just throw away the new bufering listener.
if (l == null) l = bl;
if (result.getQueryId().toString().equals("")) {
failAll();
}
}
if(failed){
l.submissionFailed(new RpcException("Remote failure while running query." + batch.getHeader().getErrorList()));
resultsListener.remove(result.getQueryId(), l);
}else{
l.resultArrived(batch);
}
if (
(failed || result.getIsLastChunk())
&&
(!(l instanceof BufferingListener) || ((BufferingListener)l).output != null)
) {
resultsListener.remove(result.getQueryId(), l);
}
}