云計(jì)算
本篇文章為大家展示了storm中對(duì)于protocol進(jìn)行的封裝是怎樣的,內(nèi)容簡明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
對(duì)于protocol的封裝
packagecom.digitalpebble.storm.crawler.fetcher;importcom.digitalpebble.storm.crawler.util.configuration;publicinterfaceprotocol{publicprotocolresponsegetprotocoloutput(stringurl)throwsexception;publicvoidconfigure(configurationconf);}
對(duì)于protoclfactory的封裝
packagecom.digitalpebble.storm.crawler.fetcher;importjava.net.url;importjava.util.weakhashmap;importcom.digitalpebble.storm.crawler.fetcher.asynchttpclient.ahprotocol;importcom.digitalpebble.storm.crawler.util.configuration;/*@authoryinshuai/publicclassprotocolfactory{privatefinalconfigurationconfig;privatefinalweakhashmap<string,protocol>cache=newweakhashmap<string,protocol>();publicprotocolfactory(configurationconf){config=conf;}/returnsaninstanceoftheprotocoltouseforagivenurl/publicsynchronizedprotocolgetprotocol(urlurl){//gettheprotocolstringprotocol=url.getprotocol();protocolpp=cache.get(protocol);if(pp!=null)returnpp;//yuk!hardcodedfornowpp=newahprotocol();pp.configure(config);cache.put(protocol,pp);returnpp;}}
對(duì)于protocolresponse的封裝
packagecom.digitalpebble.storm.crawler.fetcher;importjava.util.hashmap;publicclassprotocolresponse{finalbyte[]content;finalintstatuscode;finalhashmap<string,string[]>metadata;publicprotocolresponse(byte[]c,ints,hashmap<string,string[]>md){content=c;statuscode=s;metadata=md;}publicbyte[]getcontent(){returncontent;}publicintgetstatuscode(){returnstatuscode;}publichashmap<string,string[]>getmetadata(){returnmetadata;}}
上述內(nèi)容就是storm中對(duì)于protocol進(jìn)行的封裝是怎樣的,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注資訊頻道。