Towards a Decoupled Context-Oriented Programming Language for the Internet of Things

Baptiste Maingret, Frédéric Le Mouël, Julien Ponge, Nicolas Stouls, Jian Cao, Yannick Loiseau

TL;DR

This paper introduces Congolo, an extension of the Golo programming language designed to decouple context tracking from decision-making in Context-Oriented Programming (COP). By separating what the environment is doing from how the application should adapt, the authors enable more flexible, externalized logic—such as machine learning models—to drive software behavior in dynamic Internet of Things (IoT) environments.

What Problem Does This Paper Address?

In the Internet of Things, devices must constantly adapt to changing environments (e.g., low battery, moving locations, or varying network quality). Context-Oriented Programming (COP) is a paradigm designed for this, allowing software to swap "layers" of behavior based on the current context.

However, the authors identify a major limitation in existing COP languages: they typically bake the decision logic (e.g., "if battery < 10%, use low-power mode") directly into the application code. This tight coupling makes it difficult to use sophisticated decision-making tools like neural networks or to offload complex logic to more powerful edge servers. The authors aim to "decouple" these concerns so that the business logic remains clean while the adaptation logic can be managed independently.

Methods

The authors propose a decoupled architecture and implement it via Congolo, a contextual extension of Golo (a dynamic JVM-based language). Key technical components include:

  • Two-Level Context Management: They distinguish between concrete values (raw data like battery percentage) and meta-values (abstract states like "Low Battery").
  • External Decision Makers: Instead of hard-coded rules, Congolo allows an external "Decision Maker" (which could be a simple script or a complex AI) to receive context events and decide which code layers to activate.
  • Event-Based Interconnection: The system uses an asynchronous, hierarchical messaging system to link function calls to the decision-making process.
  • JVM Optimization: The implementation leverages the invokedynamic bytecode instruction to handle the late binding of contextual methods, allowing the language to swap behaviors at runtime.
  • Grammar Extensions: They modified the Golo grammar to support new keywords for declaring contexts and defining "layered" functions that only trigger under specific conditions.

Datasets

As this is a programming language design paper rather than a data science paper, no traditional training datasets were used. To evaluate performance, the authors used the Java Microbenchmark Harness (JMH). They compared standard Golo against Congolo across two scenarios:

  1. Single invocation: Calling a standard function vs. a contextual one.
  2. Layered invocation: Testing the overhead when a function is wrapped in 10 different contextual layers.

Key Insights and Ideas

  • Separation of Concerns: By treating the "Decision Maker" as a black box accessible via an API, developers can swap out simple "if-then" logic for complex machine learning models without rewriting the core application.
  • The "Aha" Moment on Latency: The authors realize that while their decoupled approach adds significant overhead, IoT environments often involve "stable physical phenomena." If a context (like "at home") only changes every few minutes, the millisecond-scale overhead of a decoupled lookup is negligible compared to the benefit of flexibility.
  • Meta-Value Abstraction: Using meta-values allows the business logic to remain agnostic of the specific sensors providing the data, making the code more portable across different IoT hardware.

Key Results

The quantitative results highlight a significant performance trade-off for this flexibility:

  • Performance Hit: In the initial prototype, Congolo was significantly slower than standard Golo. For a single invocation, Golo achieved ~6,135 operations per millisecond, while Congolo managed only ~29.
  • Layering Overhead: With 10 layers of behavior, Congolo's performance dropped to 1.9 ops/ms compared to Golo's 3,998.
  • Messaging Bottleneck: The authors found that the event-based messaging system was the primary bottleneck. By switching to direct calls to the Decision Maker, they nearly doubled performance (from 29 to 55 ops/ms), though it remained well below native speeds.
  • Feasibility: Despite the slow benchmarks, the authors argue that 30 function calls per millisecond is more than enough for most IoT adaptation needs.

Limitations and Future Work

The primary limitation is execution speed. The current implementation lacks the caching mechanisms found in more mature COP languages, meaning every contextual call triggers a full lookup/messaging cycle.

Future Work includes: * Caching: Implementing "branching decision caching" to avoid re-consulting the Decision Maker if the context hasn't changed. * Multi-threading: Improving the messaging system to support multi-threaded dispatching. * High-level Composition: Exploring how multiple independent Decision Makers can collaborate to control a single application.

Summary updated

Abstract

Easily programming behaviors is one major issue of a large and reconfigurable deployment in the Internet of Things. Such kind of devices often requires to externalize part of their behavior such as the sensing, the data aggregation or the code offloading. Most existing context-oriented programming languages integrate in the same class or close layers the whole behavior. We propose to abstract and separate the context tracking from the decision process, and to use event-based handlers to interconnect them. We keep a very easy declarative and non-layered programming model. We illustrate by defining an extension to Golo-a JVM-based dynamic language.
BibTeX
@inproceedings{maingret2015towards,
  author = {Baptiste Maingret and Frédéric Le Mouël and Julien Ponge and Nicolas Stouls and Jian Cao and Yannick Loiseau},
  title = {{Towards a Decoupled Context-Oriented Programming Language for the Internet of Things}},
  booktitle = {COP@ECOOP},
  year = {2015},
  url = {https://openreview.net/forum?id=IIG9FWTfFK},
}

Loading related content...

Figure