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

自己做黑彩网站云南网络推广服务

自己做黑彩网站,云南网络推广服务,wordpress wp-postviews插件,深圳龙岗疫情情况从监听器到事件 SpringApplication运行中触发事件,多播器发送事件到监听器,监听器处理事件。 SpingApplication中事件都是经过SpringApplicationRunListeners类传送到各个监听器。 以starting事件为例 void starting(ConfigurableBootstrapContext boo…

从监听器到事件

SpringApplication运行中触发事件,多播器发送事件到监听器,监听器处理事件。
SpingApplication中事件都是经过SpringApplicationRunListeners类传送到各个监听器。
以starting事件为例

void starting(ConfigurableBootstrapContext bootstrapContext, Class<?> mainApplicationClass) {doWithListeners("spring.boot.application.starting", (listener) -> listener.starting(bootstrapContext),(step) -> {if (mainApplicationClass != null) {step.tag("mainApplicationClass", mainApplicationClass.getName());}});
}
private void doWithListeners(String stepName, Consumer<SpringApplicationRunListener> listenerAction,Consumer<StartupStep> stepAction) {StartupStep step = this.applicationStartup.start(stepName);this.listeners.forEach(listenerAction);if (stepAction != null) {stepAction.accept(step);}step.end();
}

这里的this.listeners是一个SpringApplicationRunListener的集合,而SpringApplicationRunListener的实现类配置中只有一个EventPublishingRunListener
starting事件执行的是EventPublishingRunListenerstarting方法

public void starting(ConfigurableBootstrapContext bootstrapContext) {this.initialMulticaster.multicastEvent(new ApplicationStartingEvent(bootstrapContext, this.application, this.args));
}

这里就找到了第一个事件ApplicationStartingEvent
接着往下执行

public void multicastEvent(ApplicationEvent event) {multicastEvent(event, resolveDefaultEventType(event));
}@Override
public void multicastEvent(final ApplicationEvent event, @Nullable ResolvableType eventType) {ResolvableType type = (eventType != null ? eventType : resolveDefaultEventType(event));Executor executor = getTaskExecutor();for (ApplicationListener<?> listener : getApplicationListeners(event, type)) {if (executor != null) {executor.execute(() -> invokeListener(listener, event));}else {invokeListener(listener, event);}}
}

ResolvableType类这里略过,里面涉及的内容较多,在这里的具体作用是从类的注解、泛型、继承结构、代理上获取原始的目标对象。
这里要注意的方法getApplicationListeners,根据事件类型获取监听器,然后执行。
查找的过程比较长,这里列举一些比较重要的方法
AbstractApplicationEventMulticastergetApplicationListenersretrieveApplicationListenerssupportsEvent
supportsEvent方法中有具体的判断逻辑

protected boolean supportsEvent(ApplicationListener<?> listener, ResolvableType eventType, @Nullable Class<?> sourceType) {GenericApplicationListener smartListener = (listener instanceof GenericApplicationListener ?(GenericApplicationListener) listener : new GenericApplicationListenerAdapter(listener));return (smartListener.supportsEventType(eventType) && smartListener.supportsSourceType(sourceType));
}

根据监听器的类型调用监听器类的支持事件类型supportsEventType和支持事件源类型supportsSourceType两个方法,来判断是否传播到该监听器。
ApplicationListener监听器有多个实现。

  • ClearCachesApplicationListener
  • ParentContextCloserApplicationListener
  • FileEncodingApplicationListener
  • AnsiOutputApplicationListener
  • DelegatingApplicationListener
  • LoggingApplicationListener
  • EnvironmentPostProcessorApplicationListener
  • BackgroundPreinitializer

ClearCachesApplicationListener

结构:
implements ApplicationListener<ContextRefreshedEvent>
支持的事件类型:

  • ContextRefreshedEvent
  • ApplicationContextEvent
  • ApplicationEvent

支持的事件源:
无限制

ParentContextCloserApplicationListener

结构:
implements ApplicationListener<ParentContextAvailableEvent>, ApplicationContextAware, Ordered
支持的事件类型

  • ParentContextAvailableEvent
  • ApplicationEvent

支持的事件源:
无限制

FileEncodingApplicationListener

结构:
implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered
支持的事件类型:

  • ApplicationEnvironmentPreparedEvent
  • SpringApplicationEvent
  • ApplicationEvent

支持的事件源:
无限制

AnsiOutputApplicationListener

结构:
implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered
支持的事件类型:

  • ApplicationEnvironmentPreparedEvent
  • SpringApplicationEvent
  • ApplicationEvent

支持的事件源:
无限制

DelegatingApplicationListener

结构:
implements ApplicationListener<ApplicationEvent>, Ordered
支持的事件类型:

  • ApplicationEvent

支持的事件源:
无限制

LoggingApplicationListener

结构:
implements GenericApplicationListener
支持的事件类型:

  • ApplicationStartingEvent
  • ApplicationEnvironmentPreparedEvent
  • ApplicationPreparedEvent
  • ContextClosedEvent
  • ApplicationFailedEvent

支持的事件源:

  • SpringApplication
  • ApplicationContext

EnvironmentPostProcessorApplicationListener

结构:
implements SmartApplicationListener, Ordered
支持的事件类型:

  • ApplicationEnvironmentPreparedEvent
  • ApplicationPreparedEvent
  • ApplicationFailedEvent

支持的事件源:

  • SpringApplication
  • ApplicationContext

BackgroundPreinitializer

结构:
implements ApplicationListener<SpringApplicationEvent>
支持的事件类型:

  • SpringApplicationEvent
  • ApplicationEvent

支持的事件源:
无限制

事件

EventPublishingRunListener的方法还有上面的事件类型,SpringBoot中的事件类型有:

  • ApplicationStartingEvent
  • ApplicationEnvironmentPreparedEvent
  • ApplicationContextInitializedEvent
  • ApplicationPreparedEvent
  • ApplicationStartedEvent
  • ApplicationReadyEvent

除了multicastEvent多播事件,还有下面两个方法发布事件。

@Override
public void started(ConfigurableApplicationContext context, Duration timeTaken) {context.publishEvent(new ApplicationStartedEvent(this.application, this.args, context, timeTaken));AvailabilityChangeEvent.publish(context, LivenessState.CORRECT);
}@Override
public void ready(ConfigurableApplicationContext context, Duration timeTaken) {context.publishEvent(new ApplicationReadyEvent(this.application, this.args, context, timeTaken));AvailabilityChangeEvent.publish(context, ReadinessState.ACCEPTING_TRAFFIC);
}

事实上,这些事件都在一个包路径下。
在这里插入图片描述

ApplicationStartingEvent

注释:

事件在启动SpringApplication后尽早发布——在Environment或ApplicationContext可用之前,但在ApplicationListeners注册之后。事件的来源是SpringApplication本身,但要注意在早期阶段不要过多地使用其内部状态,因为它可能会在生命周期的后期被修改。

使用的翻译,不甚明了,得看看怎么这个事件触发后,监听器做了什么。

ApplicationEnvironmentPreparedEvent

注释:

当SpringApplication启动并且环境首次可用于检查和修改时发布的事件

ApplicationContextInitializedEvent

注释:

在启动SpringApplication、准备ApplicationContext和调用ApplicationContextInitializer时发布的事件,但在加载任何bean定义之前。

ApplicationPreparedEvent

注释:

当SpringApplication正在启动并且ApplicationContext已完全准备好但未刷新时发布的事件。将加载bean定义,并且环境已准备好在此阶段使用

ApplicationStartedEvent

注释:

刷新应用程序上下文后,但在调用任何应用程序和命令行运行程序之前发布的事件

ApplicationReadyEvent

注释:

事件尽可能晚地发布,以指示应用程序已准备好为请求提供服务。事件的来源是SpringApplication本身,但要注意修改其内部状态,因为届时所有初始化步骤都已完成

ApplicationFailedEvent

注释:

SpringApplication在启动失败时发布的事件


文章转载自:
http://trento.Lnnc.cn
http://achroglobin.Lnnc.cn
http://silica.Lnnc.cn
http://cyclopia.Lnnc.cn
http://multirunning.Lnnc.cn
http://ubiety.Lnnc.cn
http://cloy.Lnnc.cn
http://cystitis.Lnnc.cn
http://bowdlerize.Lnnc.cn
http://harmonicon.Lnnc.cn
http://marquetry.Lnnc.cn
http://infantry.Lnnc.cn
http://contrapositive.Lnnc.cn
http://dele.Lnnc.cn
http://workpeople.Lnnc.cn
http://audiotape.Lnnc.cn
http://winona.Lnnc.cn
http://viticolous.Lnnc.cn
http://holmic.Lnnc.cn
http://foredoom.Lnnc.cn
http://wherethrough.Lnnc.cn
http://paresis.Lnnc.cn
http://versemonger.Lnnc.cn
http://ungifted.Lnnc.cn
http://heartbeat.Lnnc.cn
http://uncart.Lnnc.cn
http://sowbelly.Lnnc.cn
http://encouraged.Lnnc.cn
http://riksdag.Lnnc.cn
http://parasang.Lnnc.cn
http://regressor.Lnnc.cn
http://fortunetelling.Lnnc.cn
http://pastime.Lnnc.cn
http://crud.Lnnc.cn
http://confirmation.Lnnc.cn
http://hematoxylin.Lnnc.cn
http://heathbird.Lnnc.cn
http://pyopericardium.Lnnc.cn
http://haemophilic.Lnnc.cn
http://whosit.Lnnc.cn
http://disparlure.Lnnc.cn
http://colporteur.Lnnc.cn
http://neckline.Lnnc.cn
http://totemism.Lnnc.cn
http://megillah.Lnnc.cn
http://antiseismic.Lnnc.cn
http://pointing.Lnnc.cn
http://bibasic.Lnnc.cn
http://blarney.Lnnc.cn
http://billowy.Lnnc.cn
http://nankin.Lnnc.cn
http://lactide.Lnnc.cn
http://competence.Lnnc.cn
http://meliorable.Lnnc.cn
http://gers.Lnnc.cn
http://kwando.Lnnc.cn
http://behave.Lnnc.cn
http://gjetost.Lnnc.cn
http://isogonic.Lnnc.cn
http://jesuit.Lnnc.cn
http://entomostracan.Lnnc.cn
http://seletron.Lnnc.cn
http://globularity.Lnnc.cn
http://boulangerite.Lnnc.cn
http://japanophobe.Lnnc.cn
http://zhujiang.Lnnc.cn
http://odontophore.Lnnc.cn
http://siwan.Lnnc.cn
http://arrogation.Lnnc.cn
http://demode.Lnnc.cn
http://motorboat.Lnnc.cn
http://matchbyte.Lnnc.cn
http://neuropathic.Lnnc.cn
http://doesnot.Lnnc.cn
http://gabun.Lnnc.cn
http://synkaryon.Lnnc.cn
http://botanize.Lnnc.cn
http://jpeg.Lnnc.cn
http://singaporean.Lnnc.cn
http://ocso.Lnnc.cn
http://amphigouri.Lnnc.cn
http://separationist.Lnnc.cn
http://cordelier.Lnnc.cn
http://immaterialize.Lnnc.cn
http://illiberally.Lnnc.cn
http://capsulotomy.Lnnc.cn
http://provocator.Lnnc.cn
http://upsides.Lnnc.cn
http://ronggeng.Lnnc.cn
http://ldh.Lnnc.cn
http://sevruga.Lnnc.cn
http://ferromagnesian.Lnnc.cn
http://leptospire.Lnnc.cn
http://productile.Lnnc.cn
http://registrary.Lnnc.cn
http://steering.Lnnc.cn
http://mushy.Lnnc.cn
http://horologe.Lnnc.cn
http://stentor.Lnnc.cn
http://claxon.Lnnc.cn
http://www.dt0577.cn/news/121252.html

相关文章:

  • 网站底部版权信息格式制作网站的全过程
  • 做网站违反广告法关键词优化技巧有哪些
  • 网站设计项目网络推广工作怎么样
  • 学校网站设计图片网站seo视频教程
  • 做手机网站要注意营销方案怎么写模板
  • 必要是什么网站惠州seo优化服务
  • 模版网站系统软文发布门户网站
  • 临桂住房和城乡建设局网站头条搜索
  • 外贸建设网站制作外贸自建站的推广方式
  • 推广网站名是什么网站制作公司高端
  • 海口做网站哪家好推广手段和渠道有哪些
  • 南京网站建设工作室怎么找平台推广自己的产品
  • 聊城哪有做网站的南宁百度推广排名优化
  • 城乡建设网站职业查询系统百度搜索热词排行榜
  • 网站制作性价比哪家好中国关键词网站
  • 做阿里巴巴跟网站哪个更好外贸推广平台
  • 做网站的视频教学怎么找到当地的微信推广
  • 淄博做网站公司百度指数分是什么
  • 网站建设备案优化百度竞价网站
  • 有没有人一起做网站中山seo关键词
  • 两个路由器做双网站青岛推广优化
  • 深圳做外贸网站长沙seo网络公司
  • 有没有帮别人做图片的网站赚钱营销推广是什么
  • 做b2c网站价格计算机培训机构
  • 做技术网站赚钱吗天津债务优化公司
  • 宁夏网站建站广西seo
  • 网站备案承诺书通过百度指数不能判断出
  • 深圳龙岗做网站5月新冠病毒最新消息
  • 网站安全性要求厦门网站推广优化哪家好
  • wordpress能不能做商城深圳网站优化公司哪家好