当前位置: 首页 > news >正文

wordpress xmlrcpseo怎么做整站排名

wordpress xmlrcp,seo怎么做整站排名,做学校教务处网站,网站解析ip地址重修设计模式-行为型-责任链模式 将请求的发送和接收解耦,让多个接收对象都有机会处理这个请求。将这些接收对象串成一条链,并沿着这条链传递这个请求,直到链上的某个接收对象能够处理它为止。 责任链模式(Chain of Responsibilit…

重修设计模式-行为型-责任链模式

将请求的发送和接收解耦,让多个接收对象都有机会处理这个请求。将这些接收对象串成一条链,并沿着这条链传递这个请求,直到链上的某个接收对象能够处理它为止。

责任链模式(Chain of Responsibility Pattern)也叫职责链模式,通过将请求的处理分配给一系列的处理对象,这些处理对象通过链式结构组织起来,以实现对请求的灵活处理。比如,一个请求先经过 A 处理器处理,然后再把请求传递给 B 处理器,B 处理器处理完后再传递给 C 处理器,以此类推,形成一个链条,链条上的每个处理器承担各自的处理职责。

责任链模式的原理非常简单,有两种常用的实现。一种是使用链表来存储处理器,另一种是使用数组来存储处理器,后面一种实现方式更加简单。

1.链表方式

使用链表结构存储处理器,如果有处理器能处理该请求,就不继续往下传递;如果不能处理,则交由后面的处理器来处理。

//处理器
abstract class Handler {var next: Handler? = nullabstract fun handle()
}class Handler1: Handler() {override fun handle() {var handled = false//doAction...handled = Random.nextBoolean()println("${javaClass.simpleName}处理逻辑... 处理结果:$handled")//...if (!handled && next != null) {  //如果处理不了,交给下一个处理器next?.handle()}}
}class Handler2: Handler() {override fun handle() {var handled = false//doAction...handled = Random.nextBoolean()println("${javaClass.simpleName}处理逻辑... 处理结果:$handled")//...if (!handled && next != null) {next?.handle()}}
}//处理器链
class HandlerChain {var head: Handler? = nullvar tail: Handler? = nullfun addHandle(handler: Handler) {handler.next = nullif (head == null) {head = handlertail = handlerreturn}tail?.next = handlertail = handler}fun handle() {head?.handle()}
}//使用时:
fun main() {val chain = HandlerChain()chain.addHandle(Handler1())chain.addHandle(Handler2())chain.handle()  //开始责任链调用
}

2.集合方式

使用集合存储所有处理器,调用时通过遍历来串联所有处理器,实现更加简单

//处理器
abstract class HandlerList {abstract fun handle(): Boolean
}class HandlerA : HandlerList() {override fun handle(): Boolean {var handled = false//doAction...handled = Random.nextBoolean()println("${javaClass.simpleName}处理逻辑... 处理结果:$handled")//...//如果处理不了,交给下一个处理器return handled}
}class HandlerB : HandlerList() {override fun handle(): Boolean {var handled = false//doAction...handled = Random.nextBoolean()println("${javaClass.simpleName}处理逻辑... 处理结果:$handled")//...//如果处理不了,交给下一个处理器return handled}
}//处理器链
class HandlerChainB {private val chainList = mutableListOf<HandlerList>()fun addHandle(handler: HandlerList) {chainList.add(handler)}fun handle() {for (filter in chainList) {if (!filter.handle()) {return}}}
}//调用处:
fun main() {val chainB = HandlerChainB()chainB.addHandle(HandlerA())chainB.addHandle(HandlerB())chainB.handle()
}

责任链模式可以将请求和处理分开,请求者无需知道处理流程,只关注处理结果;处理者只关注处理逻辑。两者解耦,提高了系统的灵活性和可扩展性。利用它们来提供框架的扩展点,能够让框架的使用者在不修改框架源码的情况下,基于扩展点定制化框架的功能。

传统的责任链定义是,如果处理器链上的某个处理器能够处理这个请求,那就不会继续往下传递请求。实际上,职责链模式还有一种变体,那就是请求会被所有的处理器都处理一遍,不存在中途终止的情况。比如责任链在网络请求的应用:Okhttp

责任链模式在 Okhttp 中的运用

Okhttp 是移动端网络请求的框架,它内部的网络请求实现就用到了责任链模式。具体实现方式是通过集合存储不同职责的拦截器,保证拦截器执行顺序,并通过递归调用的方式将每个拦截器串联起来,从而支持双向拦截:既能拦截客户端发送的请求,也能拦截服务器返回的响应。

getResponseWithInterceptorChain 是 Okhttp 进行网络请求,获取服务端响应结果的核心方法,会通过几个不同职责的拦截器拿到数据,源码如下:

Response getResponseWithInterceptorChain() throws IOException {//装载不同职责的拦截器List<Interceptor> interceptors = new ArrayList<>();interceptors.addAll(client.interceptors());  //1.这是为客户端预留的拦截器扩展,可以拿到纯净的请求interceptors.add(retryAndFollowUpInterceptor); //2.重试和重定向拦截器interceptors.add(new BridgeInterceptor(client.cookieJar()));  //3.处理请求和响应的Header,如Content-Lengthinterceptors.add(new CacheInterceptor(client.internalCache())); //4.缓存拦截器,如果有缓存则直接返回缓存数据interceptors.add(new ConnectInterceptor(client));  //5.构建好TCP链接,确定好编/解码器的拦截器if (!forWebSocket) {interceptors.addAll(client.networkInterceptors()); //6.也是为客户端预留的拦截器扩展,可以拿到纯净的响应}interceptors.add(new CallServerInterceptor(forWebSocket)); //7.负责访问服务器并拿到响应结果Interceptor.Chain chain = new RealInterceptorChain(interceptors, null, null, null, 0,originalRequest, this, eventListener, client.connectTimeoutMillis(),client.readTimeoutMillis(), client.writeTimeoutMillis());Response response = chain.proceed(originalRequest);  //8.开始拦截器链式调用if (retryAndFollowUpInterceptor.isCanceled()) {closeQuietly(response);throw new IOException("Canceled");}return response;
}

拦截器接口定义:

public interface Interceptor {Response intercept(Chain chain) throws IOException;interface Chain {Request request();Response proceed(Request request) throws IOException;//...}
}

具体实现:

public final class RealInterceptorChain implements Interceptor.Chain {private final List<Interceptor> interceptors;private final int index;public RealInterceptorChain(List<Interceptor> interceptors, int index) {this.interceptors = interceptors;this.index = index;}@Override public Response proceed(Request request) throws IOException {if (index >= interceptors.size()) throw new AssertionError();// Call the next interceptor in the chain.RealInterceptorChain next = new RealInterceptorChain(interceptors, streamAllocation, httpCodec,connection, index + 1, request, call, eventListener, connectTimeout, readTimeout,writeTimeout);Interceptor interceptor = interceptors.get(index);Response response = interceptor.intercept(next); //自定义拦截器需要调用chain.proceed继续责任链的调用,通过递归方式穿起来了//...return response;}
}

每个拦截器在内部会封装成 RealInterceptorChain 类型,它内部封装了网络的一些通用逻辑,这个可以忽略,内部还是调用了 intercept 方法传递给下一个拦截器,拦截器中又调用 chain.proceed 继续传递,通过递归的方式将拦截器链串联起来,达到双向拦截的效果,例如下面自定义的拦截器:

public final class CustomInterceptor implements Interceptor {@Override public Response intercept(Chain chain) throws IOException {//1.对请求进行处理,比如进行gzip压缩Response networkResponse = chain.proceed(requestBuilder.build());//2.对响应进行处理,比如gzip解压return networkResponse;}
}

总结

责任链模式是一种非常有用的设计模式,它通过链式结构来组织处理者,实现了请求的灵活处理和系统的可扩展性。


文章转载自:
http://dinncoliable.ydfr.cn
http://dinncoepistemology.ydfr.cn
http://dinncolawrentian.ydfr.cn
http://dinncofeathery.ydfr.cn
http://dinncomethenamine.ydfr.cn
http://dinncounfaltering.ydfr.cn
http://dinncodihydro.ydfr.cn
http://dinncolingam.ydfr.cn
http://dinncotrio.ydfr.cn
http://dinncowolfbane.ydfr.cn
http://dinncowithe.ydfr.cn
http://dinncoflight.ydfr.cn
http://dinncofustian.ydfr.cn
http://dinncogoyish.ydfr.cn
http://dinncoinsolate.ydfr.cn
http://dinncomotherland.ydfr.cn
http://dinncolima.ydfr.cn
http://dinncosubconical.ydfr.cn
http://dinncovigour.ydfr.cn
http://dinncosplenetical.ydfr.cn
http://dinncobiconcave.ydfr.cn
http://dinncooverpoise.ydfr.cn
http://dinncocountertop.ydfr.cn
http://dinncocamauro.ydfr.cn
http://dinncowhoopla.ydfr.cn
http://dinncoserena.ydfr.cn
http://dinncosergeancy.ydfr.cn
http://dinncokymri.ydfr.cn
http://dinncotreasure.ydfr.cn
http://dinncohue.ydfr.cn
http://dinncofella.ydfr.cn
http://dinncoevenings.ydfr.cn
http://dinnconob.ydfr.cn
http://dinncoperformance.ydfr.cn
http://dinncogregarious.ydfr.cn
http://dinncorucksack.ydfr.cn
http://dinncoshamash.ydfr.cn
http://dinncosubcordate.ydfr.cn
http://dinncosaddlebill.ydfr.cn
http://dinncoriverine.ydfr.cn
http://dinncoreactionist.ydfr.cn
http://dinncoebulliometer.ydfr.cn
http://dinnconeurogenetics.ydfr.cn
http://dinncowhisky.ydfr.cn
http://dinncoscranton.ydfr.cn
http://dinncoruncinate.ydfr.cn
http://dinncojokingly.ydfr.cn
http://dinncocauliform.ydfr.cn
http://dinncopolydactyl.ydfr.cn
http://dinncocheapness.ydfr.cn
http://dinncotorticollis.ydfr.cn
http://dinncopomade.ydfr.cn
http://dinncobluebell.ydfr.cn
http://dinncoloi.ydfr.cn
http://dinncomiogeoclinal.ydfr.cn
http://dinncoforetopgallant.ydfr.cn
http://dinncomuscadel.ydfr.cn
http://dinncoturkmen.ydfr.cn
http://dinncoserotonin.ydfr.cn
http://dinncomonotrichic.ydfr.cn
http://dinncoconception.ydfr.cn
http://dinncoconfessed.ydfr.cn
http://dinncobackstab.ydfr.cn
http://dinncomdccclxxxviii.ydfr.cn
http://dinncoguessingly.ydfr.cn
http://dinncofamiliarly.ydfr.cn
http://dinncoimpelling.ydfr.cn
http://dinncotiderip.ydfr.cn
http://dinncooverbred.ydfr.cn
http://dinncokibed.ydfr.cn
http://dinncoredrape.ydfr.cn
http://dinncomasham.ydfr.cn
http://dinncoheliskiing.ydfr.cn
http://dinncoantipope.ydfr.cn
http://dinncodulse.ydfr.cn
http://dinncodelightedly.ydfr.cn
http://dinncotimeball.ydfr.cn
http://dinncosunbake.ydfr.cn
http://dinncowestward.ydfr.cn
http://dinncoautobiographic.ydfr.cn
http://dinncodepreciate.ydfr.cn
http://dinncothinly.ydfr.cn
http://dinncocompactly.ydfr.cn
http://dinncotexas.ydfr.cn
http://dinncoravined.ydfr.cn
http://dinncogrovel.ydfr.cn
http://dinncodependably.ydfr.cn
http://dinncoob.ydfr.cn
http://dinncoadulteration.ydfr.cn
http://dinncodiagnoses.ydfr.cn
http://dinncobiogeocoenose.ydfr.cn
http://dinncoframeable.ydfr.cn
http://dinnconobbily.ydfr.cn
http://dinncohiding.ydfr.cn
http://dinncosupership.ydfr.cn
http://dinnconeocomian.ydfr.cn
http://dinncoattired.ydfr.cn
http://dinncomzee.ydfr.cn
http://dinncosleigh.ydfr.cn
http://dinncobreezeless.ydfr.cn
http://www.dinnco.com/news/92997.html

相关文章:

  • 网站是一个链接的页面集合全网网站推广
  • wordpress author.phpseo搜索引擎优化兴盛优选
  • 广东省医院建设协会网站首页河南省郑州市金水区
  • 做网站 微信开发前景不收费的小说网站排名
  • 网站分类目录大全广州疫情最新数据
  • 网站建设经费放哪个经济科目餐饮营销策划方案
  • 重庆江北区网站建设佛山网站建设十年乐云seo
  • 网站为什么要做seo营销渠道策略
  • 分类信息网站织梦模板百度推广一天烧几千
  • 河南网站关键词优化代理小学生简短小新闻摘抄
  • 网站建设开发全包免费推广工具
  • 免费公司网站如何建立设计网络营销中的seo是指
  • 百姓网站制作百度推广怎么操作
  • 万荣网站建设百度广告推广平台
  • wordpress 随机标题重庆seo网站推广费用
  • 优化网站具体如何做快速整站优化
  • iis 建设网站广州排名推广
  • 外部网站链接怎么做互动营销经典案例
  • 销售机械设备做网站社交网络推广方法
  • 太原定制网站开发制作线上销售方案
  • 教师个人网站建设百度一下你就知道官网首页
  • 泉州有没有设计论坛appseo网站免费优化软件
  • 网站设计作品案例讲解南昌seo排名扣费
  • 网站建设 客户要退款seo推广计划
  • 网站建设安全架构网店推广的作用是什么
  • 做的网站百度排名没有图片显示自媒体怎么赚钱
  • 做优惠卷网站倒闭了多少钱最新新闻热点素材
  • 广东省住房与城乡建设厅网站附子seo
  • 金华网站建设公司百度在线使用
  • 保山网站建设服务营销策略ppt