Upload
orien
View
25
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Component Composition: Reo. Composition. Composition of “black-box” component instances into a (sub)system is realized by some “glue-code” connectors that: Enable inter-component instance communication. Enforce exogenous coordination patterns. - PowerPoint PPT Presentation
Citation preview
Component Composition: Reo
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 2
Composition
Composition of “black-box” component instances into a (sub)system is realized by some “glue-code” connectors that:Enable inter-component instance
communication.Enforce exogenous coordination patterns.Have well-defined semantics independent of
component instances.Are themselves compositionally constructed
out of simpler connectors.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 3
Ordering of Writers
Example of coordinated composition:Glue these three component instances
together such that R alternately reads items produced by W1 and W2.
A system consists of three component instances: two writers, W1 and W2, and a reader, R.
R
W1 W2
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 4
Method Invocation
Message passing in OO invokes a method to perform an ADT operation.
The semantics of method invocation is heavy and non-trivial:The caller must know the callee.The caller must know the method.The callee must (pretend) to interpret the message.The caller suspends while the callee (pretends to)
perform the method.The caller resumes when the callee returns a result.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 5
Operational Interface
The operations/methods provided by an ADT/class-interface impose a tight semantic binding.
The resulting relationship among subjects and objects of operations is sometimes desirable among intra-component entities.
At the inter-component level, this relationship Weaken independence of components.Contributes to breaking of encapsulation.Tightens component inter-dependence.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 6
Components OO Style
Components are fortified (collections of) objects.
Inter-component communication is through messages that invoke remote methods.
Messages may be intercepted by connectors to:Provide services (e.g., binding and name servers)Enforce imposed constraintsEnsure protocolsPerform assigned roles
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 7
Passive Messages
Message passing without the method invocation semantics is a more abstract and more flexible mechanism.The sender does not suspend waiting for a
result.The receiver need not interpret the
message as an operation it must perform.The receiver is not obligated to reply.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 8
Message Passing
Whether messages are active or passive, the send primitive is inherently targeted.The knowledge of who the receiver is, or how it can
be identified, is contained in the sender.This makes the sender semantically
dependent on (the scheme used to identify) the receiver.
This semantic dependency weakens exogenous coordination.Third parties cannot coordinate interactions
between senders and receivers of their own choice.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 9
Anonymous Communication
Entities that communicate with each other need not know each other.
An entity exchanges identifiable sequences of passive messages with its environment only.
Inherently amenable to exogenous coordination.
Highly flexible composition possibilities.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 10
Behavior
Operations only indirectly, implicitly, and reactively represent behavior.
Behavior can be represented, e.g., as:Sequences of operationsSequences of state charts Input/output relationships
Operation sequences are too concrete and too detailed representation of behavior.
Input/output relationships more directly and abstractly represent behavior.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 11
Abstract Behavior Type
An ABT defines an abstract behavior without specifying any detail about:the operations that may be used to
implement such behavior.the data types they may manipulate for
its realization.An ABT is a (maximal) relation
among a set of timed-data-streams.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 12
Connectors
Connectors comprise the “glue code” that makes components interact. Enforce policies Mediate interactions Coordinate activities
Currently, glue code is the most rigid, component specific, and special purpose software in component based systems.
Wish list: No programming Well-defined semantics, independent of components Compositional connectors
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 13
ABT Implementation
The implementation of an ABT is a set of process specifications
Its instantiation is a set of processes communicating with the environment only through read and write operations on the channel ends according to the behavior specified by the ABT
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 14
Mobile Channels
Mobile channelsThe identity of a channel end can be passed
around as any data item, and be known to many ABT instances
The connection of a channel end can move from one component instance to another, without affecting the knowledge of the other end of the same channel
Why?To describe dynamic interfacesTo describe dynamic networks of communicating
ABT instances
Reo A Calculus for Composition of Connectors
Mobile channels as primitive connectorsConstruction of complex connectorsSemantic independence of connectorsExpressiveness of compositionVisual composition
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 16
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. Both components and connectors are uniformly
represented as ABTs. A component is any general ABT. A connector is any ABT that can be constructed out of a
user-defined set of primitive connectors (channels). [Dynamic Kahn networks, mobile channels, Broy’s timed dataflow]
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 17
Channels
Atomic connectors in Reo are called channels.A channel is an ABT defined as a binary
relationship between two timed-data streams.Channel in Reo is a generalization of its
common notion:Always has two endsTwo types of channel ends
Source: data enters into the channel Sink: data leaves the channel
A channel can have two sources or two sinks
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 18
A Sample of Channels
Synchronous channelwrite/take
Synchronous drain: two sourceswrite/write
Synchronous spout: two sinks take/take
Lossy synchronous channel
Asynchronous FIFO1 channelwrite/take , 1 ,a fifo b a b a
(0) ( , , ) (0) (0) (1)
, , ( , , ) ( , , )( , , )
L a b if b a b
a synloss b L a b L a bL a b otherwise
, ,a synsp b a b
, ,a syndr b a b
, ,a sync b a b
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 19
Flow throughMerge + replication combo
Non-deterministic merge
Replication
Join
a
b
a
c
c
b
a
b c
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 20
!x ?!x ?
?
a c
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)*.
!x x
x
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 21
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)*.a c
b
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 22
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!x ?!x ?
?
!x
!y
?
?
x
y
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 23
!1
!2
?
2
1!3
!4 2
1!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
c4,3,2,1
4
? 3,2,1
4
3,2,1!3
!4
? 2,1!3
!4
2,1!3
!4 2
? 1!3
2
1
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 24
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
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 25
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
b c
d
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 26
a b c d
Sequencer
Writes to a, b, c, and d will succeed cyclically and in that order.
o
!1
oo
!1 !2
o
!3 !1 !2
o
!1 !2
o
!2
o
!4 !2
o
!2
o
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 27
Expressiveness
What ABTs can be produced by composition of a given set of channels?With a small set of 5 channel types, the
equivalent of regular expressions can be constructed.
Turing equivalence is possible with the above set of channel types, plus unbounded FIFO.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 28
Another c = (ab)*
An a can pass through even if its pairing b is not yet available.
sequencer
b
a
c
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 29
c = (aab)*
sequencer
b
a
c
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 30
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
d c
i
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 31
C = a* | b*
The drain is asynchronous; dashed arrows show synchronous lossy channels; all other channels are synchronous.
Inhibitor 2
d
i
b
aInhibitor 1
i
d
c
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 32
Asynchronous Drain
An AsyncDrain can be composed out of a SyncDrain and 3 (or 2) Sync channels.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 33
Exclusive Router
A value written to a flows through to either b or c, but never to both.
a
b c
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 34
Inclusive Router
A value written to a flows through to either b or c, or to both.
a
b c
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 35
Overflow Lossy FIFO1
A FIFO1 channel that accepts but loses new incoming values if its buffer is full.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 36
Shift Lossy FIFO1
A FIFO1 channel that loses its old buffer contents, if necessary, to make room for new incoming values.
o
XRouter
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 37
Sequencer With Reset
Same as a simple sequencer, except that a write to reset forces the sequencer to start over with a.
XRoutero XRouter XRouter
XRouter
dcba
reset
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 38
NS Ticket Vending Machine
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 39
Ticket Machine Components
We assume the following components are available:Destination: Get user’s destination codeType: Get user’s ticket typePrice: Find the price of the ticketPayment: Handle user’s paymentPrint: Print and dispense the ticketClock: Periodically emit date and timeCancel: Produce a token whenever Cancel is
pressed
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 40
Get-Destination Component
Destination has two input and one output ports: trigger: inputcancel: inputdest: 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 codeproduces the destination code on its dest portA token on its cancel port resets the component
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 41
Get-Type Component
Type has two input and one output ports: trigger: inputcancel: 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 typeproduces the ticket type code on its type portA token on its cancel port resets the component
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 42
Lookup-Price Component
Price has 4 input and one output ports:here: inputdest: input type: input time: inputprice: 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
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 43
Payment Component
Payment has two input and two output ports:price: inputcancel: inputyes: outputno: output
When triggered by a value on its price port, it: interacts with the user to obtain the proper
paymentproduces 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
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 44
Print Component
Print has 6 input and one output ports:here: inputdest: input type: input time: inputprice: inputdone: output
When all of its input ports have values, it Prints and dispenses the ticket produces a token on its done port
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 45
Ticket Machine Composition
Here
XRouter
PrintPaymentPrice
Clock
Type
Destination
XRouter
Cancel
Sequencer with Reset
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 46
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.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 47
Beyond Channels
create connect disconnect read take write waitforget move join split
_create _connect _disconnect _read _take _write _wait_forget
Reo
Component instances
Channels
Channels and Channel-ends
Nodes and Connectors
_move
hide
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 48
Common Behavior
All channels in Reo must implement the following set of operations with the “same” semantics:
Simple topological operationsDynamic channel creation and (dis)connection of
channel ends from/to component instances.
Input/Output operationsReading/writing of data items from/to channel ends.
Inquiry operationsChecking for conditions of interest.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 49
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.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 50
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.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 51
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.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 52
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.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 53
Node Types
A node is called asource node, if it has no coincident sink
channel ends.sink node, if it has no coincident source
channel ends.mixed node, otherwise.
N
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 54
Node Operations
The Reo operations on nodes can be divided into three categories:Topological and inquiry operationsI/O operationsComposition and abstraction operations
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 55
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), .
x N
x N
x N
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 56
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.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 57
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 .
x N
x N
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 58
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.
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 59
Writing to a Node
A write(t, N, d) where , remains pending on the node N until either:Its time-out expires; oraccepts(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.
0 t
( )cx Src N
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 60
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.
( ) such that ( , )d offers N match d p ( )cx Snk N
( )d offers x
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 61
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: ( ) | ( ) ( , )N d d offers N accepts N d
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 62
Flow Through Mixed Nodes
while (true) dosuspend untilfor each do
select a _take(0, y, v, d)for each do
if (takes(x, d)) then _write(0, x, d)done
donedone
( )N
( )d N
such that ( )y N d offers y
( )x Src N
© Arbab, de Boer, Bonsangue O2C: From Objects to Components 63
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.