Page 1
Tom Van Cutsem Stijn Mostinckx Elisa Gonzalez Boix Jessie Dedecker Wolfgang De Meuter
Programming Technology LabVrije Universiteit Brussel
Brussels, Belgium
XXVI Intl. Conf. of the Chilean Computer Science Society, Iquique, Chile, Nov 2007
AmbientTalk: Object-orientedEvent-driven programming in
Mobile Ad hoc Networks
Page 2
Context
2
Hardware
Software
Pervasive Computing (Mobile Networks)
Object-oriented programming languages
Page 3
Context
2
Hardware
Software
Pervasive Computing (Mobile Networks)
Object-oriented programming languages
Page 4
Mobile Ad hoc Networks
3
Page 5
Mobile Ad hoc Networks
3
Volatile Connections
Page 6
Mobile Ad hoc Networks
3
Volatile Connections
Scarce Infrastructure
Page 7
Loose Coupling
4
reduces impact of volatile connections
Decoupling communication in Time & Synchronisation
Page 8
Loose Coupling
4
reduces impact of volatile connections
Decoupling communication in Time & Synchronisation
Page 9
Loose Coupling
4
asynchronous
send
reduces impact of volatile connections
Decoupling communication in Time & Synchronisation
Page 10
Loose Coupling
4
reduces impact of volatile connections
Decoupling communication in Time & Synchronisation
Page 11
Loose Coupling
4
reduces impact of volatile connections
Decoupling communication in Time & Synchronisation
Page 12
Loose Coupling
4
reduces impact of volatile connections
Decoupling communication in Time & Synchronisation
Page 13
Loose Coupling
4
asynchronous
receive
reduces impact of volatile connections
Decoupling communication in Time & Synchronisation
Page 14
Loose Coupling
5
enables ad hoc anonymous collaborations
Decoupling communication in Space
Page 15
Loose Coupling
5
enables ad hoc anonymous collaborations
Decoupling communication in Space
Page 16
Loose Coupling
5
enables ad hoc anonymous collaborations
Decoupling communication in Space
provide service
Page 17
Loose Coupling
5
enables ad hoc anonymous collaborations
Decoupling communication in Space
require serviceprovide service
Page 18
Ubiquitous Flea Market
6
Example: buy/sell concert tickets to proximate peers
offer
demand
Page 19
Ubiquitous Flea Market
6
Example: buy/sell concert tickets to proximate peers
offer
demand
Page 20
AmbientTalk: the language
• Distributed object-oriented language
• Event-driven concurrency based on actors [Agha86]
• Future-type asynchronous message sends
• Built-in publish/subscribe engine for service discovery of remote objects
7
Page 21
AmbientTalk: the project
• Started in 2005
• Small team: 3-6 people
• Interpreter
• Pure Java implementation
• Runs on J2ME/CDC phones
8
Page 22
def Item := object: { def category; def description; def ownerContactInfo; def init(c,d,o) { category := c; description := d; ownerContactInfo := o; } def getContactInfo() { ownerContactInfo } def placeSupply() {...} def placeDemand() {...}}
Objects
9
def ticket := Item.new(ConcertTicket,”...”,”...”);ticket.placeDemand();
• Prototype-based
• Objects are created:
• anonymously
• by cloning others
Page 23
Extensible language
10
def fac(n) { (n = 0).ifTrue: { 1 } ifFalse: { n * fac(n-1) }}
• Block closures
• Keyworded messages
• Interfacing with JVM
Page 24
Extensible language
10
def fac(n) { (n = 0).ifTrue: { 1 } ifFalse: { n * fac(n-1) }}
def Button := jlobby.java.awt.Button;def b := Button.new(”test”);b.addActionListener(object: { def actionPerformed(ae) { println(”button pressed”); }});
• Block closures
• Keyworded messages
• Interfacing with JVM
Page 25
Event loop concurrency
11
Actor
Message queue Event loop
Based on E programming language [Miller05]
Page 26
Event loop concurrency
11
Actor
Message queue Event loop
‘local’ object
Based on E programming language [Miller05]
Page 27
Event loop concurrency
11
Actor
Message queue Event loop
‘local’ object
obj
obj.m()
Based on E programming language [Miller05]
Page 28
Event loop concurrency
11
Actor
Message queue Event loop
‘local’ object ‘remote’ object
Based on E programming language [Miller05]
Page 29
Event loop concurrency
11
Actor
Message queue Event loop
‘local’ object ‘remote’ object
obj
obj<-m()
Based on E programming language [Miller05]
Page 30
Event loop concurrency
11
Actor
Message queue Event loop
‘local’ object ‘remote’ object
Actors cannot cause deadlock
No race conditions on objects
obj
obj<-m()
Based on E programming language [Miller05]
Page 31
Futures
12
advertisement
def future := advertisement<-getContactInfo()
Page 32
Futures
12
advertisement
def future := advertisement<-getContactInfo()
Page 33
Futures
12
advertisement
def future := advertisement<-getContactInfo()
?future
Page 34
Futures
12
advertisement
def future := advertisement<-getContactInfo()
?future
Page 35
Futures
12
advertisement
def future := advertisement<-getContactInfo()
?future
Page 36
when: future becomes: { |contactInfo| println(“contact seller: “ + contactInfo)}
Futures
12
advertisement
def future := advertisement<-getContactInfo()
?future
Page 37
when: future becomes: { |contactInfo| println(“contact seller: “ + contactInfo)}
Futures
12
advertisement
def future := advertisement<-getContactInfo()
?future
contactInfo
Page 38
when: future becomes: { |contactInfo| println(“contact seller: “ + contactInfo)}
Futures
12
advertisement
def future := advertisement<-getContactInfo()
?future
contactInfo
Page 39
when: future becomes: { |contactInfo| println(“contact seller: “ + contactInfo)}
Futures
12
advertisement
def future := advertisement<-getContactInfo()
?future
contactInfo
Page 40
Exporting objects
13
item
Page 41
Exporting objects
13
item
deftype ConcertTicket;
def Item := object: { def category; // a type tag ... def placeSupply() { export: item as: category; }}
Page 42
def placeDemand() { whenever: category discovered: {|item| ... }}
Service Discovery
14
<closure>
Page 43
def placeDemand() { whenever: category discovered: {|item| ... }}
Service Discovery
14
<closure> item
Page 44
def placeDemand() { whenever: category discovered: {|item| ... }}
Service Discovery
14
<closure> item
Page 45
item<closure>
Failure handling
15
item<-getContactInfo()
Page 46
item<closure> remote ref
Failure handling
15
item<-getContactInfo()
Page 47
item<closure> remote ref
Failure handling
15
item<-getContactInfo()
Page 48
item<closure> remote ref
Failure handling
15
item<-getContactInfo()
Page 49
item<closure> remote ref
Failure handling
15
when: item disconnected: { println(“Item no longer available”)}
when: item reconnected: { println(“Item available again”)}
item<-getContactInfo()
Page 50
item<closure> remote ref
Failure handling
15
when: item disconnected: { println(“Item no longer available”)}
when: item reconnected: { println(“Item available again”)}
item<-getContactInfo()
Page 51
whenever: category discovered: { |item| when: item<-getContactInfo() becomes: { |contactInfo| println(“contact seller: “ + contactInfo) } when: item disconnected: { println(“Item no longer available”) }}
Events + Objects
• Block closures as first-class event-handlers
• preserve state (all lexically visible variables)
• can be arbitrarily nested
• Leads to less ‘inversion of control’
16
Page 52
whenever: category discovered: { |item| when: item<-getContactInfo() becomes: { |contactInfo| println(“contact seller: “ + contactInfo) } when: item disconnected: { println(“Item no longer available”) }}
Events + Objects
• Block closures as first-class event-handlers
• preserve state (all lexically visible variables)
• can be arbitrarily nested
• Leads to less ‘inversion of control’
16
Page 53
Conclusion
• MANETs → loosely coupled collaboration
• AmbientTalk: event-driven OO language
• Buffered asynchronous messages: tolerate temporary network failures by default
• Built-in service discovery: no servers required
17
http://prog.vub.ac.be/amop
Volatile Connections → time & sync-decoupling
Scarce Infrastructure → space-decoupling