An Event-Based Approach to Runtime Adaptation in Communication-Centric Systems Jorge A. P´ erez University of Groningen (NL) Joint work with Cinzia Di Giusto Universit´ e de Nice Sophia-Antipolis (FR) 11th International Workshop on Web Services and Formal Methods (WS-FM) Eindhoven, September 12th, 2014 Event-Based Adaptation in Communication-Centric Systems J. A. P´ erez (Groningen)
A Model of Communication With Adaptation Communica)on ¡ External ¡request ¡ Internal ¡request ¡ Adapta)on ¡ Event-Based Adaptation in Communication-Centric Systems J. A. P´ erez (Groningen)
A Challenge • Distributed software systems are inherently communication-centric. As they run on open-ended platforms, they’re subject to requirements of runtime adaptation. • Session-based concurrency: a type-based approach to correctness of interacting software artifacts: ⋆ dialogues are structured into sessions ⋆ interaction patterns are abstracted as session types ⋆ types are checked against specifications [usually, π -calculus processes] • Session frameworks are useful to certify correct structured communications, but inadequate to handle runtime adaptation. Q1: Can we conciliate session correctness with expressive mechanisms for runtime adaptation? Event-Based Adaptation in Communication-Centric Systems J. A. P´ erez (Groningen)
Yes We Can! A First Answer: [Di Giusto and P´ erez - SAC’13] • Organize your process specification into distributed locations • Define adaptation routines targeted to location names • Keep track of the open sessions in each location • Allow runtime adaptation only on locations without open sessions + Rich forms of adaptation, disciplined by types + Syntax of session types is kept unchanged + Typing ensures consistency: running sessions are never jeopardized − External/unsolicited adaptation requests hard to express − Precludes “hot updates” in the middle of an established session Q2: Can we do better? Event-Based Adaptation in Communication-Centric Systems J. A. P´ erez (Groningen)
Yes We Can! (bis) This Work: A Second Answer • Organize your process specification into distributed locations • Define adaptation routines targeted to location names • Keep track of the current protocol state for each open session • Runtime adaptation using type-directed checks on protocol states Main features: + Rich forms of adaptation, disciplined by types + Syntax of session types is kept unchanged + Typing ensures consistency: running sessions are never jeopardized � Adaptation requests are made explicit via adaptation events. An event detector may then be used to trigger adaptation routines. � Enables consistent “hot updates” for sessions Event-Based Adaptation in Communication-Centric Systems J. A. P´ erez (Groningen)
This Work A typed framework for binary sessions with runtime adaptation. A session π -calculus with transparent locations, enhanced with: • adaptation signals/events and location queues (“how”) • event detectors on expressions (“when”) • monitors and type update processes (“what”) We retain a standard session type syntax, considering subtyping. A type system ensures safety and consistency. Well-typed programs: • do not exhibit communication errors (e.g., mismatched messages) • do not allow adaptation steps that disrupt established sessions Event-Based Adaptation in Communication-Centric Systems J. A. P´ erez (Groningen)
Session Types: Syntax A standard syntax for binary session types [cf. Honda et al.’98] : α, β ::= ?( T ) .β input a T , continue as β | !( T ) .β output a T , continue as β | & { n 1 : α 1 . . . n m : α m } branching (external choice) | ⊕{ n 1 : α 1 . . . n m : α m } selection (internal choice) | µt.α | t recursive session | ε terminated session where T stands for basic types (e.g., booleans) and session types α . Example. The session type for a client: α = ! item . ? amnt . α pay , where item and amnt are base types and α pay = ⊕{ addItem : ⊕{ ccard : α cc , payp : α pp } , cancel : ε } . Event-Based Adaptation in Communication-Centric Systems J. A. P´ erez (Groningen)
Session Types: Duality • To ensure protocol compatibility and absence of communication errors, the session types of two interacting partners should be dual. • Intuition: every action from one partner must be matched by a complementary action from the other. • Example. The following session types are dual: α = ! item . ? amnt . ⊕ { addItem : ⊕{ ccard : α cc , payp : α pp } , cancel : ε } β = ? item . ! amnt . & { addItem : & { ccard : β cc , payp : β pp } , cancel : ε } This is written α ⊥ C β . Event-Based Adaptation in Communication-Centric Systems J. A. P´ erez (Groningen)
Session Types: Subtyping • Subtyping ≤ C on session types formalizes a principle of safe substitution for typed processes [Gay and Hole’05] . • Example. Consider the session type: β pay = & { addItem : & { ccard : β cc , payp : β pp } , cancel : ε } An extended interface: β gift = & { addItem : & { giftc : β gc , ccard : β cc , payp : β pp } , cancel : ε } An implementation of β pay can be safely replaced with one of β gift (but not the other way around). This is written β pay ≤ C β gift . Event-Based Adaptation in Communication-Centric Systems J. A. P´ erez (Groningen)
Process Syntax (1): Base Language v | x, y, z | k = k | a = a e ::= expressions | P ::= u ( x : α ) .P u ( x : α ) .P session request / acceptance | | k ( e ) .P k ( x ) .P data output /input | | k ⊳ n ; P k ⊲ { n i : P i } i ∈ I selection / branching | µ X .P | X recursion / rec. variable | | P | P composition / inaction 0 | ( νκ ) P | ( νu ) P channel / name hiding | if e then P else Q conditional | close ( k ) .P session closure Example. A process specification of a client: P = u ( x : α ) .x ( book ) .x ( a ) . if a < 50 then x ⊳ addItem ; x ⊳ ccard ; R b else x ⊳ cancel ; R c Event-Based Adaptation in Communication-Centric Systems J. A. P´ erez (Groningen)
Process Syntax (2): Full Language 1. Located processes, using transparent, nested locations: loc[ P ] “process P resides at loc ” 2. Typeful update processes: � � case x 1 , . . . , x m of { ( x 1 : β i 1 ; · · · ; x m : β i loc m ) : Q i } i ∈ I 3. Session monitors, runtime entities (given a session channel k ): k ⌊ α ⌋ “type α denotes the current protocol state for k ” 4. Adaptation events and queues (given an adaptation request r ): loc( r ) loc ⌊ � r ⌋ 5. Arrival predicate in expressions—an event detector: arrive (loc , r ) Event-Based Adaptation in Communication-Centric Systems J. A. P´ erez (Groningen)
Example: A Distributed Buyer / Seller • Explicit distribution using locations sys , buyer , and seller : � � � � � � W = sys buyer u ( x : α ) .P | seller u ( y : β ) .Q • A typeful adaptation routine with two possibilities: � � � � ( x : α ; y : β ) : buyer[ R ] | seller[ Q ] U xy = sys case x, y of ( x : α pay ; y : β pay ) : buyer[ P ∗ ] | seller[ Q ∗ ] • A persistent adaptation routine, based on external request upd E : U ∗ xy = µ X . if arrive (sys , upd E ) then U xy else X Event-Based Adaptation in Communication-Centric Systems J. A. P´ erez (Groningen)
Process Semantics: Key Ideas • A reduction semantics based on synchronous communication. • Contexts C, D, . . . used to handle nested, transparent locations. • Synchronization on names leads to session establishment: ⋆ A fresh session polarized channel κ p is generated for each endpoint. ⋆ A monitor on κ p is put in parallel with the type for each endpoint. • Session synchronizations are enabled by the types in the monitors. • Adaptation requires matching (up to subtyping ≤ C ) between declared types and current protocol state. Event-Based Adaptation in Communication-Centric Systems J. A. P´ erez (Groningen)
Reduction Semantics: Some Rules (1) • Session establishment (with α ⊥ C β ): � � � � C u ( x : α ) .P | D u ( y : β ) .Q − → � � � � �� P [ κ p / x ] | κ p ⌊ α ⌋ Q [ κ p / y ] | κ p ⌊ β ⌋ ( νκ ) C | D where p and p denote opposing polarities. • Session communication: � � � � κ p ( v ) .P | κ p ⌊ !( T ) .α ⌋ κ p ( x ) .Q | κ p ⌊ ?( T ) .β ⌋ C | D − → � � � � �� P | κ p ⌊ α ⌋ Q [ v / x ] | κ p ⌊ β ⌋ ( νκ ) C | D Event-Based Adaptation in Communication-Centric Systems J. A. P´ erez (Groningen)
Reduction Semantics: Some Rules (2) • A typeful update on location loc : fc ( P ) = { κ p ∀ j ∈ [1 , .., m ] . ( κ p 1 , . . . , κ p m } j ⌊ α j ⌋ ∈ P ) ( V = P ) � ∃ l. � match I ( l, { α 1 , . . . , α m } , { β i 1 , . . . , β i m } i ∈ I ) � ∧ V = Q l [ κ p 1 , . . . , κ p m / x 1 , . . . , x m ] � �� � � � x of { ( x 1 : β i 1 ; · · · ; x m : β i m ) : Q i } i ∈ I C loc[ P ] | D loc case � − → � � � � C loc[ V ] | D 0 • Intuitively, match enforces monotonic adaptation, using ≤ C . • Impossibility of matching leaves the location as it is (no update) Event-Based Adaptation in Communication-Centric Systems J. A. P´ erez (Groningen)
Recommend
More recommend