sitemule / ILEastic

Embedded application server for ILE on IBM i
Apache License 2.0
58 stars 29 forks source link

Add a isShutdownRequested() callback (enhancement request) #58

Closed tools400 closed 5 years ago

tools400 commented 5 years ago

It was great, if ILEastic could be changed to use a non-blocking listener socket so that it can periodically call a isShutdownRequested() callback procedure. To keep ILEastic 100% backward compatible, it could use the existing blocking socket if the callback is not set. Background information: First of all I think it is bad style to end jobs with ENDJOB OPTION(*IMMED). Second, in case we make the decision to use ILEastic, it should (maybe even it must) be possible to integrate it into our framework that we use for controlling asynchronously running jobs (never ending jobs). Of course I know, that ILEastic can not accept requests while it is in the callback procedure. But is that a blocker, if ,for example, the callback just checks a flag, a data area, a data queue or %shtdn()?

NielsLiisberg commented 5 years ago

What about a Shutdown thread? so you just provide the plugin and register it and ILEastic calls it from a thread? just like the rest of the ILEastic architecture ( i.e. the router plugin and the authorization plugin)

Doing it in a thread will allow blocking listening and still having the polling flexibility - and even do a %shtdn() by default so ENDJOB OPTION(*CNTRLD) will also work.

What about that?

NielsLiisberg commented 5 years ago

Done !! Now it supports both: 1) Gracefull shutdown: by ENDJOB JOB(ILEASTIC) OPTION(*CNTRLD)
2) Have a scheduler that can detect any other programatically "end condition" and/or doing housekeeping and statistics / logging in a separate thread. Look in sample "/examples/Sehecduler.rpgle"

tools400 commented 5 years ago

Looks great. I did not yet test it, but the changes and the scheduler example looks great. Good job!