session-based distributed programming in java raymond hu 1 session-based distributed programming in...
TRANSCRIPT
Session-based Distributed Programming in Java
Raymond Hu
1
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
Session-based Distributed Programming in Java
Raymond Hu
2
Overview (1)
1. Background and Related Work.
2. Worked Example: Session Programming in SJ.
3. The SJ Session Runtime.
4. Conclusion and Future Work.
Overview
Session-based Distributed Programming in Java
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
Session-based Distributed Programming in Java
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
Session-based Distributed Programming in Java
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 and distributed language.
Theoretical Background
Session-based Distributed Programming in Java
Raymond Hu
6
Implementation of Session Types
• Singularity OS [FAHHHLL06]:– Restrictions on session features, not distributed.
Related Work
Session-based Distributed Programming in Java
Raymond Hu
7
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
Session-based Distributed Programming in Java
Raymond Hu
8
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
Session-based Distributed Programming in Java
Raymond Hu
9
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
Session-based Distributed Programming in Java
Raymond Hu
10
Overview (2)
1. Background and Related Work.
2. Worked Example: Session Programming in SJ.
3. The SJ Session Runtime.
4. Conclusion and Future Work.
Overview
Session-based Distributed Programming in Java
Raymond Hu
11
An Online Ticket Ordering System
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
12
Protocol Specification (1)
begin
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
13
Protocol Specification (1)
begin.
!(String)
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
14
Protocol Specification (1)
begin.
!(String).
?(Double)
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
15
Protocol Specification (1)
begin.
!(String).
?(Double)
![
]*.
…
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
16
Protocol Specification (1)
begin.
?[
?(String).
!(Double)
]*.
…
begin.
!(String).
?(Double)
![
]*.
…
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
17
Protocol Specification (2)
…?{
}.
…
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
18
Protocol Specification (2)
…
ACCEPT:
… ,
REJECT:
…
?{
}.
…
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
19
Protocol Specification (3)
protocol p_as {
}
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
20
Protocol Specification (3)
protocol p_as {
}
begin.!(
)
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
21
Protocol Specification (3)
?(Address).!(Date)
protocol p_as {
}
begin.!(
)
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
22
Protocol Implementation (1)
protocol p_ca {begin.![!(String).?(Double)
]*.…
// Customer
SJSocket s_ca = SJSocketImpl.create(p_ca);
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
23
Protocol Implementation (1)
protocol p_ca {begin.![!(String).?(Double)
]*.…
// Customer
SJSocket s_ca = SJSocketImpl.create(p_ca);
s_ca.request(Agency, port);
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
24
Protocol Implementation (1)
protocol p_ca {begin.![!(String).?(Double)
]*.…
// Customer
SJSocket s_ca = SJSocketImpl.create(p_ca);
s_ca.request(Agency, port);s_ca.outwhile(!decided) {
}
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
25
Protocol Implementation (1)
protocol p_ca {begin.![!(String).?(Double)
]*.…
// Customer
SJSocket s_ca = SJSocketImpl.create(p_ca);
s_ca.request(Agency, port);
s_ca.send(travDetails);
s_ca.outwhile(!decided) {
}
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
26
Protocol Implementation (1)
protocol p_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 = …;
s_ca.outwhile(!decided) {
}
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
27
Protocol Implementation (1)
protocol p_ca {begin.![!(String).?(Double)
]*.…
// Customer
SJSocket s_ca = SJSocketImpl.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 in SJ
Session-based Distributed Programming in Java
Raymond Hu
28
Protocol Implementation (2)
…!{ACCEPT:
… , // 1
REJECT:… // 2
}…
// Customer
s_ca.select(ACCEPT) {
… // 1
}
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
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 in SJ
Session-based Distributed Programming in Java
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 in SJ
Session-based Distributed Programming in Java
Raymond Hu
31
Protocol Implementation (3)
…
?{
ACCEPT:
… , // 1’
REJECT:
… // 2’
}
…
// Agency
…s_ac.branch() {
}
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
32
Protocol Implementation (3)
…
?{
ACCEPT:
… , // 1’
REJECT:
… // 2’
}
…
// Agency
case ACCEPT: {
… // 1’
}
case REJECT: {
… // 2’
}
…s_ac.branch() {
}
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
33
Putting Customer Togetherprotocol p_ca { … }
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
34
Putting Customer Together
Worked Example: Session Programming in SJ
protocol p_ca { … }SJSocket s_ca = SJSocketImpl.create(p_ca);
Session-based Distributed Programming in Java
Raymond Hu
35
Putting Customer Togetherprotocol p_ca { … }SJSocket s_ca = SJSocketImpl.create(p_ca);
s_ca.request(Agency, port);s_ca.outwhile(…) {
… }…
Worked Example: Session Programming in SJ
Session-based Distributed Programming in Java
Raymond Hu
36
Putting Customer Togetherprotocol 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
Session-based Distributed Programming in Java
Raymond Hu
37
Putting Customer Togetherprotocol p_ca { … }SJSocket s_ca = SJSocketImpl.create(p_ca);
s_ca.request(Agency, port);s_ca.outwhile(…) {
… }…
catch(SJIOException ioe) { … }
Worked Example: Session Programming in SJ
try (s_ca) {
}
Session-based Distributed Programming in Java
Raymond Hu
38
Putting Customer Togetherprotocol p_ca { … }SJSocket s_ca = SJSocketImpl.create(p_ca);
s_ca.request(Agency, port);s_ca.outwhile(…) {
… }…
catch(SJIncompatibleSessionException ise) { … }catch(SJIOException ioe) { … }
Worked Example: Session Programming in SJ
try (s_ca) {
}
Session-based Distributed Programming in Java
Raymond Hu
39
Putting Customer Togetherprotocol 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.}
Worked Example: Session Programming in SJ
try (s_ca) {
}
Session-based Distributed Programming in Java
Raymond Hu
40
Overview (3)
1. Background and Related Work.
2. Worked Example: Session Programming in SJ
3. The SJ Session Runtime.
4. Conclusion and Future Work.
Overview
Session-based Distributed Programming in Java
Raymond Hu
General Framework
41The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
Session Runtime Architecture
42
Session-based Distributed Programming in Java
Raymond Hu
43
Sessions over TCP (1)
• Map session operations to Socket communications.– Distributed interaction.– Preserve asynchrony.
The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
Session Initiation (1)
44The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
45
Session Initiation (2)
C → A : Type of session expected by C.
| A → C : Type of session expected by A.
The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
Basic Message Passing
46The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
47
Sessions over TCP (2)
• Map session operations to Socket communications.– Distributed communication.– Preserve asynchrony.
Interesting case is delegation.
The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
48
“Lost Messages” (1)
The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
49
“Lost Messages” (2)
The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
50
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
Session-based Distributed Programming in Java
Raymond Hu
51
Sessions over TCP (3)
• Map session operations to Socket communications.– Distributed communication.– Preserve asynchrony.
Interesting case is delegation.
Possible designs:× Indefinite forwarding (cf. MobileIP). “Lost message” resending.
The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
52
Sessions over TCP (3)
• Map session operations to Socket communications.– Distributed communication.– Preserve asynchrony.
Interesting case is delegation.
Possible designs:× Indefinite forwarding (cf. MobileIP). “Lost message” resending. “Lost message” forwarding.
The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
53
Session Delegation (1)
The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
54
Session Delegation (2)
1. S: Create server socket on p.
The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
55
Session Delegation (3)
1. S: Create server socket on p.
2. S → A: p
The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
56
Session Delegation (4)
1. S: Create server socket on p.
2. S → A: p
3. A → C: S, p, ST(A)
The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
57
Forwarding
4. A → S: “Lost messages” forwarded.
5. C: Connect to S:p
The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
58
Resending
4. C: Connect to S:p
5. C → S: “Lost messages” according to Session Types.
The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
Session Delegation (5)• What if A has finished her side of the session?
59The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
Session Delegation (5)• What if A has finished her side of the session?• What if A is sending a session?
60The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
Session Delegation (5)• What if A has finished her side of the session?• What if A is sending a session?• What if A is delegating the session at the same time?
61The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
Session Delegation (5)• What if A has finished her side of the session?• What if A is sending a session?• What if A is delegating the session at the same time?• Asynchronous session-send.
62The SJ Session Runtime
Session-based Distributed Programming in Java
Raymond Hu
63
Overview (4)
1. Background and Related Work.
2. Worked Example: Session Programming in SJ.
3. The SJ Session Runtime.
4. Conclusion and Future Work.
Overview
Session-based Distributed Programming in Java
Raymond Hu
64
Conclusion http://www.doc.ic.ac.uk/~rh105/sessionj.html
Conclusion
Session-based Distributed Programming in Java
Raymond Hu
65
Conclusion http://www.doc.ic.ac.uk/~rh105/sessionj.html• Integration of session type theory and O-O for
practical, type-safe session-based programming.
Conclusion
Session-based Distributed Programming in Java
Raymond Hu
66
Conclusion http://www.doc.ic.ac.uk/~rh105/sessionj.html• Integration of session type theory and O-O for
practical, type-safe session-based programming.• Runtime architecture for session abstraction.
Conclusion
Session-based Distributed Programming in Java
Raymond Hu
67
Conclusion http://www.doc.ic.ac.uk/~rh105/sessionj.html• Integration of session type theory and O-O for
practical, type-safe session-based programming.• Runtime architecture for session abstraction.• Asynchronous communication and distribution.
Conclusion
Session-based Distributed Programming in Java
Raymond Hu
68
Conclusion http://www.doc.ic.ac.uk/~rh105/sessionj.html• Integration of session type theory and O-O for
practical, type-safe session-based programming.• Runtime architecture for session abstraction.• Asynchronous communication and distribution.• Session subtyping, interleaving, exceptions/failure.
Conclusion
Session-based Distributed Programming in Java
Raymond Hu
69
Conclusion http://www.doc.ic.ac.uk/~rh105/sessionj.html• Integration of session type theory and O-O for
practical, type-safe session-based programming.• Runtime architecture for session abstraction.• Asynchronous communication and distribution.• Session subtyping, interleaving, exceptions/failure.• Combination of static and dynamic session types.
Conclusion
Session-based Distributed Programming in Java
Raymond Hu
70
Conclusion http://www.doc.ic.ac.uk/~rh105/sessionj.html• Integration of session type theory and O-O for
practical, type-safe session-based programming.• Runtime architecture for session abstraction.• Asynchronous communication and distribution.• Session subtyping, interleaving, exceptions/failure.• Combination of static and dynamic session types.• Eager class downloading and verification.
Conclusion
Session-based Distributed Programming in Java
Raymond Hu
71
Conclusion http://www.doc.ic.ac.uk/~rh105/sessionj.html• Integration of session type theory and O-O for
practical, type-safe session-based programming.• Runtime architecture for session abstraction.• Asynchronous communication and distribution.• Session subtyping, interleaving, exceptions/failure.• Combination of static and dynamic session types.• Eager class downloading and verification.• Low overhead.
Conclusion
Session-based Distributed Programming in Java
Raymond Hu
72
Future Work• Write more code!
Future Work
Session-based Distributed Programming in Java
Raymond Hu
73
Future Work• Write more code!• Usability improvements (syntax, features, ...).
Future Work
Session-based Distributed Programming in Java
Raymond Hu
74
Future Work• Write more code!• Usability improvements (syntax, features, ...).• Communication optimisations.
Future Work
Session-based Distributed Programming in Java
Raymond Hu
75
Future Work• Write more code!• Usability improvements (syntax, features, ...).• Communication optimisations.• Sessions over alternative transports.
Future Work
Session-based Distributed Programming in Java
Raymond Hu
76
Future Work• Write more code!• Usability improvements (syntax, features, ...).• Communication optimisations.• Sessions over alternative transports.• Multiparty sessions.
Future Work
Session-based Distributed Programming in Java
Raymond Hu
77
Future Work• Write more code!• Usability improvements (syntax, features, ...).• Communication optimisations.• Sessions over alternative transports.• Multiparty sessions.• Session exceptions.
Future Work
Session-based Distributed Programming in Java
Raymond Hu
78
Future Work• Write more code!• Usability improvements (syntax, features, ...).• Communication optimisations.• Sessions over alternative transports.• Multiparty sessions.• Session exceptions.• Automatic session implementation generation.
Future Work
Session-based Distributed Programming in Java
Raymond Hu
79
Future Work• Write more code!• Usability improvements (syntax, features, ...).• Communication optimisations.• Sessions over alternative transports.• Multiparty sessions.• Session exceptions.• Automatic session implementation generation.• Further integration of sessions and objects.
Future Work
Session-based Distributed Programming in Java
Raymond Hu
80
Future Work• Write more code!• Usability improvements (syntax, features, ...).• Communication optimisations.• Sessions over alternative transports.• Multiparty sessions.• Session exceptions.• Automatic session implementation generation.• Further integration of sessions and objects.
Future Work
Session-based Distributed Programming in Java
Raymond Hu
81
Preliminary Results (1)
• For simple benchmark experiment, implemented:
begin . ![ ?( MyObject ) ]* . end
Results
Session-based Distributed Programming in Java
Raymond Hu
82
Preliminary Results (1)
• For simple benchmark experiment, implemented:
begin . ![ ?( MyObject ) ]* . end
• Using:– SJFSocket and SJRSocket– java.net.Socket– RMI: MyObject remoteMeth(Boolean bool)
Results
Session-based Distributed Programming in Java
Raymond Hu
83
Preliminary Results (2)
Results