Microservices introduced the possibility to split software monoliths into manageable parts to reduce dependencies, improve availability and foster reuse.
One possibility to develop and integrate web services is provided on behalf of the orchestration language “Jolie” which gets presented in this talk.
Jolie (www.jolie-lang.org) originated as a research work at the University of Bologna in 2007 and is nowadays used both in academia and industry. The aim of this talk lies in the presentation of the fundamental concepts behind it.
SFScon19 - Matthias Dieter Wallnöfer - Jolie The first language for Microservices - Copia
1. Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo |Bertinoro International Spring School 2016
A gentle introduction to
Saverio Giallorenzo | sgiallor@cs.unibo.it
1
4. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi
Introduction to the Jolie Language
What is Jolie?
3
A Service-Oriented
Programming Language
Service
Instances
Objects
Operations Methods
Service-Oriented Object-Oriented
5. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Jolie is perfect for fast prototyping. In
little time a small team of developers can
build up a full-fledged distributed system.
Why SOC and Jolie?
4
6. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Jolie is perfect for fast prototyping. In
little time a small team of developers can
build up a full-fledged distributed system.
Why SOC and Jolie?
4
But I already know Java!
Why shall I use Jolie?
7. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Why SOC and Jolie?
5
8. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Why SOC and Jolie?
5
9. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Why SOC and Jolie?
5
SocketChannel socketChannel = SocketChannel.open();
socketChannel.connect(
new InetSocketAddress("http://someurl.com", 80));
Buffer buffer = . . .; // byte buffer
while( buffer.hasRemaining() ) {
channel.write( buffer );
}
Happy?
10. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Why SOC and Jolie?
5
SocketChannel socketChannel = SocketChannel.open();
socketChannel.connect(
new InetSocketAddress("http://someurl.com", 80));
Buffer buffer = . . .; // byte buffer
while( buffer.hasRemaining() ) {
channel.write( buffer );
}
Happy?
Ok, but you did not even close
the channel or handled
exceptions
11. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Why SOC and Jolie?
6
12. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Why SOC and Jolie?
6
SocketChannel socketChannel = SocketChannel.open();
try {
socketChannel.connect(new InetSocketAddress("http://someurl.com",
80));
Buffer buffer = . . .; // byte buffer
while( buffer.hasRemaining() ) {
channel.write( buffer );
} }
catch( UnresolvedAddressException e ) { . . . }
catch( SecurityException e ) { . . . }
/* . . . many catches later . . . */
catch( IOException e ) { . . . }
finally { channel.close(); }
Happier now?
13. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Why SOC and Jolie?
6
SocketChannel socketChannel = SocketChannel.open();
try {
socketChannel.connect(new InetSocketAddress("http://someurl.com",
80));
Buffer buffer = . . .; // byte buffer
while( buffer.hasRemaining() ) {
channel.write( buffer );
} }
catch( UnresolvedAddressException e ) { . . . }
catch( SecurityException e ) { . . . }
/* . . . many catches later . . . */
catch( IOException e ) { . . . }
finally { channel.close(); }
Happier now?
Yes, but what about the
server?
14. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Why SOC and Jolie?
7
15. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Why SOC and Jolie?
7
16. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Why SOC and Jolie?
7
Selector selector = Selector.open();
channel.configureBlocking(false);
SelectionKey key = channel.register(selector, SelectionKey.OP_READ);
while(true) {
int readyChannels = selector.select();
if(readyChannels == 0) continue;
Set<SelectionKey> selectedKeys = selector.selectedKeys();
Iterator<SelectionKey> keyIterator = selectedKeys.iterator();
while(keyIterator.hasNext()) {
SelectionKey key = keyIterator.next();
if(key.isAcceptable()) {
// a connection was accepted by a ServerSocketChannel.
} else if (key.isConnectable()) {
// a connection was established with a remote server.
} else if (key.isReadable()) {
// a channel is ready for reading
} else if (key.isWritable()) {
// a channel is ready for writing
}
keyIterator.remove();
}
}
Here you are
17. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Why SOC and Jolie?
8
Well, ok, but again, you are not handling exceptions.
And what about if different operations use the same
channel?
And if we wanted to use RMIs instead of Sockets?
In what format are you
transmitting data? And if
we need to change the
format after we wrote the
application? Do you check the
type of data you receive/send?
18. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Why SOC and Jolie?
8
Well, ok, but again, you are not handling exceptions.
And what about if different operations use the same
channel?
And if we wanted to use RMIs instead of Sockets?
In what format are you
transmitting data? And if
we need to change the
format after we wrote the
application? Do you check the
type of data you receive/send?
19. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Why SOC and Jolie?
9
Programming distributed systems is usually
harder than programming non distributed ones.
Concerns of concurrent programming.
Plus (not exhaustive):
• handling communications;
• handling heterogeneity;
• handling faults;
• handling the evolution of systems.
20. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
10
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
21. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
10
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
22. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
10
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
23. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
10
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
Include a
service
24. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
10
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
Include a
service
25. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
10
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
Include a
service
26. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
10
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
Include a
service
program entry point
27. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
10
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
Include a
service
program entry point
28. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
10
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
Include a
service
program entry point
29. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
10
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
Include a
service
program entry point
operation
30. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
10
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
Include a
service
program entry point
operation
31. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
10
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
Include a
service
program entry point
operation
32. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
10
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
Include a
service
program entry point
operation service
33. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
11
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
34. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
11
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
35. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
11
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
hello_world.ol
36. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us get our hands dirty.
“Hello World!” is enough to let you see some of the main
features of Jolie and Service-Oriented Programming.
Hello World! in Jolie
11
include "console.iol"
main
{
println@Console( "Hello, world!" )()
}
hello_world.ol
$ jolie hello_world.ol
37. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Let us see some Jolie in Action
12
Everything starts
with a calculator…
38. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Bertinoro International Spring School 2016
A gentle introduction to Jolie
include "MyInterface.iol"
outputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber @ B ( 5 )
}
include "MyInterface.iol"
inputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber( x )
}
interface MyInterface {
OneWay: sendNumber( int )
}
Behaviours and Deployments
13
ServerClient
39. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Bertinoro International Spring School 2016
A gentle introduction to Jolie
include "MyInterface.iol"
outputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber @ B ( 5 )
}
include "MyInterface.iol"
inputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber( x )
}
interface MyInterface {
OneWay: sendNumber( int )
}
Behaviours and Deployments
13
ServerClient
40. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Bertinoro International Spring School 2016
A gentle introduction to Jolie
include "MyInterface.iol"
outputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber @ B ( 5 )
}
include "MyInterface.iol"
inputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber( x )
}
interface MyInterface {
OneWay: sendNumber( int )
}
Behaviours and Deployments
13
ServerClient
41. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Bertinoro International Spring School 2016
A gentle introduction to Jolie
include "MyInterface.iol"
outputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber @ B ( 5 )
}
include "MyInterface.iol"
inputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber( x )
}
interface MyInterface {
OneWay: sendNumber( int )
}
Behaviours and Deployments
13
ServerClient
42. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Bertinoro International Spring School 2016
A gentle introduction to Jolie
include "MyInterface.iol"
outputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber @ B ( 5 )
}
include "MyInterface.iol"
inputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber( x )
}
interface MyInterface {
OneWay: sendNumber( int )
}
Behaviours and Deployments
13
ServerClient
43. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Bertinoro International Spring School 2016
A gentle introduction to Jolie
include "MyInterface.iol"
outputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber @ B ( 5 )
}
include "MyInterface.iol"
inputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber( x )
}
interface MyInterface {
OneWay: sendNumber( int )
}
Behaviours and Deployments
13
ServerClient
44. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Bertinoro International Spring School 2016
A gentle introduction to Jolie
include "MyInterface.iol"
outputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber @ B ( 5 )
}
include "MyInterface.iol"
inputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber( x )
}
interface MyInterface {
OneWay: sendNumber( int )
}
Behaviours and Deployments
13
ServerClient
45. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Bertinoro International Spring School 2016
A gentle introduction to Jolie
include "MyInterface.iol"
outputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber @ B ( 5 )
}
include "MyInterface.iol"
inputPort B {
Location:
"socket://localhost:8000"
Protocol: sodep
Interfaces: MyInterface
}
main
{
sendNumber( x )
}
interface MyInterface {
OneWay: sendNumber( int )
}
Behaviours and Deployments
13
ServerClient
46. Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo |Bertinoro International Spring School 2016
Deployments
Enabling Communication
14
Gentle introduction to Jolie
47. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Bertinoro International Spring School 2016
A gentle introduction to Jolie
Behaviours and Deployments
15
A B
sendNumber
output
port
sendNumber
input
port
medium
• Services communicate through ports.
• Ports give access to an interface.
• An interface is a set of operations.
• An output port is used to invoke interfaces exposed by other services.
• An input port is used to expose an interface.
48. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Bertinoro International Spring School 2016
A gentle introduction to Jolie
A closer look on ports - Locations
16
Medium Parameters
TCP/IP socket:// www.google.it:80
Bluetooth btl2cap://
localhost:
3B9FA89520078C303355AAA694238F07;name=Vision;encrypt=
false;authenticate=false
Local localsocket: /tmp/mysocket.socket
Java RMI rmi:// myRmiUrl.com/MyService
In-Memory local
A location describes:
• the communication medium;
• the parameters to set the communication up.
In Jolie a location is a Uniform Resource Identifier (URI)
with form: medium[:parameters]
49. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Bertinoro International Spring School 2016
A gentle introduction to Jolie
A closer look on ports - Protocols
17
A protocol defines the format the data is
sent (encoded) and received (encoded)
In Jolie protocols are names and possibly
additional parameters:
http { .debug = true }
json/rpc sodep https
soap
50. Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo |Bertinoro International Spring School 2016
Behaviours
Composing Interactions
18
Gentle introduction to Jolie
51. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi
Basic Behaviour - Composition and Workflow
Interactions via Operations
19
Input
Operations
Output
Operations
oneWay( req )
reqRes( req )( res ){
// code block
}
oneWay@Port( req )
reqRes@Port( req )( res )
52. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Bertinoro International Spring School 2016
A gentle introduction to Jolie
Behaviour Composition
20
The sequence operator ; denotes that
the left operand of the statement is
executed before the one on the right.
println@Console( "A" )();
println@Console( "B" )()
Prints
A
B
53. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Bertinoro International Spring School 2016
A gentle introduction to Jolie
Behaviour Composition
21
The parallel operator | states
that both left and right
operands execute concurrently
println@Console( "A" )()|
println@Console( "B" )()
can print
A
B
but also
B
A
54. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Behaviour Composition
22
The input choice implements input-
guarded non-deterministic choice.
[ oneWayOperation() ] { branch_code }
[ oneWayOperation2() ] {branch_code2}
[ requestResponseOperation()(){
rr_code }
] { branch_code }
55. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Behaviour Composition
23
The input choice implements input-
guarded non-deterministic choice.
main {
[ buy( stock )( response ) {
buy@Exchange( stock )( response )
} ] { println@Console( "Buy order forwarded" )() }
[ sell( stock )( response ) {
sell@Exchange( stock )( response )
}] { println@Console( "Sell order forwarded" )() }
}
56. Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo |Bertinoro International Spring School 2016
Before you take off
26
Gentle introduction to Jolie
57. Leonardo
● A web server in pure Jolie.
● Can fit in a slide.
(ok, I reduced the font size a little)
● ~50 LOCs
58. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
The Jolie Interpreter
28
http://www.jolie-lang.org/downloads.html
Last release
• Requires JRE 1.6+
• Download jolie-installer.jar
• open a console and run
java -jar jolie-installer.jar
59. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Sources
29
Jolie is an open source project with
continuous updates and a well documented
codebase
“This is the programming language
you are looking for”
https://github.com/jolie/jolie
60. |Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo
A gentle introduction to Jolie
Bertinoro International Spring School 2016
Documentation
30
Comprehensive and ever-growing
documentation and Standard Library.
http://docs.jolie-lang.org
61. Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo |Bertinoro International Spring School 2016
Thanks for your time!
32
Gentle introduction to Jolie