Chemical Foundations of Distributed Aspects
Total Page:16
File Type:pdf, Size:1020Kb
Noname manuscript No. (will be inserted by the editor) Chemical Foundations of Distributed Aspects Nicolas Tabareau ⋅ Éric Tanter the date of receipt and acceptance should be inserted later Abstract Distributed applications are challenging to distributed aspect weaving architecture. Finally, we ex- program because they have to deal with a plethora tend the calculus so that aspects can intervene upon of concerns, including synchronization, locality, replica- migration of localities. tion, security and fault tolerance. Aspect-oriented pro- The semantics of the aspect join calculus is given by gramming (AOP) is a paradigm that promotes better a chemical operational semantics. We give a translation modularity by providing means to encapsulate cross- of the aspect join calculus into the core join calculus, cutting concerns in entities called aspects. Over the and prove this translation correct by a bisimilarity ar- last years, a number of distributed aspect-oriented pro- gument. This translation is used to implement Aspect gramming languages and systems have been proposed, JoCaml on top of JoCaml.1 illustrating the benefits of AOP in a distributed setting. Chemical calculi are particularly well-suited to for- mally specify the behavior of concurrent and distributed 1 Introduction systems. The join calculus is a functional name-passing calculus, with both distributed and object-oriented ex- Distributed applications are complex to develop be- tensions. It is used as the basis of concurrency and cause of a plethora of issues related to synchroniza- distribution features in several mainstream languages tion, distribution, and mobility of code and data across like C# (Polyphonic C#, now C!), OCaml (JoCaml), the network. It has been advocated that traditional and Scala Joins. Unsurprisingly, practical programming programming languages do not allow to separate dis- in the join calculus also suffers from modularity issues tribution concerns from standard functional concerns when dealing with crosscutting concerns. in a satisfactory way. For instance, data replication, We propose the Aspect Join Calculus, an aspect- transactions, security, and fault tolerance often crosscut oriented and distributed variant of the join calculus that the business code of a distributed application. Aspect- addresses crosscutting and provides a formal founda- Oriented Programming (AOP) promotes better sepa- tion for distributed AOP. We develop a minimal aspect ration of concerns in software systems by introducing join calculus that allows aspects to advise reactions, aspects for the modular implementation of crosscutting and then extend it in several directions. We show how concerns [24,15]. Indeed, the pointcut/advice mecha- to deal with causal relations in pointcuts and how to nism of AOP provides the facility to intercept the flow support advanced customizable aspect weaving seman- of control when a program reaches certain execution tics. We also provide the foundation for a decentralized points (called join points) and perform new computa- N. Tabareau tion (called advice). The join points of interest are de- Ascola, INRIA, France noted by a predicate called a pointcut. E-mail: [email protected] AOP is frequently used in distributed component É. Tanter infrastructures such as Enterprise Java Beans, appli- PLEIAD Lab, Computer Science Dept (DCC), University of Chile, Chile 1 Implementation available online at: E-mail: [email protected] http://tabareau.fr/aspect_jocaml 2 Nicolas Tabareau, Éric Tanter cation frameworks (such as Spring2) and application In the join calculus, communication channels are servers (such as JBoss3), Recently, there is a growing created together with a set of reaction rules that spec- interest in the use of AOP for Cloud computing [32, ify, once and for all, how messages sent on these names 9], including practical infrastructures such as Cloud- are synchronized and processed. The crosscutting phe- Stack4. In all these cases however, AOP systems do not nomena manifests in programs written in this style, just support the remote definition or application of aspects. as they do in other languages. The reason is that reac- Rather, non-distributed aspects are used to manipulate tions in the join calculus are scoped: it is not possi- distributed infrastructures [39]. ble to define a reaction that consumes messages on ex- To address these limitations, distributed AOP has ternal channels. Therefore, extending a cache process been the focus of several practical developments: JAC [36], with replication implies modifying the cache definition DJcutter [33], QuO’s ASL [14], ReflexD [46], AWED [4, itself. Similarly, establishing alternative migration poli- 5], Lasagne [47], as well as a higher-order procedural cies based on the availability of locations requires in- language with distribution and aspects [45]. These lan- trusively modifying components. guages introduce new concepts for distributed AOP such The Aspect Join Calculus developed in this paper as remote pointcut (advice triggered by remote join addresses crosscutting issues in the join calculus by in- points), distributed advice (advice executed on a re- troducing the possibility to define aspects that can react mote host), migration of aspects, asynchronous and syn- to chemical reactions. In doing so, it provides a formal chronous aspects, distributed control flow, etc. Almost foundation that can be used to understand and describe all these systems are based on Java and RMI in order to the semantics of existing and future distributed aspect promote the role of AOP on commonly-used large-scale languages. We also use it to describe interesting features distributed applications. But the temptation of using that have not (yet) been implemented in practical dis- a rich language to develop interesting applications has tributed AOP systems. the drawback that it makes it almost impossible to de- Section 2 presents the distributed objective join cal- fine the formal semantics of distributed aspects. While culus, which serves as the basis for the aspect join cal- the formal foundations of aspects have been laid out culus. The core of the aspect join calculus is described in the sequential setting [49,12], to date, no theory of in Section 3. In Section 5, we extend the expressive distributed aspects has been developed.5 power of pointcuts with causality, based on a temporal This paper develops the formal foundations of dis- logic. Section 6 describe an extension of the calculus tributed AOP using a chemical calculus, essentially a with different weaving semantics per reaction. The is- variant of the distributed join calculus [17]. The join sue of decentralized aspect weaving is addressed in Sec- calculus is a functional name-passing calculus founded tion 7 by developing the concept of weaving registries. on the chemical abstract machine and implemented in Section 8 shows how to extend the core aspect join cal- several mainstream languages like OCaml [19], C# [6] culus to expose migration of localities as join points. and Scala [21]. Chemical execution engines are also be- Section 9 describes Aspect JoCaml, an implementation ing developed for Cloud computing [37,34]. Due to its of the aspect join calculus on top of JoCaml. The weav- chemical nature, the join calculus is well-suited to de- ing is based on a transformation from the aspect join scribe parallel computation. The explicit treatment of calculus into the core join calculus; the correctness of localities and migration in the distributed join calcu- this translation is given by a bisimilarity proof, in Ap- lus make it possible to express distribution-related con- pendix A. Finally, Section 10 discusses related work and cerns directly. Section 11 concludes. 2 http://www.springsource.org 2 The distributed objective join calculus 3 http://www.jboss.org 4 http://cloudstack.apache.org/ 5 This article builds upon a previous conference publica- We start by presenting a distributed and object-oriented 6 tion [43]. Much of the text has been completely rewritten. The version of the join calculus. This calculus, which we aspect join calculus has been simplified and clarified, in particu- call the distributed objective join calculus, is an origi- lar by removing the type system and the management of classes, nal, slightly adapted combination of an object-oriented because they are orthogonal to the extensions considered in this work. In addition, the technical treatment has been extended version of the join calculus [18] and an explicit notion in many ways: advanced quantification (in particular temporal of location to account explicitly for distribution [16]. pointcuts of Section 5), per-reaction weaving (Section 6), decen- tralized weaving (Section 7), and migration join points (Section 8) 6 There is a good reason why we choose a variant of the join are all new. Finally, an implementation based on JoCaml is pre- calculus with objects; we discuss it later in Section 3.3, once the sented (Section 9) and provided online. basics of aspects in the calculus are established. Chemical Foundations of Distributed Aspects 3 2.1 Message passing and internal states P ∶∶= Processes 0 null process Before going into the details of the distributed objec- x:M message sending obj x D init P in Q object definition tive join calculus, we begin with the example of the = go(H); P migration request object buffer presented in [18]. The basic operation of H[P ] situated process the join calculus is asynchronous message passing and, P & P parallel composition accordingly, the definition of an object describes how D Definitions messages received on some labels can trigger processes. ∶∶= M ▷ P reaction rule For instance, the term D or D disjunction obj r = reply(n) ▷ out:print(n) M ∶∶= Patterns l(v¯) message defines an object that reacts to messages on its own M & M synchronization label reply by sending a message with label print and D ∶∶= Named Definitions content n to an object named out that prints on the x:D object definition terminal. In the definition of an object, the ’▷’ symbol H[D∶ P ] sub-location definition defines a reaction rule that consumes the messages on D or D disjunction void definition its left hand side and produces the messages on its right ⊺ hand side.