|
|
|
@ -56,6 +56,7 @@ import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
|
|
import de.anomic.http.HttpClient;
|
|
|
|
|
import de.anomic.http.JakartaCommonsHttpClient;
|
|
|
|
@ -78,6 +79,7 @@ public class RobotsTxt {
|
|
|
|
|
|
|
|
|
|
kelondroMap robotsTable;
|
|
|
|
|
private final File robotsTableFile;
|
|
|
|
|
private ConcurrentHashMap<String, Long> syncObjects;
|
|
|
|
|
//private static final HashSet<String> loadedRobots = new HashSet<String>(); // only for debugging
|
|
|
|
|
|
|
|
|
|
public RobotsTxt(File robotsTableFile) {
|
|
|
|
@ -94,6 +96,7 @@ public class RobotsTxt {
|
|
|
|
|
blob = new kelondroBLOBTree(robotsTableFile, true, true, 256, 512, '_', kelondroNaturalOrder.naturalOrder, false, false, true);
|
|
|
|
|
}
|
|
|
|
|
robotsTable = new kelondroMap(blob, 100);
|
|
|
|
|
syncObjects = new ConcurrentHashMap<String, Long>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void resetDatabase() {
|
|
|
|
@ -133,7 +136,18 @@ public class RobotsTxt {
|
|
|
|
|
robotsTxt4Host == null ||
|
|
|
|
|
robotsTxt4Host.getLoadedDate() == null ||
|
|
|
|
|
System.currentTimeMillis() - robotsTxt4Host.getLoadedDate().getTime() > 7*24*60*60*1000
|
|
|
|
|
)) synchronized(this) {
|
|
|
|
|
)) {
|
|
|
|
|
|
|
|
|
|
// make or get a synchronization object
|
|
|
|
|
Long syncObj = this.syncObjects.get(urlHostPort);
|
|
|
|
|
if (syncObj == null) {
|
|
|
|
|
syncObj = new Long(System.currentTimeMillis());
|
|
|
|
|
this.syncObjects.put(urlHostPort, syncObj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// we can now synchronize for each host separately
|
|
|
|
|
synchronized (syncObj) {
|
|
|
|
|
|
|
|
|
|
// if we have not found any data or the data is older than 7 days, we need to load it from the remote server
|
|
|
|
|
|
|
|
|
|
// check the robots table again for all threads that come here because they waited for another one
|
|
|
|
@ -215,6 +229,7 @@ public class RobotsTxt {
|
|
|
|
|
(Integer) parserResult[2]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return robotsTxt4Host;
|
|
|
|
|
}
|
|
|
|
|