|
|
||||||
Tutorial Services and OperationsServices and operationsTable of contentsJOLIE is all about communicating with services. You can invoke a service or be the service that gets invoked. Programs get more complex by composing message sendings and/or receivings; as such, the first fundamental notion for programming with JOLIE is to understand how to define services and how to communicate. OperationsAn operation is a functionality exposed by a service, which can be invoked by other applications. Whenever you want to invoke another service, you must do so by invoking one of its operations, and vice versa (whenever another application wants to invoke yours, it must do so by invoking an operation of your program).There are two kinds of operations: - One-Way: it simply receives a message; - Request-Response: it receives a message and then sends back a response. Invocations for One-Way? operations are received by using the one-way operation statement?, while one can invoke a OneWay? operation with the notification statement?. Similarly, Request-Response? operation invocations are received by using the request-response statement?, while one can such operations with the solicit-response statement?.
Service invocationOutput portsInvoking another service requires you to define an output port in the program preamble. Defining an output port goes like this:outputPort MathService {
Location: "socket://localhost:8000"
Protocol: sodep
}From which we can see three main components already:
We refer to Location and Protocol? for a better understanding of what you can do with these two elements. We have defined MathService, but we did not specify what operations? are available for communicating with it. Let us add an operation to MathService: outputPort MathService {
Location: "socket://localhost:8000"
Protocol: sodep
RequestResponse:
twice
}We have added the twice Request-Response? operation, enabling our JOLIE program to invoke it.Outgoing communicationsTo invoke MathService?, we use the solicit-response statement?:main
{
twice@MathService(5)(result)
}Our little program calls the twice operation of the MathService service, passing 5 as invocation value. It will then wait for the response from MathService and store it in theresult variable.Creating servicesInput portsWe will now create a JOLIE application realizing the behaviour of MathService. Creating a service requires writing an input port first, which are very similar to output ports. An input port for MathService would be the following:inputPort MathService {
Location: "socket://localhost:8000"
Protocol: sodep
RequestResponse:
twice
}Ingoing communicationsNow that our program can receive invocations for thetwice operation, we just need to code its behaviour:main
{
twice(number)(result) {
result = number * 2
}
}where we use the request-response statement? for (in order):
|
SidebarLogin |
|||||