heritrix3源码分析(outbound 和inbound)

Heritrix3相较于Heritrix1.14有了显著改进,采用阻塞FIFO队列实现生产消费者模型。AbstractFrontier组件管理两个主要容器:inbound用于存储待处理的链接,而outbound则存放当前正在处理的链接。本文详细介绍了这两个队列的工作原理及其在Heritrix3中的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

heritrix3 与heritrix1.14 相比有很大不同, heritrix3 定义了一种阻塞的FIFO queue, 属于典型的生产消费者模型


AbstractFrontier 中定义了2个 容器, inbound 和outbound

inbound 容器存储的是那些即将要处理的crawlUrI, heritrix 爬取到的链接, 准备处理的链接都是先放在inbound 当中.

outbound 容器存储的当前要处理的crawlUrI, Frontier 链接工厂会从outbound取出链接并处理



/** inbound updates: URIs to be scheduled, finished; requested state changes */

transient protected ArrayBlockingQueue inbound;

/** outbound URIs */

transient protected ArrayBlockingQueue outbound;



AbstractFrontier启动时实例化 inbound , outbound

inbound 的容量是outbound 的十倍

public void start() {
if(isRunning()) {
return;
}

if (getRecoveryLogEnabled()) try {
initJournal(loggerModule.getPath().getFile().getAbsolutePath());
} catch (IOException e) {
throw new IllegalStateException(e);
}

this.outboundCapacity = getOutboundQueueCapacity();
this.inboundCapacity = outboundCapacity *
getInboundQueueMultiple();
outbound = new ArrayBlockingQueue<CrawlURI>(outboundCapacity, true);
inbound = new ArrayBlockingQueue<InEvent>(inboundCapacity, true);
pause();
startManagerThread();
}



inbound中存的是一个个等处理的事件
从inbound中处理这些事件


/**
* Drain the inbound queue of update events, or at the very least
* wait until some additional delayed-queue URI becomes available.
*
* @throws InterruptedException
*/
protected void drainInbound() throws InterruptedException {
int batch = inbound.size();
for(int i = 0; i < batch; i++) {
inbound.take().process();
}
if(batch==0) {
// always do at least one timed try
InEvent toProcess = inbound.poll(getMaxInWait(),
TimeUnit.MILLISECONDS);
if (toProcess != null) {
toProcess.process();
}
}
}


未完,待续。。。。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值