830 likes | 958 Vues
This paper provides an overview of session programming in SJ, covering session types in object and process calculi, with examples and implementations discussed. It delves into theoretical background, related work, and future directions for session-based distributed programming.
E N D
Session-based Distributed Programming in Java Raymond Hu1, Nobuko Yoshida1 and Kohei Honda2 1. Imperial College London; 2. Queen Mary, Uni. of London February 2008
Overview (1) • Background and Related Work. • Worked Example: Session Programming in SJ. • The SJ Session Runtime. • Conclusion and Future Work. Overview
Session Types • Type systems for process calculi: • Takeuchi et al. An Interaction-based Language and its Typing System. (1994) • Honda et al. Language Primitives and Type Discipline for Structured Comm… (1998) • Gay and Hole. Subtyping for Session Types in the Pi Calculus. (1999) • Hole and Gay. Bounded Polymorphism in Session Types. (2003) Theoretical Background
Session Types • Type systems for process calculi: • Takeuchi et al. An Interaction-based Language and its Typing System. (1994) • Honda et al. Language Primitives and Type Discipline for Structured Comm… (1998) • Gay and Hole. Subtyping for Session Types in the Pi Calculus. (1999) • Hole and Gay. Bounded Polymorphism in Session Types. (2003) • Session types for object calculi: • Dezani-Ciancaglini et al. A distributed Object-oriented Language with Session... (2005) • Dezani-Ciancaglini et al. Session Types for Object-oriented Languages. (2006) • Dezani-Ciancaglini et al. Bounded Session Types for Object-oriented Languages. (2007) • Coppo et al. Asynchronous Session Types and Progress for Object-oriented... (2007) Theoretical Background
Session Types • Type systems for process calculi: • Takeuchi et al. An Interaction-based Language and its Typing System. (1994) • Honda et al. Language Primitives and Type Discipline for Structured Comm… (1998) • Gay and Hole. Subtyping for Session Types in the Pi Calculus. (1999) • Hole and Gay. Bounded Polymorphism in Session Types. (2003) • Session types for object calculi: • Dezani-Ciancaglini et al. A distributed Object-oriented Language with Session... (2005) • Dezani-Ciancaglini et al. Session Types for Object-oriented Languages. (2006) • Dezani-Ciancaglini et al. Bounded Session Types for Object-oriented Languages. (2007) • Coppo et al. Asynchronous Session Types and Progress for Object-oriented... (2007) • Implementation of a practical and distributed language. Theoretical Background
Implementation of Session Types • Singularity OS [FAHHHLL06]: • Restrictions on session features, not distributed. Related Work
Implementation of Session Types • Singularity OS [FAHHHLL06]: • Restrictions on session features, not distributed. • Multithreaded functional language design [VGR06]: • Not distributed, no actual implementation. Related Work
Implementation of Session Types • Singularity OS [FAHHHLL06]: • Restrictions on session features, not distributed. • Multithreaded functional language design [VGR06]: • Not distributed, no actual implementation. • Encodings of sess. types (e.g. Haskell [NT04], C++): • Demonstrate S.T. ideas, but not full implementations. Related Work
Implementation of Session Types • Singularity OS [FAHHHLL06]: • Restrictions on session features, not distributed. • Multithreaded functional language design [VGR06]: • Not distributed, no actual implementation. • Encodings of sess. types (e.g. Haskell [NT04], C++): • Demonstrate S.T. ideas, but not full implementations. • Why use “untyped” sockets if we can use sessions? Related Work
Overview (2) • Background and Related Work. • Worked Example: Session Programming in SJ. • The SJ Session Runtime. • Conclusion and Future Work. Overview
An Online Ticket Ordering System Worked Example: Session Programming in SJ
begin Protocol Specification (1) Worked Example: Session Programming in SJ
begin. !(String) Protocol Specification (1) Worked Example: Session Programming in SJ
begin. !(String). ?(Double) Protocol Specification (1) Worked Example: Session Programming in SJ
begin. !(String). ?(Double) Protocol Specification (1) ![ ]*. … Worked Example: Session Programming in SJ
begin. ?[ ?(String). !(Double) ]*. … begin. !(String). ?(Double) Protocol Specification (1) ![ ]*. … Worked Example: Session Programming in SJ
Protocol Specification (2) … ?{ }. … Worked Example: Session Programming in SJ
Protocol Specification (2) … ACCEPT: … , REJECT: … ?{ }. … Worked Example: Session Programming in SJ
Protocol Specification (3) protocol p_as { } Worked Example: Session Programming in SJ
Protocol Specification (3) protocol p_as { } begin. !( ) Worked Example: Session Programming in SJ
Protocol Specification (3) ?(Address).!(Date) protocol p_as { } begin. !( ) Worked Example: Session Programming in SJ
protocolp_ca{ begin. ![ !(String). ?(Double) ]*. … // Customer SJSocket s_ca = SJSocketImpl.create(p_ca); Protocol Implementation (1) Worked Example: Session Programming in SJ
protocolp_ca{ begin. ![ !(String). ?(Double) ]*. … // Customer SJSocket s_ca = SJSocketImpl.create(p_ca); s_ca.request(Agency, port); Protocol Implementation (1) Worked Example: Session Programming in SJ
protocolp_ca{ begin. ![ !(String). ?(Double) ]*. … // Customer SJSocket s_ca = SJSocketImpl.create(p_ca); s_ca.request(Agency, port); Protocol Implementation (1) s_ca.outwhile(!decided){ } Worked Example: Session Programming in SJ
protocolp_ca{ begin. ![ !(String). ?(Double) ]*. … // Customer SJSocket s_ca = SJSocketImpl.create(p_ca); s_ca.request(Agency, port); s_ca.send(travDetails); Protocol Implementation (1) s_ca.outwhile(!decided){ } Worked Example: Session Programming in SJ
protocolp_ca{ begin. ![ !(String). ?(Double) ]*. … // Customer SJSocket s_ca = SJSocketImpl.create(p_ca); s_ca.request(Agency, port); s_ca.send(travDetails); cost = (Double)s_ca.receive(); decided = …; Protocol Implementation (1) s_ca.outwhile(!decided){ } Worked Example: Session Programming in SJ
protocolp_ca{ begin. ![ !(String). ?(Double) ]*. … // Customer SJSocket s_ca = SJSocketImpl.create(p_ca); s_ca.request(Agency, port); s_ca.send(travDetails); decided = …; Protocol Implementation (1) s_ca.outwhile(!decided){ } cost = s_ca.receive(); Worked Example: Session Programming in SJ
… !{ ACCEPT: … , // 1 REJECT: … // 2 } … // Customer s_ca.select(ACCEPT){ … // 1 } Protocol Implementation (2) Worked Example: Session Programming in SJ
… !{ ACCEPT: … , // 1 REJECT: … // 2 } … // Customer s_ca.select(ACCEPT){ … // 1 } Protocol Implementation (2) if(cost < 100.00){ } else{ } Worked Example: Session Programming in SJ
… !{ ACCEPT: … , // 1 REJECT: … // 2 } … // Customer s_ca.select(ACCEPT){ … // 1 } s_ca.select(REJECT){ …// 2 } Protocol Implementation (2) if(cost < 100.00){ } else{ } Worked Example: Session Programming in SJ
… ?{ ACCEPT: … , // 1’ REJECT: … // 2’ } … // Agency Protocol Implementation (3) … s_ac.branch(){ } Worked Example: Session Programming in SJ
… ?{ ACCEPT: … , // 1’ REJECT: … // 2’ } … // Agency case ACCEPT: { … // 1’ } case REJECT: { … // 2’ } Protocol Implementation (3) … s_ac.branch(){ } Worked Example: Session Programming in SJ
Putting Customer Together protocol p_ca{…} Worked Example: Session Programming in SJ
Putting Customer Together protocol p_ca{…} SJSocket s_ca = SJSocketImpl.create(p_ca); Worked Example: Session Programming in SJ
Putting Customer Together protocol p_ca{…} SJSocket s_ca = SJSocketImpl.create(p_ca); s_ca.request(Agency, port); s_ca.outwhile(…){ … } … Worked Example: Session Programming in SJ
Putting Customer Together protocol p_ca{…} SJSocket s_ca = SJSocketImpl.create(p_ca); s_ca.request(Agency, port); s_ca.outwhile(…){ … } … try(s_ca){ } Worked Example: Session Programming in SJ
Putting Customer Together protocol p_ca{…} SJSocket s_ca = SJSocketImpl.create(p_ca); s_ca.request(Agency, port); s_ca.outwhile(…){ … } … catch(SJIOException ioe){ … } try(s_ca){ } Worked Example: Session Programming in SJ
Putting Customer Together protocol p_ca{…} SJSocket s_ca = SJSocketImpl.create(p_ca); s_ca.request(Agency, port); s_ca.outwhile(…){ … } … catch(SJIncompatibleSessionException ise){ … } catch(SJIOException ioe){ … } try(s_ca){ } Worked Example: Session Programming in SJ
Putting Customer Together protocol p_ca{…} SJSocket s_ca = SJSocketImpl.create(p_ca); s_ca.request(Agency, port); s_ca.outwhile(…){ … } … catch(SJIncompatibleSessionException ise){ … } catch(SJIOException ioe){ … } finally{ … // Session socket ‘s_ca’ is closed. } try(s_ca){ } Worked Example: Session Programming in SJ
Overview (3) • Background and Related Work. • Worked Example: Session Programming in SJ • The SJ Session Runtime. • Conclusion and Future Work. Overview
General Framework The SJ Session Runtime
Sessions over TCP (1) • Map session operations to Socket communications. • Distributed interaction. • Preserve asynchrony. The SJ Session Runtime
Session Initiation (1) The SJ Session Runtime
Session Initiation (2) • C → A : Type of session expected by C. • | A → C : Type of session expected by A. The SJ Session Runtime
Basic Message Passing The SJ Session Runtime
Sessions over TCP (2) • Map session operations to Socket communications. • Distributed communication. • Preserve asynchrony. • Interesting case is delegation. The SJ Session Runtime
“Lost Messages” (1) The SJ Session Runtime
“Lost Messages” (2) The SJ Session Runtime
Sessions over TCP (3) • Map session operations to Socket communications. • Distributed communication. • Preserve asynchrony. • Interesting case is delegation. • Possible designs: • Indefinite forwarding (cf. MobileIP). The SJ Session Runtime