Presentation by Sebastián González of the paper "Context Traits: Dynamic Behaviour Adaptation Through Run-Time Trait Recomposition" at the Modularity • AOSD 2013 conference.
Context Traits Dynamic Behaviour Adaptation Through Run-Time Trait Recomposition
1. Dynamic Behaviour Adaptation
Through Run-Time Trait Recomposition
Sebastián González
Kim Mens
Marius Colacioiu
Walter Cazzola
29 March 2013
Modularity AOSD 2013
UCLouvain . U. Milan
Context Traits
2. Towards a Mindset Shift 2
programming in isolation programming with context
forward!
?
?
?
?
?
?
3. Towards a Mindset Shift 2
Caution
Design patterns
Plugin architectures
Conditional statements
...
programming in isolation programming with context
forward!
?
?
?
?
?
?
4. m(a) {
if ( ) { IE logic }
!
else if ( ) { Opera logic }
else if ( ) { Chrome logic }
else if ( ) { Safari logic }
else if ( ) { Firefox logic }
else { default logic }
}
Conditional Statements 3
Some variant of ...
5. m(a) {
if ( ) { IE logic }
!
else if ( ) { Opera logic }
else if ( ) { Chrome logic }
else if ( ) { Safari logic }
else if ( ) { Firefox logic }
else { default logic }
}
Conditional Statements 3
Some variant of ...
Adaptable
6. m(a) {
if ( ) { IE logic }
!
else if ( ) { Opera logic }
else if ( ) { Chrome logic }
else if ( ) { Safari logic }
else if ( ) { Firefox logic }
else { default logic }
}
Conditional Statements 3
Some variant of ...
Adaptable
Tangled
Scattered
Fixed
No reuse
Complex logic
14. In The Paper
‣ Contexts
‣ Traits
‣ Context-Driven Trait Compositions
‣ Composition Policies
‣ Behaviour Extensibility
‣ Context Traits in JavaScript
‣ Implementation Notes
‣ Case Studies
‣ Related Work
‣ Future Work
6
15. ‣ Contexts
‣ Traits
‣ Context-Driven Trait Compositions
‣ Composition Policies
‣ Behaviour Extensibility
‣ Context Traits in JavaScript
In This Presentation 7
16. Contexts as Situation Reifiers 8
computationally
accessible data
Battery charge = 220 mAh
Idle cycles = 100 MHz
User agent = “Mozilla/5.0...”
Z axis = 0.03
17. Contexts as Situation Reifiers 8
computationally
accessible data
no semantics
Battery charge = 220 mAh
Idle cycles = 100 MHz
User agent = “Mozilla/5.0...”
Z axis = 0.03
18. Contexts as Situation Reifiers 8
computationally
accessible data
no semantics
Battery charge = 220 mAh
Idle cycles = 100 MHz
User agent = “Mozilla/5.0...”
Z axis = 0.03
action can be taken
well-defined
situations
Context
Discovery
Low battery charge
High CPU load
Firefox
Landscape orientation
19. Contexts as Situation Reifiers 8
computationally
accessible data
no semantics
Battery charge = 220 mAh
Idle cycles = 100 MHz
User agent = “Mozilla/5.0...”
Z axis = 0.03
action can be taken
well-defined
situations
Context
Discovery
contexts are reified situations
for which adapted application behaviour can be defined
Low battery charge
High CPU load
Firefox
Landscape orientation
20. Contexts as Situation Reifiers 8
computationally
accessible data
no semantics
Battery charge = 220 mAh
Idle cycles = 100 MHz
User agent = “Mozilla/5.0...”
Z axis = 0.03
action can be taken
well-defined
situations
Context
Discovery
contexts are reified situations
for which adapted application behaviour can be defined
Low battery charge
High CPU load
Firefox
Landscape orientation
LowBattery = new Context();
window.addEventListener(‘batterystatus’,
function (data) {
if (data.level < 30)
LowBattery.activate();
else
LowBattery.deactivate(); });
... in JavaScript
36. Context + Traits 11
... in JavaScriptContext Traits
let Default ∈ C Default = new Context();
37. Context + Traits 11
... in JavaScriptContext Traits
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
38. Context + Traits 11
... in JavaScriptContext Traits
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
39. W3Clet W3C ∈ C W3C = new Context();
Context + Traits 11
... in JavaScriptContext Traits
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
40. W3Clet W3C ∈ C W3C = new Context();
Context + Traits 11
... in JavaScriptContext Traits
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
41. W3Clet W3C ∈ C W3C = new Context();
Context + Traits 11
... in JavaScriptContext Traits
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
42. W3Clet W3C ∈ C W3C = new Context();
Context + Traits 11
... in JavaScriptContext Traits
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
constitution( ida, W3C ) = W3C.adapt(a, T.ValidAnchor);
T.ValidAnchorT.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
43. W3Clet W3C ∈ C W3C = new Context();
Context + Traits 11
... in JavaScriptContext Traits
Untrusted
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
constitution( ida, W3C ) = W3C.adapt(a, T.ValidAnchor);
let Untrusted ∈ C Untrusted = new Context();
T.ValidAnchorT.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
44. W3C
constitution
( ida, Untrusted ) =
Untrusted.adapt
(a, T.SecureAnchor);
let W3C ∈ C W3C = new Context();
Context + Traits 11
... in JavaScriptContext Traits
T.SecureAnchorT.SecureAnchor
href
parent
visible
manager
...
Untrusted
let Default ∈ C Default = new Context();
a = new HTML.Anchor();let ida ∈ L
constitution: L ⨉ C → T
constitution( ida, W3C ) = W3C.adapt(a, T.ValidAnchor);
let Untrusted ∈ C Untrusted = new Context();
T.ValidAnchorT.ValidAnchor
addAttribute
setAttribute
removeAttribute
parent
...
45. Run-Time Trait Recomposition 12
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C
→ 2T
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
46. Run-Time Trait Recomposition 12
overloading of constitution: L ⨉ C → Tconstitution: L ⨉ 2C
→ 2T
defined through composition policiescomposition: 2T
→ O
constitution ( ida, { Default, Untrusted, W3C } )
= { HTML.Anchor, T.SecureAnchor, T.ValidAnchor }
86. ‣ Contexts: frame of reference to define adaptations
‣ Traits: convenient units of adaptation
‣ Policies: flexible compositions (e.g. non-linear)
‣ Extensibility: independent behaviour extensions
‣ JavaScript: easy definition of contexts, traits, and
composition
Summary 17
87. ‣ Contexts: frame of reference to define adaptations
‣ Traits: convenient units of adaptation
‣ Policies: flexible compositions (e.g. non-linear)
‣ Extensibility: independent behaviour extensions
‣ JavaScript: easy definition of contexts, traits, and
composition
Summary 17
direct causal connection
composition of the computational system
situation in which the system executes
⇋
88. In The Paper
‣ Default composition policy
‣ Resolution of proceed chains through policies
‣ Implementation technique for proceed
‣ Case Studies
18
91. Resolution of proceed Through Policies 21
a b
c d
T1
c g
q
T2c() { ... self.proceed() ... }
c d
e f
c h
T3
· · ·
92. Resolution of proceed Through Policies 21
a b
c d
T1
c g
q
T2c() { ... self.proceed() ... }
c d
e f
c h
T3
· · ·
93. Resolution of proceed Through Policies 21
pairwise resolution: Pg ( { T2, T3 } ) = { TR }
a b
c d
T1
c g
q
T2c() { ... self.proceed() ... }
c d
e f
c h
T3
· · ·
94. Resolution of proceed Through Policies 21
pairwise resolution: Pg ( { T2, T3 } ) = { TR }
a b
c d
T1
c g
q
T2
either TR ( c ) = or TR ( c ) =c c
( since policies resolve through +, ▹, ↦, – exclusively )
c() { ... self.proceed() ... }
c d
e f
c h
T3
· · ·
95. Resolution of proceed Through Policies 21
pairwise resolution: Pg ( { T2, T3 } ) = { TR }
a b
c d
T1
c g
q
T2
either TR ( c ) = or TR ( c ) =c c
( since policies resolve through +, ▹, ↦, – exclusively )
c() { ... self.proceed() ... }
c d
e f
suppose TR ( c ) = ; then <c cc
c h
T3
· · ·
96. Resolution of proceed Through Policies 22
Pg induces an order < < <c ccc
c() { ... self.proceed() ... }
current next
97. Resolution of proceed Through Policies 22
Pg induces an order < < <c ccc
c() { ... self.proceed() ... }
current next
c<
100. Resolution By Activation Age
Pa ( { TC1, TC2, ... , TCn } ) = { TC1 ▹ TC2 ▹ ... ▹ TCn }
C1 < C2 < ... < Cnyounger older
Default policy Pa
23
101. Resolution By Activation Age
Pa ( { TC1, TC2, ... , TCn } ) = { TC1 ▹ TC2 ▹ ... ▹ TCn }
C1 < C2 < ... < Cnyounger older
produces a sort of
layering according to
contexts
a b
c dc d
e f
TC1
TC2
e f
g h
TC3
Default policy Pa
23
102. m n
c d
TD
Resolution By Activation Age
Pa ( { TC1, TC2, ... , TCn } ) = { TC1 ▹ TC2 ▹ ... ▹ TCn }
C1 < C2 < ... < Cnyounger older
produces a sort of
layering according to
contexts
a b
c dc d
e f
TC1
TC2
e f
g h
TC3
Default policy Pa
23