yangyoupeng

添加ESHttpClient.queryAll方法中死循环保护方法

......@@ -177,12 +177,19 @@ public class ESHttpClient {
QueryResponse returnResponse=new QueryResponse();
int size=queryBuilder.getPage().getSize();
if(size ==0){
return null;
}
LoopCount loopcount=null;
boolean readDone=false;
while(!readDone){
QueryResponse queryResponse=this.query(queryBuilder);
int totalSize=queryResponse.getTotal().intValue();
int returnDataSize=queryResponse.getDataList().size();
returnResponse.addData(queryResponse.getDataList());
int alreadyReadSize=queryBuilder.getPage().getStart()+returnDataSize;
if(alreadyReadSize >=totalSize ){
......@@ -190,12 +197,24 @@ public class ESHttpClient {
returnResponse.setTotal(new Long(totalSize));
break;
}
//为了防止异常的出现死循环
if(loopcount==null){
loopcount=new LoopCount();
loopcount.maxLoopcount=totalSize/size;
}else if(loopcount.maxLoopcount <= 0){
break;
}else{
loopcount.maxLoopcount=loopcount.maxLoopcount-1;
}
queryBuilder.setPage(alreadyReadSize, size);
}
return returnResponse;
}
private class LoopCount{
int maxLoopcount=0;
}
/**
......