Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Merge branch 'master' of ssh://[email protected]/yacy/rc1.git
Michael Peter Christen1f4f60654a68
diff --cc source/de/anomic/crawler/Balancer.javaindex 8afb9eb6a,8afb9eb6a..a9d3438ca--- a/source/de/anomic/crawler/Balancer.java+++ b/source/de/anomic/crawler/Balancer.java@@@ -29,6 -29,6 +29,8 @@@ package de.anomic.crawlerimport java.io.File;import java.io.IOException;import java.util.ArrayList;++import java.util.Collection;++import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;@@@ -293,6 -293,6 +295,72 @@@ public class Balancer}}++ /**++ * get a list of domains that are currently maintained as domain stacks++ * @return a map of clear text strings of host names to the size of the domain stack++ */++ public Map<String, Integer> getDomainStackHosts() {++ Map<String, Integer> map = new HashMap<String, Integer>();++ for (Map.Entry<String, HandleSet> entry: this.domainStacks.entrySet()) {++ map.put(entry.getKey(), entry.getValue().size());++ }++ return map;++ }++++ /**++ * compute the current sleep time for a given crawl entry++ * @param cs++ * @param crawlEntry++ * @return++ */++ public long getDomainSleepTime(final CrawlSwitchboard cs, Request crawlEntry) {++ final CrawlProfile profileEntry = cs.getActive(UTF8.getBytes(crawlEntry.profileHandle()));++ return getDomainSleepTime(cs, profileEntry, crawlEntry);++ }++++ private long getDomainSleepTime(final CrawlSwitchboard cs, final CrawlProfile profileEntry, Request crawlEntry) {++ if (profileEntry == null) {++ return 0;++ }++ long sleeptime = (++ profileEntry.cacheStrategy() == CacheStrategy.CACHEONLY ||++ (profileEntry.cacheStrategy() == CacheStrategy.IFEXIST && Cache.has(crawlEntry.url()))++ ) ? 0 : Latency.waitingRemaining(crawlEntry.url(), this.myAgentIDs, this.minimumLocalDelta, this.minimumGlobalDelta); // this uses the robots.txt database and may cause a loading of robots.txt from the server++ return sleeptime;++ }++++ /**++ * get lists of crawl request entries for a specific host++ * @param host++ * @param maxcount++ * @return a list of crawl loader requests++ */++ public List<Request> getDomainStackReferences(String host, int maxcount) {++ HandleSet domainList = this.domainStacks.get(host);++ if (domainList == null || domainList.isEmpty()) return new ArrayList<Request>(0);++ ArrayList<Request> cel = new ArrayList<Request>(maxcount);++ for (int i = 0; i < maxcount; i++) {++ if (domainList.size() <= i) break;++ final byte[] urlhash = domainList.getOne(i);++ if (urlhash == null) continue;++ Row.Entry rowEntry;++ try {++ rowEntry = this.urlFileIndex.get(urlhash, true);++ } catch (IOException e) {++ continue;++ }++ if (rowEntry == null) continue;++ Request crawlEntry;++ try {++ crawlEntry = new Request(rowEntry);++ } catch (IOException e) {++ continue;++ }++ cel.add(crawlEntry);++ }++ return cel;++ }++private void pushHashToDomainStacks(String host, final byte[] urlhash) throws RowSpaceExceededException {// extend domain stackif (host == null) host = localhost;@@@ -417,11 -417,11 +485,8 @@@return null;}// depending on the caching policy we need sleep time to avoid DoS-like situations-- sleeptime = (-- profileEntry.cacheStrategy() == CacheStrategy.CACHEONLY ||-- (profileEntry.cacheStrategy() == CacheStrategy.IFEXIST && Cache.has(crawlEntry.url()))-- ) ? 0 : Latency.waitingRemaining(crawlEntry.url(), this.myAgentIDs, this.minimumLocalDelta, this.minimumGlobalDelta); // this uses the robots.txt database and may cause a loading of robots.txt from the server--++ sleeptime = getDomainSleepTime(cs, profileEntry, crawlEntry);++assert Base64Order.enhancedCoder.equal(nexthash, rowEntry.getPrimaryKeyBytes()) : "result = " + ASCII.String(nexthash) + ", rowEntry.getPrimaryKeyBytes() = " + ASCII.String(rowEntry.getPrimaryKeyBytes());assert Base64Order.enhancedCoder.equal(nexthash, crawlEntry.url().hash()) : "result = " + ASCII.String(nexthash) + ", crawlEntry.url().hash() = " + ASCII.String(crawlEntry.url().hash());diff --cc source/de/anomic/crawler/NoticedURL.javaindex 8d64937fd,8d64937fd..93220c5b0--- a/source/de/anomic/crawler/NoticedURL.java+++ b/source/de/anomic/crawler/NoticedURL.java@@@ -32,6 -32,6 +32,7 @@@ import java.io.IOExceptionimport java.util.HashSet;import java.util.Iterator;import java.util.List;++import java.util.Map;import java.util.Set;import net.yacy.kelondro.index.HandleSet;@@@ -228,6 -228,6 +229,50 @@@ public class NoticedURLreturn removed;}++ /**++ * get a list of domains that are currently maintained as domain stacks++ * @return a map of clear text strings of host names to the size of the domain stacks++ */++ public Map<String, Integer> getDomainStackHosts(final StackType stackType) {++ switch (stackType) {++ case CORE: return this.coreStack.getDomainStackHosts();++ case LIMIT: return this.limitStack.getDomainStackHosts();++ case REMOTE: return this.remoteStack.getDomainStackHosts();++ case NOLOAD: return this.noloadStack.getDomainStackHosts();++ default: return null;++ }++ }++++ /**++ * get a list of domains that are currently maintained as domain stacks++ * @return a collection of clear text strings of host names++ */++ public long getDomainSleepTime(final StackType stackType, final CrawlSwitchboard cs, Request crawlEntry) {++ switch (stackType) {++ case CORE: return this.coreStack.getDomainSleepTime(cs, crawlEntry);++ case LIMIT: return this.limitStack.getDomainSleepTime(cs, crawlEntry);++ case REMOTE: return this.remoteStack.getDomainSleepTime(cs, crawlEntry);++ case NOLOAD: return this.noloadStack.getDomainSleepTime(cs, crawlEntry);++ default: return 0;++ }++ }++++ /**++ * get lists of crawl request entries for a specific host++ * @param host++ * @param maxcount++ * @return a list of crawl loader requests++ */++ public List<Request> getDomainStackReferences(final StackType stackType, String host, int maxcount) {++ switch (stackType) {++ case CORE: return this.coreStack.getDomainStackReferences(host, maxcount);++ case LIMIT: return this.limitStack.getDomainStackReferences(host, maxcount);++ case REMOTE: return this.remoteStack.getDomainStackReferences(host, maxcount);++ case NOLOAD: return this.noloadStack.getDomainStackReferences(host, maxcount);++ default: return null;++ }++ }++public List<Request> top(final StackType stackType, final int count) {switch (stackType) {case CORE: return top(this.coreStack, count);@@@ -295,7 -295,7 +340,7 @@@return null;}-- private List<Request> top(final Balancer balancer, int count) {++ private static List<Request> top(final Balancer balancer, int count) {// this is a filo - topif (count > balancer.size()) count = balancer.size();return balancer.top(count);diff --cc source/net/yacy/document/parser/pdfParser.javaindex 08533c956,7424aec48..e8b01edc3--- a/source/net/yacy/document/parser/pdfParser.java+++ b/source/net/yacy/document/parser/pdfParser.java@@@ -126,32 -125,32 +125,32 @@@ public class pdfParser extends Abstractif (docTitle == null || docTitle.length() == 0) {docTitle = MultiProtocolURI.unescape(location.getFileName());}-- final CharBuffer writer = new CharBuffer(odtParser.MAX_DOCSIZE);- byte[] contentBytes = UTF8.getBytes("");- byte[] contentBytes = new byte[0];++ final CharBuffer writer = new CharBuffer(odtParser.MAX_DOCSIZE);++ byte[] contentBytes = new byte[0];try {// create a writer for output-- final PDFTextStripper stripper = new PDFTextStripper();-++ final PDFTextStripper stripper = new PDFTextStripper();+stripper.setEndPage(3); // get first 3 pages (always)writer.append(stripper.getText(pdfDoc));- contentBytes = UTF8.getBytes(writer.toString()); // remember text in case of interrupting thread-+ contentBytes = writer.getBytes(); // remember text in case of interrupting thread-++stripper.setStartPage(4); // continue with page 4 (terminated, resulting in no text)stripper.setEndPage(Integer.MAX_VALUE); // set to default// we start the pdf parsing in a separate thread to ensure that it can be terminatedfinal Thread t = new Thread() {@Overridepublic void run() {-- try {- writer.append(stripper.getText(pdfDoc));- writer.append(stripper.getText(pdfDoc));++ try {++ writer.append(stripper.getText(pdfDoc));} catch (final Throwable e) {}- }- };+ }+ };t.start();t.join(3000);-- if (t.isAlive()) t.interrupt();- pdfDoc.close();- contentBytes = UTF8.getBytes(writer.toString()); // get final text before closing writer++ if (t.isAlive()) t.interrupt();+ pdfDoc.close();- contentBytes = writer.getBytes(); // get final text before closing writer++ contentBytes = writer.getBytes(); // get final text before closing writerwriter.close();} catch (final IOException e) {// close the writer@@@ -176,8 -175,8 +175,7 @@@if (docTitle == null) {docTitle = docSubject;}----++// clear resources in pdfbox. they say that is resolved but it's not. see:// https://issues.apache.org/jira/browse/PDFBOX-313// https://issues.apache.org/jira/browse/PDFBOX-351