A Custom Service is a Java Object you write and configure to run within the Unity 2 Multiuser Server (U2MS) application. Because Custom Services are instantiatied
by U2MS they have full access to the set of built in U2MS Services. Using a Custom Service the ability
to create complex interactions with Unity become almost limitless.
Examples of Custom Services might be:
- An XML-RPC server which listens for remote requests to deploy rooms.
- An email program which sends periodic emails of the server status such as Clients connected
and Rooms deployed.
Creating A Custom Service
Create the program you want to deploy as a Custom Service.
Ensure the program implements the Service interface.
Ensure the Class is in the CLASSPATH available to Unity. One method is to package the
Class file as a .jar file and adding the .jar file to the System CLASSPATH set
in the startup script.
Add your Service to the uconfig.xml startup file. See this for details.
The Service Interface
The interface contains two methods. The first load() is called when Unity is started up. The attributes
as set in uconfig.xml are passed as an argument. Any initialization should be performed in load(). The second unload is called when Unity is shutdown.
Any cleanup of resources should be performed in unload().
Accessing the Service from within Unity
You can access the Service from within Unity via the Services Object. For example,
Service service = Services.getCustomService("EmailService");
Once you've obtained a reference to the Service you can cast it to the actual known type
to access any custom methods within the Class.
See org.moock.unity.examples.rooms.CustomServicesAccess in the ./examples/rooms/ directory
for an example.