{
// more segments to go?
while(segQueue.hasMoreSegments() && runningThreads < maxThreads && !pause && nioClient.hasFreeSlot())
{
// get next download segment of the download file
DownloadFileSegment seg = segQueue.nextSegment();
if(seg == null)
break;
String filename = seg.getDlFile().getFilename();
logger.msg("Downloading next segment of file: " + filename, MyLogger.SEV_DEBUG);
// create new response handler
RspHandler newHandler = new RspHandler(seg, false);
synchronized(activeRspHandlers)
{
activeRspHandlers.add(newHandler);
}
// map the new response handler to the download file
mapHandlerToFile(newHandler, seg);
// start data download and increase thread counter
nioClient.fetchArticleData(seg.getGroups().firstElement(), seg.getArticleId(), newHandler);
runningThreads++;
}
// Add finished response handlers from backup downloader to this.activeRspHandlers
if(backupFileDownloader != null && backupFileDownloader.hasFinishedHandlers())
{
for(RspHandler handler : backupFileDownloader.getFinishedHandlers())
{
activeRspHandlers.add(handler);
DownloadFileSegment seg = handler.dlFileSeg();
dlFileRspHandlerMap.get(seg.getDlFile()).put(seg.getIndex(), handler);
}
}
// check if the next element of the result set is already finished
int actRspHdlsSize;