|
CSP for Java (JCSP) 1.1-rc4 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jcsp.plugNplay.ints.ParaplexInt
public final class ParaplexInt
Parallel multiplexes its input integer stream array on to one output stream.
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 aThe 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
or
Any2AnyChannelImpl
) and waits for the acknowledgment
(for which only a One2OneChannelImpl
is needed).
Input Channels | ||
---|---|---|
in[] | int | Most channels in this package carry integers. |
Output Channels | ||
out | int[] | A packet carrying the paraplexed data. |
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 (); } }
DeparaplexInt
,
MultiplexInt
,
DemultiplexInt
Constructor Summary | |
---|---|
ParaplexInt(ChannelInputInt[] 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 ParaplexInt(ChannelInputInt[] in, ChannelOutput out)
in
- the input channelsout
- the output channelMethod Detail |
---|
public void run()
run
in interface CSProcess
|
CSP for Java (JCSP) 1.1-rc4 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |