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

Abstract

Easily programming behaviors is one major issue of a large and reconfigurable deployment in the Internet of Things (IoT). Such devices often require externalizing parts of their behavior, such as sensing, data aggregation, or code offloading. Most existing context-oriented programming (COP) languages integrate the entire behavior within the same class or closely coupled layers. We propose to abstract and separate context tracking from the decision process using event-based handlers for interconnection. This approach maintains a simple declarative and non-layered programming model. We illustrate this by defining Congolo, an extension to Golo, a JVM-based dynamic language.

Introduction

In the Internet of Things, devices must constantly adapt to volatile environments, responding to factors like low battery levels, changing physical locations, or fluctuating network quality. Context-Oriented Programming (COP) is a paradigm designed for such dynamism, allowing software to swap "layers" of behavior based on the current context.

However, a significant limitation in existing COP languages is the tight coupling of decision logic (e.g., "if battery < 10%, use low-power mode") directly into the application code. This makes it difficult to integrate sophisticated decision-making tools, such as machine learning models, or to offload complex logic to edge servers. Congolo aims to decouple these concerns, keeping business logic clean while managing adaptation logic independently.

Decoupled Architecture and Implementation

The core of Congolo is a decoupled architecture that distinguishes between raw data and abstract states. The system utilizes a Two-Level Context Management strategy: concrete values represent raw sensor data (e.g., battery percentage), while meta-values represent abstract states (e.g., "Low Battery").

The decoupled architecture separates concrete values and method invocations from the meta-value decision process.

Instead of hard-coded rules, Congolo allows an external "Decision Maker"—which can range from a simple script to a complex AI—to receive context events and determine which code layers to activate. This is facilitated by an asynchronous, hierarchical messaging system that links function calls to the decision-making process. To ensure efficiency on the JVM, the implementation leverages the invokedynamic bytecode instruction for late binding of contextual methods, allowing the language to swap behaviors at runtime.

Performance Evaluation

To evaluate the overhead introduced by this decoupling, the authors used the Java Microbenchmark Harness (JMH) to compare standard Golo against Congolo. The benchmarks focused on two scenarios: a single invocation of a contextual function and a "layered" invocation where a function is wrapped in 10 different contextual layers.

Performance benchmarks showing the impact of messaging optimizations on Congolo's execution speed.

The results reveal a significant performance trade-off for this flexibility. In the initial prototype, Congolo was substantially slower than standard Golo. However, by optimizing the event-based messaging system and switching to direct calls to the Decision Maker, performance nearly doubled from 29 to 55 operations per millisecond (nops/ms) for single invocations. While this remains well below native Golo speeds (~5,939 nops/ms), the authors argue that 55 calls per millisecond is sufficient for most IoT adaptation needs, where physical context changes occur on a much slower timescale.

Key Insights and Future Work

By treating the Decision Maker as a black box accessible via an API, developers can swap out simple logic for complex models without rewriting core application code. Furthermore, using meta-values allows business logic to remain agnostic of specific hardware sensors, increasing code portability.

The primary limitation currently is execution speed due to the lack of caching mechanisms; every contextual call triggers a full lookup cycle. Future work will focus on:

  • Branching decision caching to avoid redundant lookups when context is stable.
  • Multi-threading to improve messaging dispatch efficiency.
  • High-level composition to allow multiple independent Decision Makers to collaborate within 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},
}
Figure