How to code a service?
UbiquiTalk services should be implemented only on the host. When needed, clients will download required code in order to execute the service.
Three steps are required for coding a service:
- Implement client classes
- Implement service support classes
- Implement service facade class
In the follwing we present step by step the implementation of a Hello Service. The goal of this service is to allow the client to display 'Hello World!' on the Transcript of the image hosting the service.
Implement client classes
To code the service, we first focus on client class(es). They should be put in a dedidcated monticello package or in a dedicated class category. Our example has a single client class that we put in the class category 'UTHelloWorld-Client'.
Object subclass: #UTHelloClient
This class contains only a single class method which is the entry point for the service.
Implement service support classes
We also need to implement classes necessary to the service. For Hello World service, we use the Transcript. The supporting class (TranscriptStream) is already available. So, we have nothing to do for this part.
Implement service facade class
last but not the least, the service’s class. It must inherit from UTService and implement a few methods.
UTService subclass: #UTHelloService
Transcript cr; show: ‘Hello World !’
Service description methods
^‘Hello World service’
^'Prints ''Hello World!'' on a remote Transcript'
Client management methods
"Return the name of the category or Monticello package which contains client code"
"Boolean. Possess client code"
"Indicate the name of remote client object"
^UTRemoteGlobalObject named: UTHelloClient
"Return the name of class method to execute at client side"
"Return arguments used by this method contained in an Array"
UTService class implements two methods that subclasses may optionally implement : startUp and shutdown. Those methods are executed each time UbiquiTalk is started and stopped. Some services need to perform specific initialize and cleanup actions. For example a chat conference service must empty its chatters set on shutdown to avoid failures due to references on unavailable remote chatters.
UTService subclass: #UTConference
..."rest of class definiont"
"Clear the chatter list when the host is shut down. Done in order to avoid failures when disconnection occurs"
chatters := Set new.