CSP for Java
(JCSP) 1.0-rc4

jcsp.plugNplay
Class Paraplex

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

public final class Paraplex
extends Object
implements CSProcess

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

Process Diagram

     in[0]   __________
    ------->|          |
       :    |          | out
       :    | Paraplex |----->
    in[n-1] |          |
    ------->|__________|
 

Description

Paraplex is a process to convert multiple streams of Objects to a single stream. It assumes data will always be available on all its input streams. In each cycle, it inputs in parallel one Object 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 Paraplex 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 Paraplex (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 Paraplex 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, Paraplex 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 Paraplex 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).

Of course, avoiding uncontrolled sharing of the Object passing through this process is something that must be done. But that is not the responsibility of this process and must be arranged between the originator and recipient (or recipients).

Channel Protocols

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

Example

 import jcsp.lang.*;
 import jcsp.plugNplay.*;
 
 class ParaplexTest {
 
   public static void main (String[] args) {
 
     final One2OneChannel[] a = One2OneChannel.create (3);
     final One2OneChannel b = new One2OneChannel ();
 
     new Parallel (
       new CSProcess[] {
         new Numbers (a[0]),
         new Squares (a[1]),
         new Fibonacci (a[2]),
         new Paraplex (a, b),
         new CSProcess () {
           public void run () {
             System.out.println ("\n\t\tNumbers\t\tSquares\t\tFibonacci\n");
             while (true) {
               Object[] data = (Object[]) 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:
Deparaplex, Multiplex, Demultiplex

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

Paraplex

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