public RpcOutcomeListener<QueryId> getWrappedListener(UserResultsListener listener){
return new SubmissionListener(listener);
}
public void batchArrived(ConnectionThrottle throttle, ByteBuf pBody, ByteBuf dBody) throws RpcException {
final QueryResult result = RpcBus.get(pBody, QueryResult.PARSER);
final QueryResultBatch batch = new QueryResultBatch(result, dBody);
final boolean failed = (batch.getHeader().getQueryState() == QueryState.FAILED);
assert failed || batch.getHeader().getErrorCount() == 0 : "Error count for the query batch is non-zero but QueryState != FAILED";
UserResultsListener l = resultsListener.get(result.getQueryId());
// 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) {
String message = buildErrorMessage(batch);
l.submissionFailed(new RpcException(message));
resultsListener.remove(result.getQueryId(), l);
}else{
try {
l.resultArrived(batch, throttle);
} catch (Exception e) {
batch.release();
l.submissionFailed(new RpcException(e));
}
}
if (
(failed || result.getIsLastChunk())
&&
(!(l instanceof BufferingListener) || ((BufferingListener)l).output != null)
) {
resultsListener.remove(result.getQueryId(), l);
}
}