Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe...

70
Type-safe Communication in Java with Session Types Raymond Hu 1 Type-safe Communication in Java with Session Types Raymond Hu 1 , Nobuko Yoshida 1 and Kohei Honda 2 1. Imperial College London; 2. Queen Mary, Uni. of London June 2007

Transcript of Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe...

Page 1: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

1

Type-safe Communication in Java with Session TypesRaymond Hu1, Nobuko Yoshida1 and Kohei Honda2

1. Imperial College London; 2. Queen Mary, Uni. of London

June 2007

Page 2: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

2

Overview (1)

1. Background and Related Work.2. Worked Example: Session Programming.3. Runtime Support for Session Communication.4. Conclusion and Future Work.

Overview

Page 3: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

3

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

Page 4: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

4

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

Page 5: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

5

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, distributed language.

Theoretical Background

Page 6: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

6

Implementation of Session Types• Singularity OS:

– Restricted features, not distributed.

Related Work

Page 7: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

7

Implementation of Session Types• Singularity OS:

– Restricted features, not distributed.• Multithreaded functional language design [VGR06]:

– Not distributed, no actual implementation.

Related Work

Page 8: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

8

Implementation of Session Types• Singularity OS:

– Restricted features, not distributed.• Multithreaded functional language design [VGR06]:

– Not distributed, no actual implementation.• Encodings of sess. types (e.g. Haskell [NT04], C++):

– Proof of concept, but not full implementations.

Related Work

Page 9: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

9

Implementation of Session Types• Singularity OS [FAHHHLL06]:

– Restricted features, not distributed.• Multithreaded functional language design [VGR06]:

– Not distributed, no actual implementation.• Encodings of sess. types (e.g. Haskell [NT04], C++):

– Proof of concept, but not full implementations.

Why use untyped sockets if we can use sessions?

Related Work

Page 10: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

10

Overview (2)

1. Background and Related Work.2. Worked Example: Language Design.3. Runtime Support for Session Communication.4. Conclusion and Future Work.

Overview

Page 11: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

11

An Online Ticket Ordering System

Worked Example: Session Programming

Page 12: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

12

Protocol Specification (1)

begin

Worked Example: Session Programming

Page 13: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

13

Protocol Specification (1)

begin.

!(String)

Worked Example: Session Programming

Page 14: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

14

Protocol Specification (1)

begin.

!(String).?(Double)

Worked Example: Session Programming

Page 15: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

15

Protocol Specification (1)

begin.

!(String).?(Double)

![

]*.…

Worked Example: Session Programming

Page 16: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

16

Protocol Specification (1)

begin.?[?(String).!(Double)

]*.…

begin.

!(String).?(Double)

![

]*.…

Worked Example: Session Programming

Page 17: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

17

Protocol Specification (2)

…?{

}.…

Worked Example: Session Programming

Page 18: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

18

Protocol Specification (2)

ACCEPT: … ,

REJECT:…

?{

}.…

Worked Example: Session Programming

Page 19: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

19

Protocol Specification (3)

protocol p_as {

}

Worked Example: Session Programming

Page 20: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

20

Protocol Specification (3)

protocol p_as {

}

begin.!(

).end

Worked Example: Session Programming

Page 21: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

21

Protocol Specification (3)

?(Address).!(Date).end

protocol p_as {

}

begin.!(

).end

Worked Example: Session Programming

Page 22: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

22

Protocol Implementation (1)

protocol p_ca {begin.![!(String).?(Double)

]*.…

// CustomerSTSocket s_ca = STSocketImpl.create(p_ca);

Worked Example: Session Programming

Page 23: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

23

Protocol Implementation (1)

protocol p_ca {begin.![!(String).?(Double)

]*.…

// CustomerSTSocket s_ca = STSocketImpl.create(p_ca);

s_ca.request(Agency, port);

Worked Example: Session Programming

Page 24: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

24

Protocol Implementation (1)

protocol p_ca {begin.![!(String).?(Double)

]*.…

// CustomerSTSocket s_ca = STSocketImpl.create(p_ca);

s_ca.request(Agency, port);s_ca.outwhile(!decided) {

}

Worked Example: Session Programming

Page 25: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

25

Protocol Implementation (1)

protocol p_ca {begin.![!(String).?(Double)

]*.…

// CustomerSTSocket s_ca = STSocketImpl.create(p_ca);

s_ca.request(Agency, port);

s_ca.send(travDetails);s_ca.outwhile(!decided) {

}

Worked Example: Session Programming

Page 26: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

26

Protocol Implementation (1)

protocol p_ca {begin.![!(String).?(Double)

]*.…

// CustomerSTSocket s_ca = STSocketImpl.create(p_ca);

s_ca.request(Agency, port);

s_ca.send(travDetails);cost =

(Double)s_ca.receive();decided = …;

s_ca.outwhile(!decided) {

}

Worked Example: Session Programming

Page 27: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

27

Protocol Implementation (1)

protocol p_ca {begin.![!(String).?(Double)

]*.…

// CustomerSTSocket s_ca = STSocketImpl.create(p_ca);

s_ca.request(Agency, port);

s_ca.send(travDetails);

decided = …;

s_ca.outwhile(!decided) {

}

cost = s_ca.receive();

Worked Example: Session Programming

Page 28: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

28

Protocol Implementation (2)

…!{ACCEPT:

… , // 1

REJECT:… // 2

}…

// Customer

s_ca.select(ACCEPT) {… // 1

}

Worked Example: Session Programming

Page 29: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

29

Protocol Implementation (2)

…!{ACCEPT:

… , // 1

REJECT:… // 2

}…

// Customer

s_ca.select(ACCEPT) {… // 1

}

if(cost < 100.00) {

}else {

}

Worked Example: Session Programming

Page 30: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

30

Protocol Implementation (2)

…!{ACCEPT:

… , // 1

REJECT:… // 2

}…

// Customer

s_ca.select(ACCEPT) {… // 1

}

s_ca.select(REJECT) {… // 2

}

if(cost < 100.00) {

}else {

}

Worked Example: Session Programming

Page 31: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

31

Protocol Implementation (3)

…?{ACCEPT:

… , // 1’

REJECT:… // 2’

}…

// Agency

…s_ac.branch() {

}

Worked Example: Session Programming

Page 32: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

32

Protocol Implementation (3)

…?{ACCEPT:

… , // 1’

REJECT:… // 2’

}…

// Agency

case ACCEPT: {… // 1’

}case REJECT: {

… // 2’}

…s_ac.branch() {

}

Worked Example: Session Programming

Page 33: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

33

Putting Customer Togetherprotocol p_ca { … }

Worked Example: Session Programming

Page 34: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

34

Putting Customer Togetherprotocol p_ca { … }STSocket s_ca = STSocketImpl.create(p_ca);

Worked Example: Session Programming

Page 35: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

35

Putting Customer Togetherprotocol p_ca { … }STSocket s_ca = STSocketImpl.create(p_ca);

s_ca.request(Agency, port);s_ca.outwhile(…) {

…}…

Worked Example: Session Programming

Page 36: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

36

Putting Customer Togetherprotocol p_ca { … }STSocket s_ca = STSocketImpl.create(p_ca);

s_ca.request(Agency, port);s_ca.outwhile(…) {

…}…

try {

}

Worked Example: Session Programming

Page 37: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

37

Putting Customer Togetherprotocol p_ca { … }STSocket s_ca = STSocketImpl.create(p_ca);

s_ca.request(Agency, port);s_ca.outwhile(…) {

…}…

catch(IOException ioe) { … }

try {

}

Worked Example: Session Programming

Page 38: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

38

Putting Customer Togetherprotocol p_ca { … }STSocket s_ca = STSocketImpl.create(p_ca);

s_ca.request(Agency, port);s_ca.outwhile(…) {

…}…

catch(STIncompatibleSessionException ise) { … }catch(IOException ioe) { … }

try {

}

Worked Example: Session Programming

Page 39: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

39

Putting Customer Togetherprotocol p_ca { … }STSocket s_ca = STSocketImpl.create(p_ca);

s_ca.request(Agency, port);s_ca.outwhile(…) {

…}…

catch(STIncompatibleSessionException ise) { … }catch(IOException ioe) { … }finally {

s_ca.close();}

try {

}

Worked Example: Session Programming

Page 40: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

40

Overview (3)

1. Background and Related Work.2. Worked Example: Language Design.3. Runtime Support for Session Communication.4. Conclusion and Future Work.

Overview

Page 41: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

41

Sessions over TCPMap session operations to Socket communications.– Preserve asynchrony.– Interesting case is delegation.

Runtime Support for Session Communication

Page 42: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

42

Sessions over TCPMap session operations to Socket communications.– Preserve asynchrony.– Interesting case is delegation.

• Possible designs:– Proxy / Integrated runtime layer.– “Lost message” forwarding (cf. Mobile IP).– “Lost message” resending.

Runtime Support for Session Communication

Page 43: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

43

Session Initiation

Runtime Support for Session Communication

Page 44: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

44

Session Initiation

1. C → A : Type of intended session.

Runtime Support for Session Communication

Page 45: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

45

Session Initiation

1. C → A : Type of intended session.2. A → C: “YES” if types compatible, else “NO”.

Runtime Support for Session Communication

Page 46: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

46

Session Communication

Runtime Support for Session Communication

Page 47: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

47

Session Delegation (1)

Runtime Support for Session Communication

Page 48: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

48

Session Delegation (2)

1. S: Create server socket on port.

Runtime Support for Session Communication

1.

Page 49: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

49

Session Delegation (2)

1. S: Create server socket on port.2. S → A: port

Runtime Support for Session Communication

1.← 2. port

Page 50: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

50

Session Delegation (2)

1. S: Create server socket on port.2. S → A: port3. A → C: IPS, port, STA(sca)

Runtime Support for Session Communication

1.← 2. port

3.

Page 51: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

51

Session Delegation (3)

4. C: Connect to IPS: port.

Runtime Support for Session Communication

Page 52: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

52

Session Delegation (3)

4. C: Connect to IPS: port.5. C → S: “Lost messages” according to STA(sca) - STC(sca).

Runtime Support for Session Communication

5. delivAddr

Page 53: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

53

Overview (4)

1. Background and Related Work.2. Worked Example: Language Design.3. Runtime Support for Session Communication.4. Conclusion and Future Work.

Overview

Page 54: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

54

Conclusionhttp://www/~rh105/sessiondj.html

Conclusion

Page 55: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

55

Conclusionhttp://www/~rh105/sessiondj.html

• Realised many session type principles in a concrete, practical object-oriented language.

Conclusion

Page 56: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

56

Conclusionhttp://www/~rh105/sessiondj.html

• Realised many session type principles in a concrete, practical object-oriented language.

• Asynchrony and distribution.

Conclusion

Page 57: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

57

Conclusionhttp://www/~rh105/sessiondj.html

• Realised many session type principles in a concrete, practical object-oriented language.

• Asynchrony and distribution.• Session interleaving, exceptions/failure.

Conclusion

Page 58: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

58

Conclusionhttp://www/~rh105/sessiondj.html

• Realised many session type principles in a concrete, practical object-oriented language.

• Asynchrony and distribution.• Session interleaving, exceptions/failure.• Protocols for session initiation, delegation and close.

Conclusion

Page 59: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

59

Conclusionhttp://www/~rh105/sessiondj.html

• Realised many session type principles in a concrete, practical object-oriented language.

• Asynchrony and distribution.• Session interleaving, exceptions/failure.• Protocols for session initiation, delegation and close.• Delegation protocol uses session type information.

Conclusion

Page 60: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

60

Future Work• Usability improvements (syntax, features, ...).• Communication optimisations.

Future Work

Page 61: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

61

Future Work• Usability improvements (syntax, features, ...).• Communication optimisations.• Language evaluation (large example applications).• Performance evaluation.

Future Work

Page 62: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

62

Future Work• Usability improvements (syntax, features, ...).• Communication optimisations.• Language evaluation (large example applications).• Performance evaluation.• Associating session types to addresses.

Future Work

Page 63: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

63

Future Work• Usability improvements (syntax, features, ...).• Communication optimisations.• Language evaluation (large example applications).• Performance evaluation.• Associating session types to addresses.• Class downloading and verification.

Future Work

Page 64: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

64

Future Work• Usability improvements (syntax, features, ...).• Communication optimisations.• Language evaluation (large example applications).• Performance evaluation.• Associating session types to addresses.• Class downloading and verification.• Session exceptions.

Future Work

Page 65: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

65

Future Work• Usability improvements (syntax, features, ...).• Communication optimisations.• Language evaluation (large example applications).• Performance evaluation.• Associating session types to addresses.• Class downloading and verification.• Session exceptions.• Alternative runtime designs.• Sessions over alternative transports.

Future Work

Page 66: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

66

Session Exceptions (Poss. Design)protocol p { begin.….end | X:….end | … }STChannel c = new STChannel(…, p);STSocket s = STSocketImpl.create(c);try {

try {s.request();…

}catch(STIncompatibleSessionException ise) { }catch(s:X) { … }catch(…) { … }

}catch(IOException ioe) { … }finally { s.close(); }

Future Work

Page 67: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

67

Preliminary Results (1)• For simple benchmark experiment, implemented:

begin . ![ ?( MyObject ) ]* . end

Results

Page 68: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

68

Preliminary Results (1)• For simple benchmark experiment, implemented:

begin . ![ ?( MyObject ) ]* . end

• Using:– STSocket and equivalent “Plain Socket”– STNIOSocket and equivalent “Plain SocketChannel”– RMI: MyObject remoteMeth(Boolean bool)

Results

Page 69: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

69

Preliminary Results (2)

Results

Page 70: Type-safe Communication in Java with Session Typesrhu/sessionj/icooolps07language.pdf · Type-safe Communication in Java with Session Types Raymond Hu 3 Session Types • Type systems

Type-safe Communication in Java with Session Types

Raymond Hu

70

Preliminary Results (3)

Results