zoukankan      html  css  js  c++  java
  • 深入学习Heritrix---解析处理器(Processor)(转)

     

    深入学习Heritrix---解析处理器(Processor)

    本节解析与处理器有关的内容.

    与处理器有关的主要在以下几个类:Processor(处理器类),ProcessorChain(处理器类),ProcessorChainList(处理器链列表).它们之间的关系如下:

    下面将解析该图.

    (1)Processor

    代表一个处理器.

    Code

    (2)ProcessorChain

    该类实际上实现一个队列的功能,它代表一个由许多处理器连接的处理器链.

    Code

    (3)ProcessorChainList

    该类是保存一次抓取任务的所有的处理器链(ProcessorChain).


    package org.archive.crawler.framework;
    public class ProcessorChainList {
        
    //处理器链列表,保存所有的处理器链
        private List<ProcessorChain> chainList = new ArrayList<ProcessorChain>();
        
    //所有的处理器
        private Map<String,ProcessorChain> chainMap
         
    = new HashMap<String,ProcessorChain>();

         
    /** Add a new chain of processors to the chain list.
         * 将所有的处理器链添加到Map中
         * This method takes a map of processors and wraps it in a ProcessorChain
         * object and adds it to the list of chains.
         *
         * 
    @param processorMap the processor map to be added.
         
    */
        
    public void addProcessorMap(String name, MapType processorMap) {
            
    //由MapType生成一个处理器链
            ProcessorChain processorChain = new ProcessorChain(processorMap);
            ProcessorChain previousChain 
    = getLastChain();
            
    if (previousChain != null) {
                
    //设置下一个处理器链
                previousChain.setNextChain(processorChain);
            }
            chainList.add(processorChain);
            chainMap.put(name, processorChain);
        }

        
    /** Get the first processor chain.
         * 获取第一个处理链
         * 
    @return the first processor chain.
         
    */
        
    public ProcessorChain getFirstChain() {
            
    return (ProcessorChain) chainList.get(0);
        }

     (4)ToeThread

    为了高效抓取网页,Heritrix采用了线程池的设计.每一个线程将调用所有的处理器来处理链接.

    Code

    (5)处理器链的初始化

    所有的处理器链都是在CrawlController的initialize中初始化的.

    Code
    Code
  • 相关阅读:
    【第36题】2019年OCP认证12C题库062考试最新考试原题
    004 基本命令 touch cp mv 命令
    003 基本指令 mkdir rm -rf(暴力删除)
    002 文件目录类的指令 cd ls
    001 指定运行级别
    005 抽象工厂模式
    006 使用类加载器加载资源文件
    004 方法反射
    003 属性反射
    003 工厂方法模式
  • 原文地址:https://www.cnblogs.com/seurain/p/3200728.html
Copyright © 2011-2022 走看看