public final class Multiplex
Fair multiplexes its input Object stream array into one output stream (carrying source channel and data pairs).
The ordering of the channels in the in array makes no difference to the functionality of this process -- the multiplexing services all channels fairly.
Input Channels | ||
---|---|---|
in[] | java.lang.Object | The input streams. |
Output Channels | ||
out | java.lang.Integer, java.lang.Object | The channel index followed by the multiplexed data. |
import org.jcsp.lang.*; import org.jcsp.plugNplay.*; public final class MultiplexExample { public static void main (String[] argv) { final One2OneChannel[] a = Channel.createOne2One (3); final One2OneChannel b = Channel.createOne2One (); new Parallel ( new CSProcess[] { new Numbers (a[0].out ()), new Fibonacci (a[1].out ()), new Squares (a[2].out ()), new Multiplex (Channel.getInputArray (a), b.out ()), new CSProcess () { public void run () { String[] key = {"Numbers ", " Fibonacci ", " Squares "}; while (true) { int channel = ((Integer) b.in ().read ()).intValue (); System.out.print (key[channel]); // print channel source int n = ((Integer) b.in ().read ()).intValue (); System.out.println (n); // print multiplexed data } } } } ).run (); } }
Constructor and description |
---|
Multiplex
(AltingChannelInput[] in, ChannelOutput out) Construct a new Multiplex process with the input Channel in and the output Channels out. |
Construct a new Multiplex 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.
in
- the input channelsout
- the output channelJCSP for Java 1.8 generated 14-10-2016 by Jon Kerridge, Edinburgh Napier University - j dot kerridge at napier dot ac dot uk