I think its better to have one place to handle the shutdown work.
Willem Jiang Blog: http://willemjiang.blogspot.com (English) http://jnn.iteye.com (Chinese) Twitter: willemjiang Weibo: 姜宁willem On Tue, May 8, 2018 at 4:36 PM, wjm wjm <zzz...@gmail.com> wrote: > eventBus maybe not a good idea > because eventBus is not ordered, we can not control which one run first. > > 2018-05-08 16:33 GMT+08:00 Willem Jiang <willem.ji...@gmail.com>: > > > How about register a Vertx thread clean up task in the event bus? > > > > Then we just need to trigger the Event after close. > > > > And the user can do some extension it by adding event handler which > listens > > to the close event. > > > > > > Willem Jiang > > > > Blog: http://willemjiang.blogspot.com (English) > > http://jnn.iteye.com (Chinese) > > Twitter: willemjiang > > Weibo: 姜宁willem > > > > On Tue, May 8, 2018 at 4:27 PM, 郑扬勇 <yangyong.zh...@qq.com> wrote: > > > > > Yes, mechanism based on spring had existed, and I had use these code to > > > make Gracefully Shutdown work : > > > > > > ... start up event code > > > } else if (event instanceof ContextClosedEvent) { > > > LOGGER.warn("cse is closing now..."); > > > triggerEvent(EventType.BEFORE_CLOSE); > > > > > > //1.Unregister microservice instance from Service Center > > > //it contains eventBus.post(new ShutdownEvent());I think we may > > move > > > out from it > > > RegistryUtils.destroy(); > > > > > > //2.Stop all network transport threads > > > for (String vertx : VertxUtils.getVertxMap(). > keySet().toArray(new > > > String[0])) { > > > VertxUtils.getVertxMap().get(vertx).close(); > > > VertxUtils.getVertxMap().remove(vertx); > > > } > > > > > > //3.Close ApplicationContext > > > if (applicationContext instanceof AbstractApplicationContext) { > > > ((AbstractApplicationContext) applicationContext).close(); > > > } > > > > > > //4.Raise an ShutdownEvent in EventBus in order to notify > > > components do clean works > > > //eventBus.post(new ShutdownEvent()); > > > > > > triggerEvent(EventType.AFTER_CLOSE); > > > isInit = false; > > > } > > > > > > > > > And I think we can use EventBus listening ShutdownEvent rather than > only > > > use SPI, may even simpler ? > > > > > > Best Regards! > > > YangYongZheng > > > > > > ------------------ 原始邮件 ------------------ > > > 发件人: "wjm wjm"<zzz...@gmail.com>; > > > 发送时间: 2018年5月8日(星期二) 下午3:50 > > > 收件人: "dev"<dev@servicecomb.apache.org>; > > > > > > 主题: Re: [Discussion]What Java Chassis need to do for support > Gracefully > > > Shutdown > > > > > > > > > > > > we already have this mechanism, but listener depend on spring bean. > > > so we can improve it: > > > 1.allow listener registered by SPI > > > 2.modules should register listener to do their clean up works > > > 3.clean up maybe must ordered, so listener add getOrder method. > > > > > > 2018-05-08 14:56 GMT+08:00 Willem Jiang <willem.ji...@gmail.com>: > > > > > > > My suggestion is register a shutdown callback (to do 1,2,4) in the > > > > ApplicationContext. > > > > In this way we can do some clean up work with or without Spring. > > > > > > > > > > > > Willem Jiang > > > > > > > > Blog: http://willemjiang.blogspot.com (English) > > > > http://jnn.iteye.com (Chinese) > > > > Twitter: willemjiang > > > > Weibo: 姜宁willem > > > > > > > > On Tue, May 8, 2018 at 2:53 PM, 郑扬勇 <yangyong.zh...@qq.com> wrote: > > > > > > > > > Hi All: > > > > > In order to let Java Chassis support Gracefully Shutdown, I > think > > > need > > > > > to do these works : > > > > > 1.Unregister microservice instance from Service Center(clean > > service > > > > > registry). > > > > > 2.Stop all network transport threads (vertx > eventloop-threads)(to > > > > > prevent blocking exit). > > > > > 3.Close ClassPathXmlApplicationContext created in > BeanUtils.init() > > > and > > > > > release all resources and locks. > > > > > 4.Raise an ShutdownEvent in EventBus. > > > > > > > > > > Also if user directly call `System.exit(0)` , all these works > will > > > > done > > > > > and jvm can terminate with `Process finished with exit code 0`. > > > > > > > > > > What's missing or any suggestions are welcome ! > > > > > > > > > > Best Regards! > > > > > YangYongZheng > > > > > > > > > >