CSP for Java
(JCSP) 1.0-rc4

jcsp.plugNplay.ints
Class ParaplexInt

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

public final class ParaplexInt
extends Object
implements CSProcess

Parallel multiplexes its input integer stream array on to one output stream.

Process Diagram

     in[0]   _____________
    ------->|             |
       :    |             | out
       :    | ParaplexInt |----->
    in[n-1] |             |
    ------->|_____________|
 

Description

ParaplexInt is a process to convert multiple streams of ints to a single stream. It assumes data will always be available on all its input streams. In each cycle, it inputs in parallel one int from each of its inputs, packs them into an array and outputs that array as a single communication.

The parallel input means that the process will wait until something arrives from every input channel, accepting items in whatever order they turn up. The ordering of the channels in the in array, therefore, makes no difference to the functionality of this process.

Caution: the process receiving packets from ParaplexInt must agree to the following contract:

Input of an array packet means that previously input arrays must not be looked at any more (neither by itself nor any other processes to which they may have been passed).
Supporting the above, there is one more rule:
There must be only one process receiving array packets from ParaplexInt (i.e. its output channel must not be connected to a One2AnyChannel or Any2AnyChannel).
The reason for these obligations is to remove the need for ParaplexInt to generate a new array packet for each paraplexed communication -- an array that will normally be discarded by the receiving process after dealing with its contents. Instead of that, ParaplexInt operates a double-buffered protocol, constructing and reusing just two array packets. It switches between them after every cycle. In this way, it fills one packet while the process receiving its output consumes the other one. This is safe so long as that receiving process agrees to the above rules. See the Low Level example in Parallel for the details of this implementation.

Note: the above two constraints should work naturally with most applications. However, by converting the first rule into a protocol where the receiving process explicitly returns the packet (through an acknowledgment channel) when it has finished using it and before inputting the next one, the second rule could be dropped. This is trivial to do by piping the output from ParaplexInt through a simple cyclic process that inputs a packet, forwards it (down a One2AnyChannel or Any2AnyChannel) and waits for the acknowledgment (for which only a One2OneChannel is needed).

Channel Protocols

Input Channels
in[] int Most channels in this package carry integers.
Output Channels
out int[] A packet carrying the paraplexed data.

Example

 import jcsp.lang.*;
 import jcsp.plugNplay.*;
 
 class ParaplexIntTest {
 
   public static void main (String[] args) {
 
     final One2OneChannelInt[] a = One2OneChannelInt.create (3);
     final One2OneChannel b = new One2OneChannel ();
 
     new Parallel (
       new CSProcess[] {
         new NumbersInt (a[0]),
         new SquaresInt (a[1]),
         new FibonacciInt (a[2]),
         new ParaplexInt (a, b),
         new CSProcess () {
           public void run () {
             System.out.println ("\n\t\tNumbers\t\tSquares\t\tFibonacci\n");
             while (true) {
               int[] data = (int[]) b.read ();
               for (int i = 0; i < data.length; i++) {
                 System.out.print ("\t\t" + data[i]);
               }
               System.out.println ();
             }
           }
         }
       }
     ).run ();
   }
 
 }
 

Author:
P.H.Welch
See Also:
DeparaplexInt, MultiplexInt, DemultiplexInt

Constructor Summary
ParaplexInt(ChannelInputInt[] in, ChannelOutput out)
          Construct a new ParaplexInt 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

ParaplexInt

public ParaplexInt(ChannelInputInt[] in,
                   ChannelOutput out)
Construct a new ParaplexInt 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.
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.