Package org.jcsp.plugNplay.ints

# Class Plex2Int

java.lang.Object
org.jcsp.plugNplay.ints.Plex2Int

All Implemented Interfaces:
  `CSProcess`

public final class Plex2Int extends Object implements CSProcess
Fair multiplexes two integer streams into one.

## Process Diagram

        in0  __________
       -->--|          | out
        in1 | Plex2Int |-->--
       -->--|__________|

## Description

`Plex2Int` 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 | int | The input streams.
Output Channels
out | int | The multiplexed output stream.

## Example

The following example shows how to use `Plex2Int` in a small program. The program also uses some of the other `plugNplay` processes.

     import org.jcsp.lang.*;
     import org.jcsp.plugNplay.ints.*;

     public class Plex2IntExample {

       public static void main (String[] argv) {

         final One2OneChannelInt a = Channel.one2oneInt ();
         final One2OneChannelInt b = Channel.one2oneInt ();
         final One2OneChannelInt c = Channel.one2oneInt ();

         new Parallel (
           new CSProcess[] {
             new FibonacciInt (a.out ()),
             new SquaresInt (b.out ()),
             new Plex2Int (a.in (), b.in (), c.out ()),
             new PrinterInt (c.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 `Plex2`.

## Implemntation Note

For information, here is the `run` method for this process:

       public void run () {
         AltingChannelInputInt[] 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
         }
       }

Author:
  P.H. Welch
See Also:
  - `PlexInt`
  - `MultiplexInt`

## Constructor Summary

Constructors
Constructor
Description
`Plex2Int(AltingChannelInputInt in0, AltingChannelInputInt in1, ChannelOutputInt out)`
Construct a new `Plex2Int` process with the input channels `in0` and `in1` and the output channel `out`.

## Method Summary

Modifier and Type
Method
Description
`void`
`run()`
The main body of this process.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### Plex2Int

public Plex2Int(AltingChannelInputInt in0, AltingChannelInputInt in1, ChannelOutputInt out)
Construct a new `Plex2Int` 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 channel
  `in1` - an input channel
  `out` - the output channel

## Method Details

### run

public void run()
The main body of this process.

Specified by:
  `run` in interface `CSProcess`