jcsp.plugNplay
Class Multiplex
java.lang.Object
|
+--jcsp.plugNplay.Multiplex
- All Implemented Interfaces:
- CSProcess
- public final class Multiplex
- extends Object
- implements CSProcess
Fair multiplexes its input Object stream array into one output stream
(carrying source channel and data pairs).
Process Diagram
in[0] +-----------+
------>| |
: | | out
: | Multiplex |----->
in[n-1] | |
------>| |
+-----------+
Description
Multiplex is a process to convert multiple streams of
objects to a single stream in such a way that it can be
de-multiplexed
later.
The protocol on the outgoing multiplexed stream consists of
an Integer, that represents the channel identity of the
multiplexed data, followed by the multiplexed data.
The ordering of the channels in the in array makes
no difference to the functionality of this process -- the multiplexing
services all channels fairly.
Channel Protocols
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.
|
The following example shows how to use MultiplexInt in a small program.
import jcsp.lang.*;
import jcsp.plugNplay.*;
public final class MultiplexExample {
public static void main (String[] argv) {
final One2OneChannel[] a = One2OneChannel.create (3);
final One2OneChannel b = new One2OneChannel ();
new Parallel (
new CSProcess[] {
new Numbers (a[0]),
new Fibonacci (a[1]),
new Squares (a[2]),
new Multiplex (a, b),
new CSProcess () {
public void run () {
String[] key = {"Numbers ",
" Fibonacci ",
" Squares "};
while (true) {
int channel = ((Integer) b.read ()).intValue ();
System.out.print (key[channel]); // print channel source
int n = ((Integer) b.read ()).intValue ();
System.out.println (n); // print multiplexed data
}
}
}
}
).run ();
}
}
- Author:
- P.D.Austin and P.H.Welch
- See Also:
Demultiplex
,
Paraplex
,
Deparaplex
,
Plex
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 |
Multiplex
public Multiplex(AltingChannelInput[] in,
ChannelOutput 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.
- Parameters:
in
- the input channelsout
- the output channel
run
public void run()
- The main body of this process.
- Specified by:
run
in interface CSProcess
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.