/**
 * Description: This is assignment project of Software Architecture and Design
 * Course The purpose of this project is to build a web crawler to get
 * information from some specific sites. In this case, crawler will get
 * information about drug from www.drugs.com
 */
/**
 * Created at: 12:17:19 AM Jul 18, 2013
 *
 * @author TanNhat Project: wcrawler
 */
package wcrawler.core;

import com.google.common.util.concurrent.RateLimiter;
import java.net.URL;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.apache.log4j.Logger;
import wcrawler._interface.IDomainRateLimiter;

public class DomainRateLimiter implements IDomainRateLimiter {
    private static Logger _logger = Logger.getLogger(DomainRateLimiter.class);
    
    private long defaultMinCrawlDelayInMilliSecs;
    private ConcurrentHashMap<String, RateLimiter> _rateLimiterLookup;

    public DomainRateLimiter(long defaultMinCrawlDelayInMilliSecs) {
        if(defaultMinCrawlDelayInMilliSecs < 0){
            throw new ArithmeticException("defaultMinCrawlDelayInMilliSecs");
        }
        this.defaultMinCrawlDelayInMilliSecs = defaultMinCrawlDelayInMilliSecs;
        
        _rateLimiterLookup = new ConcurrentHashMap<String, RateLimiter>();
    }
    
    
    @Override
    public void rateLimit(URL url) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void addDomain(URL url, long minCrawlDelayInMilliSecs) {
        if(url == null)
            throw new NullPointerException("url");
        
        if(minCrawlDelayInMilliSecs < 1)
            throw new ArithmeticException("minCrawlDelayInMilliSecs");
        
        
        long millThatIsGreater = minCrawlDelayInMilliSecs > defaultMinCrawlDelayInMilliSecs ? minCrawlDelayInMilliSecs : defaultMinCrawlDelayInMilliSecs;
        RateLimiter rateLimiter = RateLimiter.create(millThatIsGreater);
        _rateLimiterLookup.put(url.getAuthority(), rateLimiter);
    }
}

@@ -1283,25 +1283,109 @@
  %7D%0A    %0A    
+// Implement rate limit, by getting the %22ratelimiter%22 object from _rateLimiterLookup
 %0A
-
     @Overrid
@@ -1566,16 +1566,87 @@
 %0A    %7D%0A%0A
+    // Add a domain and its crawl-delay value into a concurrenthashmap%0A
     @Ove
@@ -1711,32 +1711,71 @@
 yInMilliSecs) %7B%0A
+        // Check valid of input first %0A
         if(url =
@@ -1963,32 +1963,110 @@
        %0A        
+// Get the greater value of new crawl-delay value or default crawl-delay value
 %0A        long mi
@@ -2196,32 +2196,78 @@
 layInMilliSecs;%0A
+        // Create rateLimiter with that value%0A
         RateLimi
@@ -2335,59 +2335,245 @@
     
-_rateLimiterLookup.put(url.getAuthority(), rateLimi
+// Add to _rateLimiterLookup. Each url will has its own rateLimiter%0A        _rateLimiterLookup.put(url.getAuthority(), rateLimiter);%0A        _logger.debug(%22Add Domain %5C%22%22+url.getAuthority()+%22%5C%22 and RateLimiter with value %22+millThatIsGrea
 ter)

Implement DomainRateLimiter but still have problem with RateLimiter with is provided in Guava library of google. I am asking for help with this problem on stackoverflow.com already.