basic behaviour composition and workflow
play

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 -


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

  2. Basic Behaviour - Composition and Workflow Previously on Jolie interface MyInterface { OneWay: sendNumber( int ) } include "MyInterface.iol" include "MyInterface.iol" outputPort B { inputPort B { Location: Location: "socket://localhost:8000" "socket://localhost:8000" Protocol: sodep Protocol: sodep Interfaces: MyInterface Interfaces: MyInterface } } main main { { sendNumber @ B ( 5 ) sendNumber( x ) } } 2 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  3. Basic Behaviour - Composition and Workflow Using ports Once defined, a port can be used for input (output) communications. Ports can provide one-way s and request-response s . Input Operations Output Operations ow-op( req ) ow-op@Port( req ) rr-op( req )( res ){ // code block rr-op@Port( req )( res ) } 3 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  4. Basic Behaviour - Composition and Workflow Sequential Composition 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" )() A Prints B 4 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  5. Basic Behaviour - Composition and Workflow ; Sequential Composition Ceci n’est pas une fin d’instruction 5 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  6. Basic Behaviour - Composition and Workflow Sequential Composition println@Console( "A" )(); println@Console( "B" )(); If this is the last statement that is definitely wrong! 6 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  7. Basic Behaviour - Composition and Workflow Parallel Composition The parallel operator | states that both left and right operands execute concurrently println@Console( "A" )()| println@Console( "B" )() can print A but also B B A 7 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  8. Basic Behaviour - Composition and Workflow Parallel Composition The parallel operator has always priority on the sequence print@Console( "A" )()| print@Console( "B" )(); print@Console( "C" )() can print ABC but also BAC 8 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  9. Basic Behaviour - Composition and Workflow Parallel Composition 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. 9 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  10. Basic Behaviour - Composition and Workflow Parallel Composition Good practice: use scopes {} to explicitly group parallel statements when mixed with sequences is equal to print@Console( "A" )()| print@Console( "B" )(); print@Console( "C" )() { print@Console( "A" )()| But this is easier print@Console( "B" )() }; to understand print@Console( "C" )() 10 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  11. Basic Behaviour - Composition and Workflow Parallel Composition 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” 11 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  12. Basic Behaviour - Composition and Workflow Input-Choice The input choice implements input- guarded non-deterministic choice . [ input_operation_1 ]{ branch_code_1 } [ ... ]{ ... } [ input_operation_n ]{ branch_code_n } 12 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  13. Basic Behaviour - Composition and Workflow Input-Choice The input choice implements input- guarded non-deterministic choice . [ oneWayOperation() ] { branch_code } [ requestResponseOperation()(){ rr_code } ] { branch_code } 13 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  14. Basic Behaviour - Composition and Workflow Input-Choice 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" )() } } 14 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  15. Basic Behaviour - Composition and Workflow Service execution modalities 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. Default if execution{ single execution | concurrent is not defined | sequential } 15 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  16. Basic Behaviour - Composition and Workflow Conditionals 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 16 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  17. Basic Behaviour - Composition and Workflow Conditionals The statement if ... else is used to write deterministic choices if ( cond ) { … if( cond1 ){ … } [else { } else if ( cond2 ) { … … }] } else if ( cond3 ){ … if s can be nested } 17 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  18. Basic Behaviour - Composition and Workflow Loops while( condition ) { ... } for ( ini_code, cond, aftermath-code ) { ... } 18 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  19. Basic Behaviour - Composition and Workflow “main” and “init” procedures 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. 19 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  20. Basic Behaviour - Composition and Workflow “main” and “init” procedures 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 )() } 20 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  21. Basic Behaviour - Composition and Workflow Procedures: definition and recall define procedureName include "console.iol" { define fibonacci ... { code if( f1 < end ){ ... println@Console( f1 )(); } _f2 = f1+f2; f1 = f2; f2 = _f2; fibonacci } } main { f1 = 0; f2 = 1; end = 200; fibonacci } 21 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  22. Basic Behaviour - Composition and Workflow Constants It is possible to define constants by means of the construct constants. The declarations of 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 22 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

  23. Basic Behaviour - Composition and Workflow global variables 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 ) } 23 Saverio Giallorenzo | sgiallor@cs.unibo.it | DISI@Unibo Laboratorio di Sistemi Operativi |

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend