Reactors: A data-oriented synchronous/asynchronous programming model for distributed applications

John Field, Maria-Cristina Marinescu, Christian Stefansen
2009 Theoretical Computer Science  
Our aim is to define the kernel of a simple and uniform programming model -the reactor model -which can serve as a foundation for building and evolving internet-scale programs. Such programs are characterized by collections of loosely-coupled distributed components that are assembled on the fly to produce a composite application. A reactor consists of two principal components: mutable state, in the form of a fixed collection of relations, and code, in the form of a fixed collection of rules in
more » ... he style of Datalog. A reactor's code is executed in response to an external stimulus, which takes the form of an attempted update to the reactor's state. As in classical process calculi, the reactor model accommodates collections of distributed, concurrently executing processes. However, unlike classical process calculi, our observable behaviors are sequences of states, rather than sequences of messages. Similarly, the interface to a reactor is simply its state, rather than a collection of message channels, ports, or methods. One novel feature of our model is the ability to compose behaviors both synchronously and asynchronously. Also, our use of Datalog-style rules allows aspect-like composition of separately-specified functional concerns in a natural way. a single language: (1) data, rather than ports or channels as the interface to a component; (2) synchronous and asynchronous interaction in the same model, with the ability to generate processes dynamically; (3) expressive data query and transformation constructs; (4) the ability to specify constraints/assertions as a natural part of the core language; (5) distributed atomic transactions; and (6) declarative, compositional specification of functionality in an "aspect-like" manner. We believe that Internet components can be developed more productively and composed more readily when these attributes are provided in a single programming model. This paper is an updated and extended version of [8] . This version fills in many semantic details absent from the earlier version, corrects errors, and adds additional examples. Reactor basics A reactor consists of a collection of relations and rules, which together constitute a reactive, atomic, stateful unit of distribution. The full reactor syntax is given in Fig. 1 . Consider the declaration for OrderEntryA in Fig. 2. OrderEntryA defines a class of reactors that are intended to log orders-say, for an on-line catalog application. Reactor instances are created dynamically, using a mechanism we will describe in Section 3.2. The state of a reactor is embodied in a fixed collection of persistent relations. Relations are sets of (τ 1 , . . . , τ n ) tuples, where each τ i is one of the types int, string, or ref reactor-type-name. The primitive types have the usual meanings. Reactor references, of the form ref reactor-type-name, are described in Section 3.2. Relations are empty when a reactor is instantiated. In addition to persistent relations, whose values persist between reactions, a reactor can declare ephemeral relations. These relations are written and read in the same manner as persistent relations, but they are re-initialized as empty with every reaction.
doi:10.1016/j.tcs.2008.09.052 fatcat:gts74gv6snbhvorstl3mxzjqhi