云计算
本篇文章为大家展示了storm中对于protocol进行的封装是怎样的,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
对于protocol的封装
packagecom.digitalpebble.storm.crawler.fetcher;importcom.digitalpebble.storm.crawler.util.configuration;publicinterfaceprotocol{publicprotocolresponsegetprotocoloutput(stringurl)throwsexception;publicvoidconfigure(configurationconf);}
对于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;}}
对于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;}}
上述内容就是storm中对于protocol进行的封装是怎样的,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注资讯频道。
云服务器安全防护优惠帮助文档网易考拉微商城店主项目我程序和数据库都上传了无法访问哪里买域名便宜?域名注册哪个便宜?如何解决php上传中文乱码的问题服务器昨晚上公司升级后就占用很高如何将网站绑定域名?网站绑定域名有什么流程?如何建一个企业网站?告诉你企业网站设计的5个要点