Package org.jcsp.plugNplay
Class Plex
java.lang.Object
org.jcsp.plugNplay.Plex
- All Implemented Interfaces:
CSProcess
Fair multiplexes its input Object stream array into one output stream.
Process Diagram
Description
Plex is a process whose output stream is a fair multiplexing of its input streams. It makes no assumptions about the traffic patterns occuring on the input streams and ensures that no input stream will be starved by busy siblings. It guarantees that if an input stream has data pending, no other stream will be serviced twice before that data is serviced.Channel Protocols
Input Channels | ||
---|---|---|
in[] | java.lang.Object | The input streams. |
Output Channels | ||
out | java.lang.Object | The multiplexed output stream. |
Example
The following example shows how to use Plex in a small program.import org.jcsp.lang.*; import org.jcsp.plugNplay.*; public class PlexExample { public static void main (String[] argv) { final One2OneChannel[] a = Channel.one2oneArray (3); final One2OneChannel[] b = Channel.one2oneArray (3); final One2OneChannel c = Channel.one2one (); new Parallel ( new CSProcess[] { new Numbers (a[0].out ()), new Fibonacci (a[1].out ()), new Squares (a[2].out ()), new Sign ("Numbers ", a[0].in (), b[0].out ()), new Sign (" Fibonacci ", a[1].in (), b[1].out ()), new Sign (" Squares ", a[2].in (), b[2].out ()), new Plex (Channel.getInputArray (b), c.out ()), new Printer (c.in (), "", "\n") } ).run (); } }
Implemntation Note
For information, here is the run method for this process:public void run () { Alternative alt = new Alternative (in); // in is the input channel array while (true) { out.write (in[alt.fairSelect ()].read ()); // out is the output channel } }
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AltingChannelInput[]
The first input Channelprivate final ChannelOutput
The output Channel -
Constructor Summary
ConstructorsConstructorDescriptionPlex
(AltingChannelInput[] in, ChannelOutput out) Construct a new Plex process with input channels in and output channel out. -
Method Summary
-
Field Details
-
in
The first input Channel -
out
The output Channel
-
-
Constructor Details
-
Plex
Construct a new Plex process with input channels in and output channel out. The ordering of the input channels makes no difference to the behaviour of this process.- Parameters:
in
- the input channelsout
- the output channel
-
-
Method Details