package us.codecraft.webmagic.scheduler;

import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Task;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;


/**
 * Basic Scheduler implementation.<br>
 * Store urls to fetch in LinkedBlockingQueue and remove duplicate urls by HashMap.
 *
 * @author code4crafter@gmail.com <br>
 * @since 0.1.0
 */
public class QueueScheduler extends DuplicateRemovedScheduler implements MonitorableScheduler {

    private BlockingQueue<Request> queue = new LinkedBlockingQueue<Request>();

    @Override
    public void pushWhenNoDuplicate(Request request, Task task) {
        queue.add(request);
    }

    @Override
    public Request poll(Task task) {
        return queue.poll();
    }

    @Override
    public int getLeftRequestsCount(Task task) {
        return queue.size();
    }

    @Override
    public int getTotalRequestsCount(Task task) {
        return getDuplicateRemover().getTotalRequestsCount(task);
    }
}

@@ -501,16 +501,22 @@
 private 
+final 
 Blocking
@@ -539,46 +539,434 @@
 ueue
- = new LinkedBlockingQueue%3CRequest%3E();
+;%0A%0A    public QueueScheduler() %7B%0A        this.queue = new LinkedBlockingQueue%3C%3E();%0A    %7D%0A%0A    /**%0A     * Creates a %7B@code QueueScheduler%7D with the given (fixed) capacity.%0A     *%0A     * @param capacity the capacity of this queue,%0A     * see %7B@link LinkedBlockingQueue#LinkedBlockingQueue(int)%7D%0A     * @since 0.8.0%0A     */%0A    public QueueScheduler(int capacity) %7B%0A        this.queue = new LinkedBlockingQueue%3C%3E(capacity);%0A    %7D
 %0A%0A  
@@ -1035,32 +1035,50 @@
 t, Task task) %7B%0A
+        try %7B%0A    
         queue.ad
@@ -1079,11 +1079,11 @@
 eue.
-add
+put
 (req
@@ -1089,16 +1089,117 @@
 quest);%0A
+        %7D catch (InterruptedException e) %7B%0A            Thread.currentThread().interrupt();%0A        %7D%0A
     %7D%0A%0A 

Revise QueueScheduler to support capacity-restricted.