You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicecomb.apache.org by 郑扬勇 <ya...@qq.com> on 2018/05/08 06:53:00 UTC

[Discussion]What Java Chassis need to do for support Gracefully Shutdown

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

回复: [Discussion]What Java Chassis need to do for support Gracefully Shutdown

Posted by 郑扬勇 <ya...@qq.com>.
Hi all:
 I had make some improvement base on current mechanism and PR is here : https://github.com/apache/incubator-servicecomb-java-chassis/pull/693 , I think it is enough.
   
 When user call system.exit(0),these three works will do:
 1.Unregister microservice instance from Service Center:
 this work will do by process ContextClosedEvent, we need unregister immediately for stopping provide service any more.
 2.Waiting for all invocations to finish:
 this work will do by ShutdownHandler, when all invocations finished or 'deadline time reached', cc and transport vertx threads will close.
 3.All spring bean do close process
 we had registerShutdownHook for spring ApplicationContext and beans can define 'destroy-method' do cleaning.
 
here is example:
  
 Spring mvc Hello Java Chassis
Pojo Hello person ServiceComb/Java Chassis
Jaxrs Hello person ServiceComb/Java Chassis
Spring mvc Hello person ServiceComb/Java Chassis
2018-05-09 16:02:14,288 [WARN] handler chain is shutting down org.apache.servicecomb.core.handler.ShutdownHookHandler.run(ShutdownHookHandler.java:87)
2018-05-09 16:02:14,289 [INFO] Closing org.springframework.context.support.ClassPathXmlApplicationContext@7cf10a6f: startup date [Wed May 09 16:02:05 CST 2018]; root of context hierarchy org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:984)
2018-05-09 16:02:14,290 [WARN] cse is closing now... org.apache.servicecomb.core.CseApplicationListener.onApplicationEvent(CseApplicationListener.java:148)
2018-05-09 16:02:14,291 [INFO] service center task is shutdown. org.apache.servicecomb.serviceregistry.registry.RemoteServiceRegistry.onShutdown(RemoteServiceRegistry.java:72)
2018-05-09 16:02:14,295 [WARN] handler chain is shut down org.apache.servicecomb.core.handler.ShutdownHookHandler.run(ShutdownHookHandler.java:103)
2018-05-09 16:02:14,296 [INFO] Unregister microservice instance success. microserviceId=90b76fd551c511e8b51db4b676a39f40 instanceId=481f630d535f11e8bc19b4b676a39f40 org.apache.servicecomb.serviceregistry.registry.AbstractServiceRegistry.unregisterInstance(AbstractServiceRegistry.java:232)
 Process finished with exit code 0
  
 Best Regards!
 YangYongZheng
  
 ------------------ 原始邮件 ------------------
  发件人: "wjm wjm"<zz...@gmail.com>;
 发送时间: 2018年5月9日(星期三) 下午3:06
 收件人: "dev"<de...@servicecomb.apache.org>;
 
 主题: Re: [Discussion]What Java Chassis need to do for support Gracefully Shutdown

 

it's impossible
we are a framework, we can handle shutdown work in one place

but how can customer do in this places?
shutdown process is ordered, if customer's shutdown work processed before
us, then exists invocations maybe can not finished.

2018-05-09 14:40 GMT+08:00 Willem Jiang <wi...@gmail.com>:

> 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 <zz...@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 <wi...@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, 郑扬勇 <ya...@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"<zz...@gmail.com>;
> > > >  发送时间: 2018年5月8日(星期二) 下午3:50
> > > >  收件人: "dev"<de...@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 <wi...@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, 郑扬勇 <ya...@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
> > > > >
> > > >
> > >
> >
>

Re: [Discussion]What Java Chassis need to do for support Gracefully Shutdown

Posted by Willem Jiang <wi...@gmail.com>.
Oh, let me make it clear.
As Liubao said, we have two place to do the shutdown work.

"Now java-chassis doing the following:
1. A shutdown hook for spring context shutdown and unregistered from
service center
2. A shutdown hook waiting for all invocations to finish"

My suggestion is unify the shutdown process from two hooks.
If user has some customer shutdown producers to use, we could provide an
interface for them to hook up.



Willem Jiang

Blog: http://willemjiang.blogspot.com (English)
          http://jnn.iteye.com  (Chinese)
Twitter: willemjiang
Weibo: 姜宁willem

On Wed, May 9, 2018 at 3:06 PM, wjm wjm <zz...@gmail.com> wrote:

> it's impossible
> we are a framework, we can handle shutdown work in one place
>
> but how can customer do in this places?
> shutdown process is ordered, if customer's shutdown work processed before
> us, then exists invocations maybe can not finished.
>
> 2018-05-09 14:40 GMT+08:00 Willem Jiang <wi...@gmail.com>:
>
> > 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 <zz...@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 <wi...@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, 郑扬勇 <ya...@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"<zz...@gmail.com>;
> > > > >  发送时间: 2018年5月8日(星期二) 下午3:50
> > > > >  收件人: "dev"<de...@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 <wi...@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, 郑扬勇 <ya...@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
> > > > > >
> > > > >
> > > >
> > >
> >
>

Re: [Discussion]What Java Chassis need to do for support Gracefully Shutdown

Posted by wjm wjm <zz...@gmail.com>.
it's impossible
we are a framework, we can handle shutdown work in one place

but how can customer do in this places?
shutdown process is ordered, if customer's shutdown work processed before
us, then exists invocations maybe can not finished.

2018-05-09 14:40 GMT+08:00 Willem Jiang <wi...@gmail.com>:

> 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 <zz...@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 <wi...@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, 郑扬勇 <ya...@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"<zz...@gmail.com>;
> > > >  发送时间: 2018年5月8日(星期二) 下午3:50
> > > >  收件人: "dev"<de...@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 <wi...@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, 郑扬勇 <ya...@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
> > > > >
> > > >
> > >
> >
>

Re: [Discussion]What Java Chassis need to do for support Gracefully Shutdown

Posted by Willem Jiang <wi...@gmail.com>.
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 <zz...@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 <wi...@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, 郑扬勇 <ya...@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"<zz...@gmail.com>;
> > >  发送时间: 2018年5月8日(星期二) 下午3:50
> > >  收件人: "dev"<de...@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 <wi...@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, 郑扬勇 <ya...@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
> > > >
> > >
> >
>

Re: [Discussion]What Java Chassis need to do for support Gracefully Shutdown

Posted by wjm wjm <zz...@gmail.com>.
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 <wi...@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, 郑扬勇 <ya...@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"<zz...@gmail.com>;
> >  发送时间: 2018年5月8日(星期二) 下午3:50
> >  收件人: "dev"<de...@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 <wi...@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, 郑扬勇 <ya...@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
> > >
> >
>

Re: [Discussion]What Java Chassis need to do for support Gracefully Shutdown

Posted by Willem Jiang <wi...@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, 郑扬勇 <ya...@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"<zz...@gmail.com>;
>  发送时间: 2018年5月8日(星期二) 下午3:50
>  收件人: "dev"<de...@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 <wi...@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, 郑扬勇 <ya...@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
> >
>

回复: [Discussion]What Java Chassis need to do for support Gracefully Shutdown

Posted by 郑扬勇 <ya...@qq.com>.
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"<zz...@gmail.com>;
 发送时间: 2018年5月8日(星期二) 下午3:50
 收件人: "dev"<de...@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 <wi...@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, 郑扬勇 <ya...@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
>

Re: [Discussion]What Java Chassis need to do for support Gracefully Shutdown

Posted by wjm wjm <zz...@gmail.com>.
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 <wi...@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, 郑扬勇 <ya...@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
>

回复: [Discussion]What Java Chassis need to do for support Gracefully Shutdown

Posted by bismy <bi...@qq.com>.
I think we should focus on "data" and "transactions". "Threads" and "Network Resources" will collected by operation system when process exit and sometimes is very hard to clean.


Now java-chassis doing the following:
1. A shutdown hook for spring context shutdown and unregistered from service center
2. A shutdown hook waiting for all invocations to finish


As users can add their owner shutdown hooks to clean business data, I think we do not necessarily provide other ways(like events) .


If someone provide some more scenarios related to "data" and "transactions" is preferred.




------------------ 原始邮件 ------------------
发件人: "willem.jiang"<wi...@gmail.com>;
发送时间: 2018年5月8日(星期二) 下午2:56
收件人: "dev"<de...@servicecomb.apache.org>;

主题: Re: [Discussion]What Java Chassis need to do for support Gracefully Shutdown



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, 郑扬勇 <ya...@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

Re: [Discussion]What Java Chassis need to do for support Gracefully Shutdown

Posted by Willem Jiang <wi...@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, 郑扬勇 <ya...@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