Print

Tutorial Services and Operations

Services and operations


Table of contents



JOLIE 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.

Operations

An 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?.


TIP
Service operations are informally similar to what methods are for objects in the object-oriented paradigm.



Service invocation

Output ports

Invoking 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:
  • Name: every output port has an unique name, in this case MathService;
  • Location: it's a URI (external link), telling where the service is located;
  • Protocol?: indicates what protocol to use to communicate with the service.

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 communications

To 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 services

Input ports

We 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 communications

Now that our program can receive invocations for the twice 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):
  • receiving a value in the number variable;
  • storing in the result variable the value of number multiplied by 2;
  • sending back result as a response.


Menu [toggle]

Powered by TikiWiki CMS/Groupware v2.2 -Arcturus-