⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frontier.java

📁 爬虫
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Frontier * * $Id: Frontier.java,v 1.14 2005/11/12 00:39:51 gojomo Exp $ * * Created on Mar 29, 2004 * * Copyright (C) 2004 Internet Archive. * * This file is part of the Heritrix web crawler (crawler.archive.org). * * Heritrix is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * any later version. * * Heritrix is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU Lesser Public License for more details. * * You should have received a copy of the GNU Lesser Public License * along with Heritrix; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package org.archive.crawler.framework;import java.io.IOException;import java.util.ArrayList;import org.archive.crawler.datamodel.CandidateURI;import org.archive.crawler.datamodel.CrawlSubstats;import org.archive.crawler.datamodel.CrawlURI;import org.archive.crawler.framework.exceptions.EndedException;import org.archive.crawler.framework.exceptions.FatalConfigurationException;import org.archive.crawler.framework.exceptions.InvalidFrontierMarkerException;import org.archive.crawler.frontier.FrontierJournal;import org.archive.net.UURI;import org.archive.util.Reporter;/** * An interface for URI Frontiers. * * <p>A URI Frontier is a pluggable module in Heritrix that maintains the * internal state of the crawl. This includes (but is not limited to): * <ul> *     <li>What URIs have been discovered *     <li>What URIs are being processed (fetched) *     <li>What URIs have been processed *     <li>In what order unprocessed URIs will be processed * </ul> * * <p>The Frontier is also responsible for enforcing any politeness restrictions * that may have been applied to the crawl. Such as limiting simultaneous * connection to the same host, server or IP number to 1 (or any other fixed * amount), delays between connections etc. * * <p>A URIFrontier is created by the * {@link org.archive.crawler.framework.CrawlController CrawlController} which * is in turn responsible for providing access to it. Most significant among * those modules interested in the Frontier are the * {@link org.archive.crawler.framework.ToeThread ToeThreads} who perform the * actual work of processing a URI. * * <p>The methods defined in this interface are those required to get URIs for * processing, report the results of processing back (ToeThreads) and to get * access to various statistical data along the way. The statistical data is * of interest to {@link org.archive.crawler.framework.StatisticsTracking * Statistics Tracking} modules. A couple of additional methods are provided * to be able to inspect and manipulate the Frontier at runtime. * * <p>The statistical data exposed by this interface is: * <ul> *     <li> {@link #discoveredUriCount() Discovered URIs} *     <li> {@link #queuedUriCount() Queued URIs} *     <li> {@link #finishedUriCount() Finished URIs} *     <li> {@link #succeededFetchCount() Successfully processed URIs} *     <li> {@link #failedFetchCount() Failed to process URIs} *     <li> {@link #disregardedUriCount() Disregarded URIs} *     <li> {@link #totalBytesWritten() Total bytes written} * </ul> * * <p>In addition the frontier may optionally implement an interface that * exposes information about hosts. * * <p>Furthermore any implementation of the URI Frontier should trigger * {@link org.archive.crawler.event.CrawlURIDispositionListener * CrawlURIDispostionEvents} by invoking the proper methods on the * {@link org.archive.crawler.framework.CrawlController CrawlController}. * Doing this allows a custom built * {@link org.archive.crawler.framework.StatisticsTracking * Statistics Tracking} module to gather any other additional data it might be * interested in by examining the completed URIs. * * <p>All URI Frontiers inherit from * {@link org.archive.crawler.settings.ModuleType ModuleType} * and therefore creating settings follows the usual pattern of pluggable modules * in Heritrix. * * @author Gordon Mohr * @author Kristinn Sigurdsson * * @see org.archive.crawler.framework.CrawlController * @see org.archive.crawler.framework.CrawlController#fireCrawledURIDisregardEvent(CrawlURI) * @see org.archive.crawler.framework.CrawlController#fireCrawledURIFailureEvent(CrawlURI) * @see org.archive.crawler.framework.CrawlController#fireCrawledURINeedRetryEvent(CrawlURI) * @see org.archive.crawler.framework.CrawlController#fireCrawledURISuccessfulEvent(CrawlURI) * @see org.archive.crawler.framework.StatisticsTracking * @see org.archive.crawler.framework.ToeThread * @see org.archive.crawler.framework.FrontierHostStatistics * @see org.archive.crawler.settings.ModuleType */public interface Frontier extends Reporter {    /**     * All URI Frontiers should have the same 'name' attribute. This constant     * defines that name. This is a name used to reference the Frontier being     * used in a given crawl order and since there can only be one Frontier     * per crawl order a fixed, unique name for Frontiers is optimal.     *     * @see org.archive.crawler.settings.ModuleType#ModuleType(String)     */    public static final String ATTR_NAME = "frontier";    /**     * Initialize the Frontier.     *     * <p> This method is invoked by the CrawlController once it has     * created the Frontier. The constructor of the Frontier should     * only contain code for setting up it's settings framework. This     * method should contain all other 'startup' code.     *     * @param c The CrawlController that created the Frontier.     *     * @throws FatalConfigurationException If provided settings are illegal or     *            otherwise unusable.     * @throws IOException If there is a problem reading settings or seeds file     *            from disk.     */    public void initialize(CrawlController c)            throws FatalConfigurationException, IOException;    /**     * Get the next URI that should be processed. If no URI becomes availible     * during the time specified null will be returned.     *     * @return the next URI that should be processed.     * @throws InterruptedException     * @throws EndedException      */    CrawlURI next() throws InterruptedException, EndedException;    /**     * Returns true if the frontier contains no more URIs to crawl.     *     * <p>That is to say that there are no more URIs either currently availible     * (ready to be emitted), URIs belonging to deferred hosts or pending URIs     * in the Frontier. Thus this method may return false even if there is no     * currently availible URI.     *     * @return true if the frontier contains no more URIs to crawl.     */    boolean isEmpty();    /**     * Schedules a CandidateURI.     *     * <p>This method accepts one URI and schedules it immediately. This has     * nothing to do with the priority of the URI being scheduled. Only that     * it will be placed in it's respective queue at once. For priority     * scheduling see {@link CandidateURI#setSchedulingDirective(int)}     *     * <p>This method should be synchronized in all implementing classes.     *     * @param caURI The URI to schedule.     *     * @see CandidateURI#setSchedulingDirective(int)     */    public void schedule(CandidateURI caURI);    /**     * Report a URI being processed as having finished processing.     *     * <p>ToeThreads will invoke this method once they have completed work on     * their assigned URI.     *     * <p>This method is synchronized.     *     * @param cURI The URI that has finished processing.     */    public void finished(CrawlURI cURI);    /**     * Number of <i>discovered</i> URIs.     *     * <p>That is any URI that has been confirmed be within 'scope'     * (i.e. the Frontier decides that it should be processed). This     * includes those that have been processed, are being processed     * and have finished processing. Does not include URIs that have     * been 'forgotten' (deemed out of scope when trying to fetch,     * most likely due to operator changing scope definition).     *     * <p><b>Note:</b> This only counts discovered URIs. Since the same     * URI can (at least in most frontiers) be fetched multiple times, this     * number may be somewhat lower then the combined <i>queued</i>,     * <i>in process</i> and <i>finished</i> items combined due to duplicate     * URIs being queued and processed. This variance is likely to be especially     * high in Frontiers implementing 'revist' strategies.     *     * @return Number of discovered URIs.     */    public long discoveredUriCount();    /**     * Number of URIs <i>queued</i> up and waiting for processing.     *     * <p>This includes any URIs that failed but will be retried. Basically this     * is any <i>discovered</i> URI that has not either been processed or is     * being processed. The same discovered URI can be queued multiple times.     *     * @return Number of queued URIs.     */    public long queuedUriCount();    public long deepestUri(); // aka longest queue    public long averageDepth(); // aka average queue length    public float congestionRatio(); // multiple of threads needed for max progress        /**     * Number of URIs that have <i>finished</i> processing.     *     * <p>Includes both those that were processed successfully and failed to be     * processed (excluding those that failed but will be retried). Does not     * include those URIs that have been 'forgotten' (deemed out of scope when

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -