All pastes #259416 Raw Edit

Anonymous

public text v1 · immutable
#259416 ·published 2006-11-27 13:40 UTC
rendered paste body


/*
 * Workpool.java
 *
 * Created on 22. November 2006, 10:50
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package javaapplication5;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.*;

/**
 *
 * @author kj09
 */
public class Workpool {
    public List Pool = new ArrayList();
    public ThreadGroup crawlers;
    /** Creates a new instance of Workpool */
    public Workpool(ThreadGroup crawlersp) throws MalformedURLException, IOException {
        crawlers = crawlersp;
    }
    
    public synchronized void add(URLentry entry) throws MalformedURLException, IOException{
        //Halt, wir checken jetzt erstmal, ob es vielleicht den Eintrag schon gibt ;D
       if(Pool.contains(entry.getadress())){
       } else {
        
        Pool.add(entry);
        System.out.println("Added entry to URL-Pool: "+entry.getadress()+", ID: "+entry.getID());
       }
    }
    
    public synchronized URLentry get() throws MalformedURLException, IOException{
       System.out.println("Crawler requests new URL. - URLs Left: "+size());
       URLentry val = (URLentry) Pool.get((Pool.size()-1)); //Den letzten Eintrag rausholen!
       
        remove(val);
        return(val);
        
    }
    
    private synchronized void remove(URLentry entry){
        Pool.remove(entry);        
    }
    
    public synchronized  boolean isEmpty(){
        if(Pool.size() == 0){ return true; } else { return false; }
    }
    
    public synchronized int size(){
        return(Pool.size());
    }
   
    
   
  

}