{8.0.0-new, 8.1.2-deprecated} Listeners

As mentioned previously, the lifecycle methods for the {@link oaj.microservice.Microservice} class are explicitly defined as non-final so that they can be overridden by subclasses.

In addition to this support, an interface for defining event listeners for your microservice:

This listener API can be used for listening for and reacting to configuration changes on the file system.

public class MyMicroserviceListener extends BasicMicroserviceListener { @Override /* MicroserviceListener */ public void onConfigChange(Microservice microservice, ConfigEvents events) { // Restart the microservice if anything was modified in one of our sections if (events.isSectionChanged("MySection")) microservice.stop().start(); } }

Note that the {@link oaj.microservice.Microservice#onConfigChange(ConfigEvents)} method can also be overridden to react to configuration changes as well:

public class MyMicroservice extends Microservice { @Override /* MicroserviceListener */ public void onConfigChange(ConfigEvents events) { // Restart the microservice if anything was modified in one of our sections if (events.isSectionChanged("MySection")) this.stop().start(); } }