Class ParaplexInt
- java.lang.Object
-
- org.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
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
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 inOne2AnyChannelImpl
orAny2AnyChannelImpl
).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
One2AnyChannelImpl
orAny2AnyChannelImpl
) and waits for the acknowledgment (for which only aOne2OneChannelImpl
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 org.jcsp.lang.*; import org.jcsp.plugNplay.ints.*; class ParaplexIntExample { public static void main (String[] args) { final One2OneChannelInt[] a = Channel.one2oneIntArray (3); final One2OneChannel b = Channel.one2one (); new Parallel ( new CSProcess[] { new NumbersInt (a[0].out ()), new SquaresInt (a[1].out ()), new FibonacciInt (a[2].out ()), new ParaplexInt (Channel.getInputArray (a), b.out ()), new CSProcess () { public void run () { System.out.println ("\n\t\tNumbers\t\tSquares\t\tFibonacci\n"); while (true) { int[] data = (int[]) b.in ().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
Constructors Constructor Description ParaplexInt(ChannelInputInt[] in, ChannelOutput out)
Construct a new ParaplexInt process from the array of input channels to the output channel.
-
-
-
Constructor Detail
-
ParaplexInt
public ParaplexInt(ChannelInputInt[] 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.- Parameters:
in
- the input channelsout
- the output channel
-
-