How to run an arbitrary server in the Container.
Familiarity with the Developer Guide is assumed.
JDisc servers
JDisc servers are the most abstract level in JDisc, they are an arbitrary service with a life cycle.
JDisc will start the service and stop the service as required,
but what the service actually does is fully up to the user.
JDisc only handles basic infrastructure in this case, and makes no assumptions about what a service is.
The server class
Set up a project as in the Developer Guide,
then create hello_world/components/src/main/java/com/mydomain/demo/HelloWorldServer.java:
The important part is the class com.yahoo.jdisc.service.AbstractServerProvider.
This provides wiring, so it is possible for JDisc to do life cycle management,
while the example is left to implement the actual server.
A server is defined by the interface com.yahoo.jdisc.service.ServerProvider,
it contains only two methods: void start() and void close().
A server can in other words be pretty much anything,
the container just makes life cycle management, reconfiguration and so on available as needed.
The configuration class
The demo server requires a custom configuration class, it is defined in
components/src/main/resources/configdefinitions/hello-world-server.def:
package=com.mydomain.demo
response string default="No config value given."
port int
Notice how hyphens in the file name are converted to camel-casing in the generated class name.
The application
Everything is pretty much the same as when writing a basic handler, though,
as the server is not directly connected to HTTP, it has no binding.
Our custom configuration configures the HelloWorldServer to bind to port 16889.