CSP for Java
(JCSP) 1.1-rc4

Class Paraplex

  extended by org.jcsp.plugNplay.Paraplex
All Implemented Interfaces:

public final class Paraplex
extends Object
implements CSProcess

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

Process Diagram


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.


 import org.jcsp.lang.*;
 import org.jcsp.plugNplay.*;
 class ParaplexExample {
   public static void main (String[] args) {
     final One2OneChannel[] a = Channel.one2oneArray (3);
     final One2OneChannel b = Channel.one2one ();
     new Parallel (
       new CSProcess[] {
         new Numbers (a[0].out ()),
         new Squares (a[1].out ()),
         new Fibonacci (a[2].out ()),
         new Paraplex (Channel.getInputArray (a), b.out ()),
         new CSProcess () {
           public void run () {
             ChannelInput in = b.in ();
             System.out.println ("\n\t\tNumbers\t\tSquares\t\tFibonacci\n");
             while (true) {
               Object[] data = (Object[]) in.read ();
               for (int i = 0; i < data.length; i++) {
                 System.out.print ("\t\t" + data[i]);
               System.out.println ();
     ).run ();

P.H. Welch
See Also:
Deparaplex, Multiplex, Demultiplex

Constructor Summary
Paraplex(ChannelInput[] in, ChannelOutput out)
          Construct a new ParaplexInt process from the array of input channels to the output channel.
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


public Paraplex(ChannelInput[] in,
                ChannelOutput out)
Construct a new ParaplexInt process from the array of input channels to the output channel. The ordering of the channels in the input array makes no difference to the functionality of this process.

in - the input channels
out - the output channel
Method Detail


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

Specified by:
run in interface CSProcess

CSP for Java
(JCSP) 1.1-rc4

Submit a bug or feature to jcsp-team@kent.ac.uk
Version 1.1-rc4 of the JCSP API Specification (Copyright 1997-2008 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.