Basic Behaviour Composition and Workflow Saverio Giallorenzo | - - PowerPoint PPT Presentation

basic behaviour composition and workflow
SMART_READER_LITE
LIVE PREVIEW

Basic Behaviour Composition and Workflow Saverio Giallorenzo | - - PowerPoint PPT Presentation

Basic Behaviour - Composition and Workflow Basic Behaviour Composition and Workflow Saverio Giallorenzo | sgiallor@cs.unibo.it 1 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi | Basic Behaviour -


slide-1
SLIDE 1

Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo | Basic Behaviour - Composition and Workflow

Basic Behaviour

Saverio Giallorenzo | sgiallor@cs.unibo.it

1 Laboratorio di Sistemi Operativi

Composition and Workflow

slide-2
SLIDE 2

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

include "MyInterface.iol"

  • utputPort 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 ) }

Previously on Jolie

2

slide-3
SLIDE 3

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Using ports

3

Once defined, a port can be used for input (output) communications. Ports can provide

  • ne-ways and request-responses.

Input Operations Output Operations

  • w-op( req )

rr-op( req )( res ){ // code block }

  • w-op@Port( req )

rr-op@Port( req )( res )

slide-4
SLIDE 4

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Sequential Composition

4

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

slide-5
SLIDE 5

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Sequential Composition

5

Ceci n’est pas une fin d’instruction

;

slide-6
SLIDE 6

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Sequential Composition

6

println@Console( "A" )(); println@Console( "B" )();

If this is the last statement that is definitely wrong!

slide-7
SLIDE 7

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Parallel Composition

7

The parallel operator | states that both left and right

  • perands execute concurrently

println@Console( "A" )()| println@Console( "B" )()

can print A

B

but also B

A

slide-8
SLIDE 8

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Parallel Composition

8

The parallel operator has always priority on the sequence

print@Console( "A" )()| print@Console( "B" )(); print@Console( "C" )()

can print ABC but also BAC

slide-9
SLIDE 9

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Parallel Composition

9

print@Console( "A" )()| print@Console( "B" )(); print@Console( "C" )()

This means: print “A” and “B” in parallel and then print “C” The first two statements create a race to access the stdout. After their execution the last statement can execute.

slide-10
SLIDE 10

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Parallel Composition

10

Good practice: use scopes {} to explicitly group parallel statements when mixed with sequences

{ print@Console( "A" )()| print@Console( "B" )() }; print@Console( "C" )() print@Console( "A" )()| print@Console( "B" )(); print@Console( "C" )()

is equal to

But this is easier to understand

slide-11
SLIDE 11

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Parallel Composition

11

Scopes are very useful to clearly specify complex mixes of parallels and sequences of statements

{ print@Console( "A" )() | print@Console( "B" )() };{ print@Console( "C" )() | print@Console( "D" )() }

Print “AB” or “BA” and then “CD” or “DC”

slide-12
SLIDE 12

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Input-Choice

12

The input choice implements input- guarded non-deterministic choice.

[ input_operation_1 ]{ branch_code_1 } [ ... ]{ ... } [ input_operation_n ]{ branch_code_n }

slide-13
SLIDE 13

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Input-Choice

13

The input choice implements input- guarded non-deterministic choice.

[ oneWayOperation() ] { branch_code } [ requestResponseOperation()(){ rr_code } ] { branch_code }

slide-14
SLIDE 14

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Input-Choice

14

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" )() } }

slide-15
SLIDE 15

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Service execution modalities

15

A service participates in a session by executing an instance of its behaviour.

Jolie allows to reuse a behavioural definition multiple times with the execution primitive.

execution{ single | concurrent | sequential }

Default if execution is not defined

slide-16
SLIDE 16

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Conditionals

16

Conditions are used in control flow to check a boolean expression

==

equals to

!=

not equals to

<

lower than

<=

lower than or equal to

>

greater than

>=

greater than or equal to

!

negation

slide-17
SLIDE 17

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Conditionals

17

The statement if ... else is used to write deterministic choices

if( cond1 ){ … } else if ( cond2 ) { … } else if ( cond3 ){ … }

if ( cond ) { … } [else { … }]

ifs can be nested

slide-18
SLIDE 18

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Loops

18

while( condition ) { ... } for ( ini_code, cond, aftermath-code ) { ... }

slide-19
SLIDE 19

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

“main” and “init” procedures

19

The main procedure may be preceded or succeeded by the definition of auxiliary procedures that can be invoked from any other code block and can access any data associated with the specific instance they belong to. Unlike in other major languages, procedures in Jolie do not posses a local variable scope.

slide-20
SLIDE 20

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

“main” and “init” procedures

20

The init procedure, if present, is executed before the main. The body of the init procedure is executed only once, when the service is started.

init { getCurrentDateTime@Time()( date ) } main { start(); println@Console( "start date: " + date )(); getCurrentDateTime@Time()( date ); println@Console( "current date: " + date )() }

slide-21
SLIDE 21

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Procedures: definition and recall

21

define procedureName { ... code ... }

include "console.iol" define fibonacci { if( f1 < end ){ println@Console( f1 )(); _f2 = f1+f2; f1 = f2; f2 = _f2; fibonacci } } main { f1 = 0; f2 = 1; end = 200; fibonacci }

slide-22
SLIDE 22

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

Constants

22

It is possible to define constants by means

  • f the construct constants. The declarations
  • f the constants are divided by commas

constants { server_location = "socket://localhost:8080", ALARM_TIMEOUT = 2000, standard_gravity = 9.8 }

Constants might also be assigned on the command line.

jolie -C ALARM_TIMEOUT=2000 program.ol

which overrides ALARM_TIMEOUT

slide-23
SLIDE 23

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

global variables

23

Jolie provides global variables to support sharing of data among different instances. Global variables belong to the global prefix

[ count() ]{ global.i++ } [ print( run ) ]{ println@Console(global.i)(); println@Console( "missing: " + run - global.i )(); undef( global.i ) }

slide-24
SLIDE 24

| Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi Basic Behaviour - Composition and Workflow

synchronized scopes

24

Concurrent access to global variables can be restricted through synchronized blocks

synchronized( id ){ … }

[ count() ]{ synchronized( syncToken ){ global.i++ } }

[ print( run ) ]{ println@Console(global.i)(); println@Console( "missing: " + run - global.i )(); undef( global.i ) }