Package org.jcsp.plugNplay
Class Plex2
- java.lang.Object
-
- org.jcsp.plugNplay.Plex2
-
- All Implemented Interfaces:
CSProcess
public final class Plex2 extends java.lang.Object implements CSProcess
Fair multiplexes two Object streams into one.Process Diagram
in0 _______ -->--| | out in1 | Plex2 |-->-- -->--|_______|
Description
Plex2 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 in0, in1 java.lang.Object The input streams. Output Channels out java.lang.Object The multiplexed output stream. Example
The following example shows how to use Plex2 in a small program. The program also uses some of the other plugNplay processes.import org.jcsp.lang.*; import org.jcsp.plugNplay.*; public class Plex2Example { public static void main (String[] argv) { final One2OneChannel[] a = Channel.one2oneArray (2); final One2OneChannel[] b = Channel.one2oneArray (2); final One2OneChannel c = Channel.one2one (); new Parallel ( new CSProcess[] { new Fibonacci (a[0].out ()), new Squares (a[1].out ()), new Sign ("Fibonacci ", a[0].in (), b[0].out ()), new Sign (" Squares ", a[1].in (), b[1].out ()), new Plex2 (b[0].in (), b[1].in (), c.out ()), new Printer (c.in (), "", "\n") } ).run (); } }
Implemntation Note
For information, here is the run method for this process:public void run () { AltingChannelInput[] input = {in0, in1}; // in0 and in1 are the input channels Alternative alt = new Alternative (input); while (true) { out.write (input[alt.fairSelect ()].read ()); // out is the output channel } }
-
-
Field Summary
Fields Modifier and Type Field Description private AltingChannelInput
in0
The first input Channelprivate AltingChannelInput
in1
The second input Channelprivate ChannelOutput
out
The output Channel
-
Constructor Summary
Constructors Constructor Description Plex2(AltingChannelInput in0, AltingChannelInput in1, ChannelOutput out)
Construct a new Plex2 process with the input channels in0 and in1 and the output channel out.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
run()
The main body of this process.
-
-
-
Field Detail
-
in0
private final AltingChannelInput in0
The first input Channel
-
in1
private final AltingChannelInput in1
The second input Channel
-
out
private final ChannelOutput out
The output Channel
-
-
Constructor Detail
-
Plex2
public Plex2(AltingChannelInput in0, AltingChannelInput in1, ChannelOutput out)
Construct a new Plex2 process with the input channels in0 and in1 and the output channel out. The ordering of the input channels makes no difference to the behaviour of this process.- Parameters:
in0
- an input channelin1
- an input channelout
- the output channel
-
-