Context-awareness plays a central role in self-
adaptive software. By a programming perspective, context is
often used implicitly, and context-aware code is fragmented
in the codebase. In Context-Oriented Programming, instead,
context is considered a first-class citizen and is explicitly used
to modularise context-sensitive functionality and behavioural
variability. In this paper, we reflect on the role of context in
collective adaptive systems, by a discussion from the special
perspective of a macro paradigm, Aggregate Programming,
which supports the specification of collective behaviour by a
global perspective through functional compositions of field com-
putations. In particular, we consider the abstractions exposed in
Context-Oriented and Aggregate Programming, suggest potential
synergies in both directions, and accordingly take the first steps
towards a combined design.
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
On Context-Orientation in Aggregate Programming
1. On Context-Orientation in Aggregate Programming
Roberto Casadei1
, Danilo Pianini1
, Guido Salvaneschi2
, Mirko Viroli1
1
ALMA MATER STUDIORUM–Università di Bologna, Cesena, Italy
2
Technische Universität Darmstadt, Darmstadt, Germany
4th eCAS Workshop on Engineering Collective Adaptive Systems
Umeå, Sweden
June, 2019
R. Casadei Introduction COP AP AP + COP Wrap-up 1/17
2. Outline
1 Introduction
2 Context-Oriented Programming (COP)
3 Aggregate Programming
4 Programming Context-aware Systems: AP & COP
5 Wrap-up
R. Casadei Introduction COP AP AP + COP Wrap-up 2/17
7. motivation—how to program
context-aware systems?
runtime dependency substitution, AOP, ...
Context-Oriented Programming (COP)
software variability management (SPLs, ...)
self-* research—e.g., Aggregate Programming (AP)
R. Casadei Introduction COP AP AP + COP Wrap-up 4/17
8. motivation—how to program
context-aware systems?
runtime dependency substitution, AOP, ...
Context-Oriented Programming (COP)
software variability management (SPLs, ...)
self-* research—e.g., Aggregate Programming (AP)
R. Casadei Introduction COP AP AP + COP Wrap-up 4/17
9. motivation—how to program
context-aware systems?
runtime dependency substitution, AOP, ...
Context-Oriented Programming (COP)
software variability management (SPLs, ...)
self-* research—e.g., Aggregate Programming (AP)
R. Casadei Introduction COP AP AP + COP Wrap-up 4/17
10. motivation—how to program
context-aware systems?
runtime dependency substitution, AOP, ...
Context-Oriented Programming (COP)
software variability management (SPLs, ...)
self-* research—e.g., Aggregate Programming (AP)
R. Casadei Introduction COP AP AP + COP Wrap-up 4/17
11. motivation—how to program
context-aware systems?
runtime dependency substitution, AOP, ...
Context-Oriented Programming (COP)
software variability management (SPLs, ...)
self-* research—e.g., Aggregate Programming (AP)
R. Casadei Introduction COP AP AP + COP Wrap-up 4/17
12. contribution
1) context-orientation in Aggregate Computing
2) potential synergies between Context-Oriented (COP)
and Aggregate Programming (AP)
– AP for COP
– COP for AP
R. Casadei Introduction COP AP AP + COP Wrap-up 5/17
13. contribution
1) context-orientation in Aggregate Computing
2) potential synergies between Context-Oriented (COP)
and Aggregate Programming (AP)
– AP for COP
– COP for AP
R. Casadei Introduction COP AP AP + COP Wrap-up 5/17
14. contribution
1) context-orientation in Aggregate Computing
2) potential synergies between Context-Oriented (COP)
and Aggregate Programming (AP)
– AP for COP
– COP for AP
R. Casadei Introduction COP AP AP + COP Wrap-up 5/17
15. contribution
1) context-orientation in Aggregate Computing
2) potential synergies between Context-Oriented (COP)
and Aggregate Programming (AP)
– AP for COP
– COP for AP
R. Casadei Introduction COP AP AP + COP Wrap-up 5/17
16. Outline
1 Introduction
2 Context-Oriented Programming (COP)
3 Aggregate Programming
4 Programming Context-aware Systems: AP & COP
5 Wrap-up
R. Casadei Introduction COP AP AP + COP Wrap-up 6/17
18. ctx-oriented programming (COP) [5, 4]
ctx-aware system development as linguistic problem
abstractions for adaptation modularization
– layer
abstractions for dynamic de/activation of layers
– dynamically scoped activation, implicit activation...
R. Casadei Introduction COP AP AP + COP Wrap-up 7/17
19. ctx-oriented programming (COP) [5, 4]
ctx-aware system development as linguistic problem
abstractions for adaptation modularization
– layer
abstractions for dynamic de/activation of layers
– dynamically scoped activation, implicit activation...
R. Casadei Introduction COP AP AP + COP Wrap-up 7/17
20. ctx-oriented programming (COP) [5, 4]
ctx-aware system development as linguistic problem
abstractions for adaptation modularization
– layer
abstractions for dynamic de/activation of layers
– dynamically scoped activation, implicit activation...
R. Casadei Introduction COP AP AP + COP Wrap-up 7/17
21. ctx-oriented programming (COP) [5, 4]
class Storage<K,V> {
V getItem(K key){ println("Lookup."); /*...*/ return result; }
layer logLayer {
print("Logging.")
V getItem(K key){ log("..."); return proceed(); }
}
layer cacheLayer {
print("Cache.")
V getItem(K key){ /*..*/ return res!=null ? res : proceed(); }
}
}
Storage s = new Storage<String,String>();
s.getItem("foo"); // Lookup.
with(cacheLayer){ s.getItem("foo"); } // Cache. Lookup.
with(cacheLayer,logLayer){
s.getItem("foo"); } // Logging. Cache. Lookup.
R. Casadei Introduction COP AP AP + COP Wrap-up 7/17
22. Outline
1 Introduction
2 Context-Oriented Programming (COP)
3 Aggregate Programming
4 Programming Context-aware Systems: AP & COP
5 Wrap-up
R. Casadei Introduction COP AP AP + COP Wrap-up 8/17
23. Background » Aggregate Programming (AP) [2, 6]
Aggregate Computing =
paradigm for programming CASs
formally founded (computational field calculus)
continuous execution of a global program
R. Casadei Introduction COP AP AP + COP Wrap-up 9/17
24. Background » Aggregate Programming (AP) [2, 6]
Aggregate Computing =
paradigm for programming CASs
formally founded (computational field calculus)
continuous execution of a global program
R. Casadei Introduction COP AP AP + COP Wrap-up 9/17
25. Background » Aggregate Programming (AP) [2, 6]
sensors
local functions
actuators
Application
Code
Developer
APIs
Field Calculus
Constructs
Resilient
Coordination
Operators
Device
Capabilities
functions repnbr
TGCfunctions
communication state
PerceptionPerception
summarize
average
regionMax
…
ActionAction StateState
Collective BehaviorCollective Behavior
distanceTo
broadcast
partition
…
timer
lowpass
recentTrue
…
collectivePerception
collectiveSummary
managementRegions
…
Crowd ManagementCrowd Management
dangerousDensity crowdTracking
crowdWarning safeDispersal
restriction
selfstabilisation
R. Casadei Introduction COP AP AP + COP Wrap-up 9/17
26. Background » Aggregate Programming (AP) [2, 6]
AP execution model (protocol)
async rounds of computation
1) full run of “aggregate program” against “local context”
device state
sensor readings
neighbourhood coordination data
2) broadcast coordination data to neighbours
R. Casadei Introduction COP AP AP + COP Wrap-up 9/17
27. Background » Aggregate Programming (AP) [2, 6]
“hello world” example (gradient)
R. Casadei Introduction COP AP AP + COP Wrap-up 9/17
28. Background » Aggregate Programming (AP) [2, 6]
“hello world” example (gradient)
class MyProgram extends AggregateProgram {
override def main = gradient(sense[Boolean]("source"))
def gradient(source: Boolean): Double =
rep(Double.PositiveInfinity)(distance =>
mux(source){
0.0
}{
minHoodPlus( nbr{distance} + metric )))
}
)
}
R. Casadei Introduction COP AP AP + COP Wrap-up 9/17
29. key insight
AP enables convenient definition of distributed,
continuous processes of reification, transformation,
fusion, spreading of contexts
AP intrinsically deals with more that one individual
A) usually to drive collective behaviour (local-to-global), &
B) to locally make sense of what happens around
(global-into-local)
branch(gradient(src) < threshold){
// CONTEXT: near to point-of-interest
}{
// CONTEXT: distant to point-of-interest
}
R. Casadei Introduction COP AP AP + COP Wrap-up 10/17
31. AC for app context management
R. Casadei Introduction COP AP AP + COP Wrap-up 10/17
32. context in aggregate computing
neighbour
coordination
data
sensor data
state
LOCAL
CONTEXT
GLOBAL
CONTEXT
actuation
R. Casadei Introduction COP AP AP + COP Wrap-up 10/17
33. Outline
1 Introduction
2 Context-Oriented Programming (COP)
3 Aggregate Programming
4 Programming Context-aware Systems: AP & COP
5 Wrap-up
R. Casadei Introduction COP AP AP + COP Wrap-up 11/17
34. AC for COP: programming the context
R. Casadei Introduction COP AP AP + COP Wrap-up 12/17
35. AC for COP: programming the context
COP assumes context is already here
AC enables progressive construction and
propagation of context
– to drive activation of layers
R. Casadei Introduction COP AP AP + COP Wrap-up 12/17
36. AC for COP: programming the context
COP assumes context is already here
AC enables progressive construction and
propagation of context
– to drive activation of layers
R. Casadei Introduction COP AP AP + COP Wrap-up 12/17
37. AC for COP: programming the context
R. Casadei Introduction COP AP AP + COP Wrap-up 12/17
38. COP for AP
R. Casadei Introduction COP AP AP + COP Wrap-up 13/17
39. COP for AP
layers to modularise alternative collective behaviours
– mainly an aid for code organisation
Ǧ e.g., concrete gradient impl based on system dynamics
R. Casadei Introduction COP AP AP + COP Wrap-up 13/17
40. COP for AP
layers to modularise alternative collective behaviours
– mainly an aid for code organisation
Ǧ e.g., concrete gradient impl based on system dynamics
R. Casadei Introduction COP AP AP + COP Wrap-up 13/17
41. COP for AP
class AggregateProgram with Layers {
/* Layer definitions */
layer("HighMobility"){
_.replace("Gradient"){ ULTg /* see[1] */ }
.after("FunctionXXX") { /* side computation */ }
}.on { /* collective estimation of mobility */ }
/* Layered functions */
def gradient(source: Boolean): Double =
layered("Gradient"){
classicGradient(source) // most basic impl
}
def main() = { // program entry point
val leaders = S(grain)
val g = gradient(leaders) // ctx-sensitive
val data = C(g, events) // collect into leaders
// ...
}
}
R. Casadei Introduction COP AP AP + COP Wrap-up 13/17
42. COP for AP
issues
1) basic HFC cannot align dynamic computations
HFC extended as per [3]
2) devices executing different gradient algorithms cannot
interact!
border nodes must run both algorithms and bridge
values
R. Casadei Introduction COP AP AP + COP Wrap-up 13/17
43. more on context & AC: aggregate
processes
dynamic, concurrent aggregate computations
see COORD’19 paper [3]
context-oriented lifecycle management
R. Casadei Introduction COP AP AP + COP Wrap-up 14/17
44. more on context & AC: aggregate
processes
dynamic, concurrent aggregate computations
see COORD’19 paper [3]
context-oriented lifecycle management
R. Casadei Introduction COP AP AP + COP Wrap-up 14/17
45. more on context & AC: aggregate
processes
dynamic, concurrent aggregate computations
see COORD’19 paper [3]
context-oriented lifecycle management
R. Casadei Introduction COP AP AP + COP Wrap-up 14/17
46. Outline
1 Introduction
2 Context-Oriented Programming (COP)
3 Aggregate Programming
4 Programming Context-aware Systems: AP & COP
5 Wrap-up
R. Casadei Introduction COP AP AP + COP Wrap-up 15/17
47. key points
AP is for distributed, continuous processes of
transformation, fusion, spreading of contexts
contextual fields in AP can feed COP modules
AP DSLs can be extended with COP-like features
future work
systematic review on context-orientation in CAS
extend this work with more on AP+COP mixing
R. Casadei Introduction COP AP AP + COP Wrap-up 16/17
48. References (1/1)
[1] Giorgio Audrito et al. “Compositional blocks for optimal self-healing gradients”. In: Conf. on
Self-Adaptive and Self-Organizing Systems (SASO). IEEE. 2017, pp. 91–100.
[2] Jacob Beal, Danilo Pianini, and Mirko Viroli. “Aggregate Programming for the Internet of Things”. In:
IEEE Computer (2015). ISSN: 1364-503X.
[3] Roberto Casadei et al. “Aggregate Processes in Field Calculus”. In: International Conference on
Coordination Languages and Models. Springer. 2019, pp. 200–217.
[4] Pascal Costanza and Robert Hirschfeld. “Language constructs for context-oriented programming: an
overview of ContextL”. In: Proceedings of the 2005 symposium on Dynamic languages. ACM. 2005,
pp. 1–10.
[5] Guido Salvaneschi, Carlo Ghezzi, and Matteo Pradella. “Context-oriented programming: A software
engineering perspective”. In: Journal of Systems and Software 85.8 (2012), pp. 1801–1817. ISSN:
01641212. DOI: 10.1016/j.jss.2012.03.024. URL:
http://dx.doi.org/10.1016/j.jss.2012.03.024.
[6] Mirko Viroli et al. “From Field-Based Coordination to Aggregate Computing”. In: Int. Conf. on
Coordination Languages and Models. Springer. 2018, pp. 252–279.
R. Casadei Appendix References 17/17