Frontier鏈結製造工廠

2021-04-17 11:06:48 字數 4364 閱讀 7470

frontier在英文中的意思是「前線,領域」,在heritrix中,它表示一種具。它通過一些特定的演算法來決定哪個鏈結將接下來被送入處理器鏈中,同時,它本身也負責一定的日誌和狀態報告功能。

事實上,要寫出乙個合格並且真正能夠使用的frontier絕非一件簡單的事情,儘管有了frontier介面,其中的方法約束了frontier的行為,也給編碼帶來了一定的指示。但是其中還存在著很多問題,需要很好的設計和處理才可以解決。 在heritrix的官方文件上,有乙個frontier的例子,在此拿出來進行一下講解,以此來向讀者說明乙個最簡單的frontier都能夠做什麼事。以下就是這個frontier的**。

public

class

myfrontier 

extends

moduletype 

implements

frontier, 

fetchstatuscodes 

宣告各種變數;

//列表中儲存了還未被抓取的鏈結 

list pendinguris 

=new

arraylist(); 

//這個列表中儲存了一系列的鏈結,它們的優先順序 

//要高於pendinguris那個list中的任何乙個鏈結 

//表中的鏈結表示一些需要被滿足的先決條件 

list prerequisites 

=new

arraylist(); 

//乙個hashmap,用於儲存那些已經抓取過的鏈結 

map alreadyincluded 

=new

hashmap(); 

//crawlcontroller物件 

crawlcontroller controller; 

//用於標識是否乙個鏈結正在被處理 

boolean

uriinprocess 

=false

; //

long

successcount =0

; //

失敗的數量 

long

failedcount =0

; //

拋棄掉鏈結的數量 

long

disregardedcount =0

; //

long

totalprocessedbytes =0

;  建構函式:

public

myfrontier(string name)  

初始化,引數為乙個crawlcontroller

public

void

initialize(crawlcontroller controller) 

throws

fatalconfigurationexception, ioexception  

} } 

public

synchronized

crawluri next(

inttimeout) 

throws

interruptedexception  

else

curi.setserver(controller.getservercache().getserverfor(curi)); 

return

curi; 

} else } 

判斷是否為空

public

boolean

isempty()  

該方法用於將新鏈結加入到pendinguris佇列中,等待處理

public

synchronized

void

schedule(candidateuri cauri)  

else //

hashmap中使用url的字串來做為key 

//而將實際的cadidateuri物件做為value 

alreadyincluded.put(cauri.geturistring(), cauri); 

} } 

批處理public

void

batchschedule(candidateuri cauri)  

public

void

batchflush()  

一次抓取結束後所執行的操作,該操作由執行緒池中的執行緒來進行呼叫

public

synchronized

void

finished(crawluri curi)  

//else

if(curi.getfetchstatus() 

==s_deferred)  

//其他狀態 

else

if(curi.getfetchstatus() 

==s_robots_precluded 

||curi.getfetchstatus() 

==s_out_of_scope 

||curi.getfetchstatus() 

==s_blocked_by_user 

||curi.getfetchstatus() 

==s_too_many_embed_hops 

||curi.getfetchstatus() 

==s_too_many_link_hops 

||curi.getfetchstatus() 

==s_deleted_by_user)  

else

curi.processingcleanup(); } 

最後的容器處理:

//返回所有已經處理過的鏈結數量 

public

long

discovereduricount()  

//返回所有等待處理的鏈結的數量 

public

long

queueduricount()  

//返回所有已經完成的鏈結數量 

public

long

finisheduricount()  

//返回所有成功處理的鏈結數量 

public

long

successfullyfetchedcount()  

//返回所有失敗的鏈結數量 

public

long

failedfetchcount()  

//返回所有拋棄的鏈結數量 

public

long

disregardedfetchcount()  

//public

long

totalbyteswritten()  

public

string report()  

public

void

importrecoverlog(string pathtolog) 

throws

ioexception  

public

frontiermarker getinitialmarker(string regexpr, 

boolean

incacheonly)  

public

arraylist geturislist(frontiermarker marker, 

intnumberofmatches, 

boolean

verbose) 

throws

invalidfrontiermarkerexception  

public

long

deleteuris(string match)  } 

frontier是用來向執行緒提供鏈結的,因此,在上面的**中,使用了兩個arraylist來儲存鏈結。其中,第乙個pendinguris儲存的是等待處理的鏈結,第二個prerequisites中儲存的也是鏈結,只不過它裡面的每個鏈結的優先順序都要高於pendinguris裡的鏈結。通常,在prerequisites中儲存的都是如dns之類的鏈結,只有當這些鏈結被首先解析後,其後續的鏈結才能夠被解析。

除了這兩個arraylist外,在上面的frontier還有乙個名稱為alreadyincluded的hashmap。它用於記錄那些已經被處理過的鏈結。每當呼叫frontier的schedule()方法來加入乙個新的鏈結時,frontier總要先檢查這個正要加入到佇列中的鏈結是不是已經被處理過了。

很顯然,在分析網頁的時候,會出現大量相同的鏈結,如果沒有這種檢查,很有可能造成抓取任務永遠無法完成的情況。同時,在schedule()方法中還加入了一些邏輯,用於判斷當前要進入佇列的鏈結是否屬於需要優先處理的,如果是,則置入prerequisites佇列中,否則,就簡單的加入pendinguris中即可。

唉!其實看不懂啊!…………

URL重寫 鏈結工廠

要根據資料庫中已有的資料,例如產品名稱或種類名稱,使用函式來生成新的url位址,實現一致性 建立兩個php函式 1.prepare url text接收乙個字串引數 比如產品或種類名稱,它將被用於包含到被重寫後的url位址中 並將它轉換為能夠放入url位址中的相應格式,比如 函式可以將 super ...

阿里巴巴為新製造數字工廠揭幕

雲智慧型驅動的製造模式可為中小型企業創造公平的競爭環境,實現小批量定製和敏捷化生產 中國杭州 美國商業資訊 阿里巴巴集團控股 alibaba group holding limited,nyse baba hkex 9988,簡稱 阿里巴巴 或 阿里巴巴集團 今天為其迅犀數字工廠 迅犀 舉行揭幕儀式...

製造工廠的6點特徵適用MES系統

智慧型化生產製造過程管控的mes系統,可以幫助企業降低製造成本 提公升工作效率,從而贏得與其他同行的競爭,企業能獲得更大的利潤 得到更大的發展。但是我們都知道並不是所有的工廠,都適用於mes系統。不同行業就會有不同的mes系統,它所包含的基本概念也各有不同。比較常見將mes系統分成離散製造業和流程製...