CSP for Java
(JCSP) 1.0-rc4

jcsp.plugNplay.ints
Class MultiplexInt

java.lang.Object
  |
  +--jcsp.plugNplay.ints.MultiplexInt
All Implemented Interfaces:
CSProcess

public final class MultiplexInt
extends Object
implements CSProcess

Fair multiplexes its input integer stream array into one output stream (carrying source channel and data pairs).

Process Diagram

     in[0]   ______________
    ------->|              |
       :    |              | out
       :    | MultiplexInt |----->
    in[n-1] |              |
    ------->|______________|
 

Description

MultiplexInt is a process to convert multiple streams of ints to a single stream in such a way that it can be de-multiplexed later. The protocol on the outgoing multiplexed stream consists of an int, that represents the channel identity of the multiplexed data, followed by the multiplexed data.

The ordering of the channels in the in array makes no difference to the functionality of this process -- the multiplexing services all channels fairly.

Channel Protocols

Input Channels
in[] int All channels in this package carry integers.
Output Channels
out int, int An out message is an index followed by the multiplexed data.

Example

The following example shows how to use MultiplexInt in a small program.
 import jcsp.lang.*;
 import jcsp.plugNplay.ints.*;
 
 public final class MultiplexIntExample {
 
   public static void main (String[] argv) {
 
     final One2OneChannelInt[] a = One2OneChannelInt.create (3);
     final One2OneChannelInt b = new One2OneChannelInt ();
 
     new Parallel (
       new CSProcess[] {
         new NumbersInt (a[0]),
         new FibonacciInt (a[1]),
         new SquaresInt (a[2]),
         new MultiplexInt (a, b),
         new CSProcess () {
           public void run () {
             String[] key = {"Numbers ",
                             "            Fibonacci ",
                             "                          Squares "};
             while (true) {
               System.out.print (key[b.read ()]);   // print channel source
               System.out.println (b.read ());      // print multiplexed data
             }
           }
         }
       }
     ).run ();
 
   }
 
 }
 

Author:
P.D.Austin and P.H.Welch
See Also:
DemultiplexInt, ParaplexInt, DeparaplexInt, PlexInt

Constructor Summary
MultiplexInt(AltingChannelInputInt[] in, ChannelOutputInt out)
          Construct a new MultiplexInt process with the input Channel in and the output Channels out.
 
Method Summary
 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 Detail

MultiplexInt

public MultiplexInt(AltingChannelInputInt[] in,
                    ChannelOutputInt out)
Construct a new MultiplexInt process with the input Channel in and the output Channels out. The ordering of the Channels in the in array make no difference to the functionality of this process -- the multiplexing services all channels fairly.
Parameters:
in - the input channels
out - the output channel
Method Detail

run

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

CSP for Java
(JCSP) 1.0-rc4

Submit a bug or feature to jcsp-team@ukc.ac.uk
Version 1.0-rc4 of the JCSP API Specification (Copyright 1997-2000 P.D.Austin and P.H.Welch - All Rights Reserved)
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.