Storm中對(duì)于Protocol進(jìn)行的封裝是怎樣的

本篇文章為大家展示了Storm中對(duì)于Protocol進(jìn)行的封裝是怎樣的,內(nèi)容簡明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

成都創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的鐵西網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

對(duì)于Protocol的封裝

package com.digitalpebble.storm.crawler.fetcher;

import com.digitalpebble.storm.crawler.util.Configuration;

public interface Protocol {

    public ProtocolResponse getProtocolOutput(String url) throws Exception;
    
    public void configure(Configuration conf);
}

 對(duì)于ProtoclFactory的封裝

package com.digitalpebble.storm.crawler.fetcher;

import java.net.URL;
import java.util.WeakHashMap;

import com.digitalpebble.storm.crawler.fetcher.asynchttpclient.AHProtocol;
import com.digitalpebble.storm.crawler.util.Configuration;

/**
 * @author Yin Shuai
 *
 */
public class ProtocolFactory {

    private final Configuration config;

    private final WeakHashMap<String, Protocol> cache = new WeakHashMap<String, Protocol>();

	public ProtocolFactory(Configuration conf) {
        config = conf;
    }

    /** Returns an instance of the protocol to use for a given URL **/
    public synchronized Protocol getProtocol(URL url) {
        // get the protocol
        String protocol = url.getProtocol();
        Protocol pp = cache.get(protocol);
        if (pp != null)
            return pp;
        
        // yuk! hardcoded for now
        pp = new AHProtocol();
        pp.configure(config);
        cache.put(protocol,pp);
        return pp;
    }

}

 對(duì)于ProtocolResponse的封裝

package com.digitalpebble.storm.crawler.fetcher;

import java.util.HashMap;

public class ProtocolResponse {

    final byte[] content;
    final int statusCode;
    final HashMap<String, String[]> metadata;

    public ProtocolResponse(byte[] c, int s, HashMap<String, String[]> md){
        content = c;
        statusCode = s;
        metadata = md;
    }

    public byte[] getContent() {
        return content;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public HashMap<String, String[]> getMetadata() {
        return metadata;
    }

}

上述內(nèi)容就是Storm中對(duì)于Protocol進(jìn)行的封裝是怎樣的,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)站欄目:Storm中對(duì)于Protocol進(jìn)行的封裝是怎樣的
地址分享:http://bm7419.com/article2/geigoc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、網(wǎng)站導(dǎo)航網(wǎng)頁設(shè)計(jì)公司、ChatGPT、微信小程序網(wǎng)站營銷

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司