/*
* 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());
}
}