GuozhongCrawler系列教程 (5) TransactionRequest详解

为了实现和维护并发抓取的属性信息提供线程安全的事务请求。TransactionRequest是一个抽象类自己不能设置Processor,,却需要实现 TransactionCallBack接口。TransactionRequest是个复合的BasicRequest。他可以将多个PageRequest、BinaryRequest甚至TransactionRequest 自己的对象添加到child集合中,在下载过程中首先下载TransactionRequest中的所有childRequest,每个childRequest下载完成后使用notify方式逐步向上通知, 直到所有的child下载完成TransactionRequest回调 TransactionCallBack的callBack方法通知业务层这个TransactionRequest下载完成。

方法详细资料getPipelinepublicPipelinegetPipeline()setPipelinepublicvoidsetPipeline(Pipelinepipeline)addAttributepublicBasicRequestaddAttribute(java.lang.Stringattribute,java.lang.Objectvalue)

从类复制的说明:BasicRequest

设置属性

指定者:addAttribute在类中BasicRequest返回:返回BasicRequest对象自身getAttributepublicjava.lang.ObjectgetAttribute(java.lang.Stringattribute)

从类复制的说明:BasicRequest

取得属性

指定者:getAttribute在类中BasicRequest返回:返回attribute属性对应的value。没有则返回nulladdChildRequestpublicvoidaddChildRequest(BasicRequestrequest)

添加一个BasicRequest到TransactionRequest的child中

参数:request – iteratorChildRequestspublicjava.util.Iterator<BasicRequest>iteratorChildRequests()

返回这个TransactionRequest所有child的迭代器

返回:notifypublicvoidnotify(inthashcode)

从类复制的说明:BasicRequest

当子url或者当前url完成的时候回调

覆盖:notify在类中BasicRequest参数:hashcode – 实际Request的hashCodecheckCompletepublicvoidcheckComplete()

检查是否所有的Request标记都不是false。如果是那么所有的Request已经请求完成和处理。

如果可以,我真想和你一直旅行。或许是某个未开发的荒凉小岛,

GuozhongCrawler系列教程 (5) TransactionRequest详解

相关文章:

你感兴趣的文章:

标签云: