Class PlexInt

java.lang.Object
org.jcsp.plugNplay.ints.PlexInt
All Implemented Interfaces:
CSProcess

public final class PlexInt extends Object implements CSProcess
Fair multiplexes its input integer stream array into one output stream.

Process Diagram

Description

PlexInt 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[] int The input streams.
Output Channels
out int The multiplexed output stream.

Example

The following example shows how to use PlexInt in a small program.
 import org.jcsp.lang.*;
 import org.jcsp.plugNplay.ints.*;
 
 public class PlexIntExample {
 
   public static void main (String[] argv) {
 
     final One2OneChannelInt[] a = Channel.one2oneIntArray (3);
     final One2OneChannelInt b = Channel.one2oneInt ();
 
     new Parallel (
       new CSProcess[] {
         new NumbersInt (a[0].out ()),
         new FibonacciInt (a[1].out ()),
         new SquaresInt (a[2].out ()),
         new PlexInt (Channel.getInputArray (a), b.out ()),
         new PrinterInt (b.in (), "--> ", "\n")
       }
     ).run ();
 
   }
 
 }
 
Note: this example does not produce easily understandable output, since the multiplexed stream contains only numbers -- there is no indication of the streams from which they were sourced. To get that indication, we can either use MultiplexInt or sign each int stream to be multiplexed with SignInt and multiplex with Plex.

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 Details

  • Constructor Details

    • PlexInt

      public PlexInt(AltingChannelInputInt[] in, ChannelOutputInt out)
      Construct a new PlexInt 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 channels
      out - the output channel
  • Method Details

    • run

      public void run()
      The main body of this process.
      Specified by:
      run in interface CSProcess