-
Notifications
You must be signed in to change notification settings - Fork 97
Hosting Custom Services On Xenon
The Xenon framework comes with a set of core services but it is meant as general hosting framework, where authors create a set of services, package them in a JAR, then start them using either a custom host, invoked from the command line, or through dynamic loading.
Please first take a look at the example service tutorial to get an idea on how to build and interact with Xenon services.
To start a Xenon process, with custom services, you need to follow these steps
- create a new JAR that represents your host.
- add the Xenon jar as a dependency
- add a custom host class, that derives from ServiceHost
- Override the start() method and start the core services
- Start any additional services you created.
To start your host invoke it using the java 8 jvm:
java --jar .jar --port
More details on starting one or more Xenon hosts, see the debugging page
Here is a snippet from the source, showing the few lines needed in creating a custom host:
class ExampleServiceHost extends ServiceHost {
public static void main(String[] args) throws Throwable {
ExampleServiceHost h = new ExampleServiceHost();
h.initialize(args);
h.start();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
h.log(Level.WARNING, "Host stopping ...");
h.stop();
h.log(Level.WARNING, "Host is stopped");
}));
}
@Override
public ServiceHost start() throws Throwable {
super.start();
startDefaultCoreServicesSynchronously();
// start the example factory
super.startService(new ExampleFactoryService());
return this;
}
}
The following are needed:
- a static main() that creates an instance of the custom host class (which derives from ServiceHost)
- call to the super class initialize(args) method, with the command line arguments
- call to the super class start() method
- Override of the start() method
- starting the core services
- starting any additional, custom services (in this case, we start the provisioning services)
The custom host jar can include service classes or services can be packaged in their own jar so they can be re-used by other projects.
See the xenon-loader package, it provides a service for finding and loading xenon services from jar files, dynamically.