{8.0.0-new, 8.1.2-deprecated} Extending JettyMicroservice

This example shows how the {@link oaj.microservice.jetty.JettyMicroservice} class can be extended to implement lifecycle listener methods or override existing methods. We'll create a new class com.foo.MyJettyMicroservice.

/** * Sample subclass of a JettyMicroservice that provides customized behavior. */ public class MyJettyMicroservice extends JettyMicroservice { public static void main(String[] args) throws Exception { JettyMicroserviceBuilder builder = JettyMicroservice.create(); new MyJettyMicroservice(builder).start().join(); } public MyJettyMicroservice(JettyMicroserviceBuilder builder) throws Exception { super(builder); } // Customized code here.

Optionally, you can extend the {@link oaj.microservice.jetty.JettyMicroserviceBuilder} class as well:

public class MyJettyMicroserviceBuilder extends JettyMicroserviceBuilder { int extraField; /** * Constructor (required). */ protected MyJettyMicroserviceBuilder() {} /** * Copy constructor (required). * * @param copyFrom The builder to copy settings from. */ protected MyJettyMicroserviceBuilder(MyJettyMicroserviceBuilder copyFrom) { super(copyFrom); } // Additional setters public MyJettyMicroserviceBuilder extraField(int extraField) { this.extraField = extraField; return this; } // Overridden methods @Override /* JettyMicroserviceBuilder */ public MyJettyMicroserviceBuilder copy() { return new MyJettyMicroserviceBuilder(this); } @Override /* JettyMicroserviceBuilder */ public MyJettyMicroserviceBuilder ports(int...ports) { super.ports(ports); return this; } @Override /* JettyMicroserviceBuilder */ public MyJettyMicroserviceBuilder servlet(Class<? extends RestServlet> c) throws InstantiationException, IllegalAccessException { super.servlet(c); return this; } ... }