Download presentation
Presentation is loading. Please wait.
Published byMagnus Black Modified over 9 years ago
2
Reo A Calculus for Composition of Connectors (taken from slides of Farhad Arbab)
3
Reo Reo is based on a calculus for compositional construction of component connectors. Both components and connectors in Reo are distributed and mobile. Reo connectors are dynamically reconfigurable.
4
Channels Atomic connectors in Reo are called channels. A channel is defined as a binary relationship between two timed-data streams. Channel in Reo is a generalization of its common notion: –Always has two ends –Two types of channel ends Source: data enters into the channel Sink: data leaves the channel –A channel can have two sources or two sinks
5
A Sample of Channels Synchronous channel –write/take Synchronous drain: two sources –write/write Synchronous spout: two sinks –take/take Lossy synchronous channel Asynchronous FIFO1 channel –write/take
6
Flow through –Merge + replication combo Non-deterministic merge Replication Join a b a c c b a bc
7
!x? ? ? ac b Regulated Reads (TC) With a synchronous channel on b, takes from c produce successive values of a. Values pass through the junction only whenever something is taken from b. A take from b, then, is the cue for the completion of a write-take pair on a and c. We express this as c = (b:a)*. Symmetrically, we have b = (c:a)*. !xx x
8
Regulated Reads (WC) With a synchronous drain, takes from c produce successive values of a. Values pass through the junction only whenever something is written to b. A write on b, then, is the cue for the completion of a write-take pair on a and c. We express this as c = (b/a)*. ac b
9
Flow Synchronization If all channels are synchronous, takes from c and d are synchronized: barrier synchronization. If only the drain is asynchronous, no simultaneous takes are possible on c and d. a b c d !x ? ? ? !y ? ? x y
10
!1 !2 ? 2 1!3 !42 1!1 !2 Order a And b Subsequent takes from c retrieve the elements of the stream (ab)* Both a and b must be present before a pair can go through. a b c 4,3,2,1 4 ?3,2,1 4 !3 !4 ?2,1!3 !4 2,1!3 !42 ?1!3 2 1
11
Order a, b, And c Subsequent takes from z retrieve the elements of the stream (abc)* All three must be present before a triplet can go through. a b c z
12
Take a when b or c A take from d succeeds only if there is a value written to b or c. The values taken from d are elements of the stream a* We have d = ((b|c)/a)* a bc d
13
ab c d Sequencer Writes to a, b, c, and d will succeed cyclically and in that order. o !1 oo !2 o !3!1!2 o !1!2 o o !4!2 o o
14
Another c = (ab)* An a can pass through even if its pairing b is not yet available. sequencer b a c
15
c = (aab)* sequencer b a c
16
Inhibitor All values flow from d to c until a value is written to i. A write to i inhibits (i.e., blocks) further writes to both d and i. o dc i
17
C = a* | b* The drain is asynchronous; dashed arrows show synchronous lossy channels; all other channels are synchronous. Inhibitor 2 d i b a Inhibitor 1 i d c
18
Asynchronous Drain z An AsyncDrain can be composed out of a SyncDrain and 3 (or 2) Sync channels.
19
Exclusive Router A value written to a flows through to either b or c, but never to both. a b c
20
Inclusive Router A value written to a flows through to either b or c, or to both. a bc
21
Overflow Lossy FIFO1 z A FIFO1 channel that accepts but loses new incoming values if its buffer is full.
22
Shift Lossy FIFO1 A FIFO1 channel that loses its old buffer contents, if necessary, to make room for new incoming values. o XRouter
23
Sequencer With Reset Same as a simple sequencer, except that a write to reset forces the sequencer to start over with a. XRouter o d c b a reset
24
NS Ticket Vending Machine
25
Ticket Machine Components We assume the following components are available: –Destination: Get user’s destination code –Type: Get user’s ticket type –Price: Find the price of the ticket –Payment: Handle user’s payment –Print: Print and dispense the ticket –Clock: Periodically emit date and time –Cancel: Produce a token whenever Cancel is pressed
26
Get-Destination Component Destination has two input and one output ports: –trigger: input –cancel: input –dest: output When triggered by a token on its trigger port, it: –interacts with the user through numeric keypad (2) and display to obtain the destination code –produces the destination code on its dest port –A token on its cancel port resets the component
27
Get-Type Component Type has two input and one output ports: –trigger: input –cancel: input –type: output When triggered by a token on its trigger port, it: –interacts with the user through special keypad (3) to obtain the ticket type –produces the ticket type code on its type port –A token on its cancel port resets the component
28
Lookup-Price Component Price has 4 input and one output ports: –here: input –dest: input –type: input –time: input –price: output When all of its input ports have values, it –looks up the price if the specified ticket in its database –produces the ticket price on its price port
29
Payment Component Payment has two input and two output ports: –price: input –cancel: input –yes: output –no: output When triggered by a value on its price port, it: –interacts with the user to obtain the proper payment –produces a token on its yes or no port to indicate whether the full payment was made or not –A token on its cancel port resets the component
30
Print Component Print has 6 input and one output ports: –here: input –dest: input –type: input –time: input –price: input –done: output When all of its input ports have values, it –Prints and dispenses the ticket –produces a token on its done port
31
Ticket Machine Composition Here XRouter Print Payment Price Clock Type Destination XRouter Cancel Sequencer with Reset
32
Reo A compositional paradigm for coordination of mobile components, based on mobile channels. Provides a set of operations for components to: –Create and compose channels into complex connectors. –Perform I/O operations on connectors, as a result of which the participating components are coordinated. –The semantics of connectors are independent of components.
33
Beyond Channels createconnectdisconnectreadtakewritewaitforgetmovejoinsplit _create_connect_disconnect_read_take_write_wait_forget Reo Component instances Channels Channels and Channel-ends Nodes and Connectors _move hide
34
Common Behavior All channels in Reo must implement the following set of operations with the “same” semantics: Simple topological operations –Dynamic channel creation and (dis)connection of channel ends from/to component instances. Input/Output operations –Reading/writing of data items from/to channel ends. Inquiry operations –Checking for conditions of interest.
35
Topological Operations –_create(type [, filter]) Returns a pair of channel ends for a new channel of the specified type with its associated filter. –_connect([t,] cev) Waits (indefinitely or for the specified time-out, t) to connect the specified channel end, cev, to the component instance. –_disconnect(cev) Disconnects the specified channel end, cev, from the component instance. –_forget(cev) The component performing this operation loses all its references to the specified channel end, cev.
36
Input/Output Operations –_read([t,] inp[, v [, pat]]) Suspends the active entity that performs it (indefinitely or for the specified time-out, t) waiting for a value (that matches with pat) to become available for reading from the sink channel end inp into the variable v. The value item is not removed from the channel. –_take([t,] inp[, v [, pat]]) Removes a value from inp and behaves analogous to read. –_write([t,] outp, v) Suspends the active entity that performs it (indefinitely or for the specified time-out, t) until it succeeds to write the contents of the variable v into the source channel end outp.
37
Inquiry Operations –_wait([t,] conds) Suspends the active entity that performs it (indefinitely or for the specified time-out, t) waiting for the specified conditions to become true. The argument conds is a boolean combination of a set of predefined primitive wait conditions on a channel end, cev, which includes: –connected(cev) –disconnected(cev) –empty(cev) –full(cev) –etc.
38
Connectors A connector consists of a set of channels organized in a graph of nodes and edges where: –Zero or more channel ends coincide on every node. –There is an edge between two (not necessarily distinct) nodes iff there is a channel whose ends coincide on those nodes. Every channel “is” a (simple) connector.
39
Node Types A node is called a –source node, if it has no coincident sink channel ends. –sink node, if it has no coincident source channel ends. –mixed node, otherwise.
40
Node Operations The Reo operations on nodes can be divided into three categories: –Topological and inquiry operations –I/O operations –Composition and abstraction operations
41
Node Topology Operations Reo defines the following topological operations on a node N: create(type [, filter]) –Performs a _create(type [, filter]) and returns a pair of nodes for the resulting channels ends. connect([t,] N) –If N is not a mixed node, atomically performs _connect([t,] x),. disconnect(N) –Atomically performs _disconnect([t,] x),. forget(N) –Atomically performs _forget([t,] x),.
42
Node Inquiry Operations –wait([t,] nconds) Suspends the active entity that performs it (indefinitely or for the specified time-out, t) waiting for the specified conditions to become true. The argument nconds is a boolean combination of a set of predefined primitive wait conditions on nodes: –connected(N), connectedAll(N) –disconnected(N), disconnectedAll(N) –empty(N), emptyAll(N) –full(N), fullAll(N) –etc.
43
Node I/O Operations –read([t,] N[, v [, pat]]) If N is a sink node connected to the component instance performing this operation, this operation succeeds when a value compatible with pat is non-deterministically read from some channel end into the variable v. –take([t,] N[, v [, pat]]) Similar to read, but the value is also removed from the channel. –write([t,] N, v) If N is a source node connected to the component instance performing this operation, this operation succeeds when a copy of the value in v is written to every channel end.
44
Node Composition join(N1, N2) –If at least one of the nodes N1 and N2 is connected to the component instance performing this operation, it produces a new node that results from the destructive merge of N1 and N2. split(N[, quoin]) –Produces a new node N’ and splits the channels ends that coincide on N between N and N’. hide(N) –Hides the node N such that it cannot be used in any other node operation.
45
Writing to a Node A write(t, N, d) where, remains pending on the node N until either: –Its time-out expires; or –accepts(N,d) becomes true, and: the set of operations _write(0, xc, d), for all channel ends for which takes(xc, d) is true, is performed atomically.
46
Taking from a Node A take(t, N, v, p) remains pending on the node N until either: –Its time-out expires; or – and: a channel end is selected non- deterministically such that and the operation _take(0, x, v, p) is performed.
47
Semantics of Mixed Nodes Mixed nodes cannot be connected to components. No read, take, or write operations can be performed on mixed nodes. A mixed node automatically transfers all eligible data items from its coincident sinks to its coincident sources. The multi-set of data items that are eligible for transfer at a mixed node is defined as:
48
Flow Through Mixed Nodes while (true) do suspend until for each do select a _take(0, y, v, d) for each do if (takes(x, d)) then _write(0, x, d) done
49
Summary of Reo Reo is a powerful expressive coordination language. Complex connectors can be built compositionally out of simpler ones. Semantics of connectors is independent of the components/entities that use them. Mobility (of components and connectors) is inherent and implicit in Reo.
50
Conclusion Components are necessary –To overcome the shortcomings of OO –To capture the meaning of (stronger) encapsulation Two directions –Fortified objects (Extension of) existing technology Method invocation inhibits strong decoupling –Abstract Behavioral Types Real loose coupling Exogenous coordination Requires new channel-based programming styles
51
Washing Machine Interface
52
Behavior of Buttons Successively pressing the Program button (3) cycles through the following choices: –Cotton; Color; Synthetic; Delicate; Wool; Quick; Rinse & Spin; Spin Successively pressing the Options button (4) cycles through the following choices: –Eco+; Rinse+; Pre-wash; [no-choice] Successively pressing the Spin button (5) cycles through the following choices: –No Spin; Rinse & Hold; [no-choice] Successively pressing the Temp button (6) cycles through 5 different choices for the temperature setting. Successively pressing the Delay Start button (7) cycles through 25 different choices (1-24 plus 0) for the delay setting. Pressing the Start (8) button takes the current values of all choices and starts the (Pre-wash, Wash, Rinse, Spin) cycle they specify.
53
Exercise I Implement in Java asynchronous communication between threads via unbounded FIFO buffers. Provide also a means to initialize these buffers.
54
Exercise II Let a Java component be a package with two special static classes IChn and OChn which declare by means of static attributes a collection of input and output channels, respectively. Discuss possible forms of encapsulation and the corresponding techniques to enforce them.
55
Exercise III Define a Java component Merger with a class IChn declaring two asynchronous input channels in1, in2, and a class OChn declaring a single asynchronous output channel out. The component reads non-deterministically from the input channels in1 and in2 and outputs these values along its output channel out in the original order.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.