jcsp.plugNplay
Class Plex
java.lang.Object
|
+--jcsp.plugNplay.Plex
- All Implemented Interfaces:
- CSProcess
- public final class Plex
- extends Object
- implements CSProcess
Fair multiplexes its input Object stream array into one output stream.
Process Diagram
in[0] +------+
------>| |
: | | out
: | Plex |----->
in[n-1] | |
------>| |
+------+
Description
Plex is a process whose output stream is a fair multiplexing
of its input streams. It makes no assumptions about the traffic patterns occuring
on the input streams and ensures that no input stream will be starved by busy siblings.
It guarantees that if an input stream has data pending, no other stream will be
serviced twice before that data is serviced.
Channel Protocols
Input Channels |
in[] |
java.lang.Object |
The input streams.
|
Output Channels |
out |
java.lang.Object |
The multiplexed output stream.
|
Example
The following example shows how to use Plex in a small program.
import jcsp.lang.*;
import jcsp.plugNplay.*;
public final class PlexExample {
public static void main (String[] argv) {
final One2OneChannel[] a = One2OneChannel.create (3);
final One2OneChannel[] b = One2OneChannel.create (3);
final One2OneChannel c = new One2OneChannel ();
new Parallel (
new CSProcess[] {
new Numbers (a[0]),
new Fibonacci (a[1]),
new Squares (a[2]),
new Sign ("Numbers ", a[0], b[0]),
new Sign (" Fibonacci ", a[1], b[1]),
new Sign (" Squares ", a[2], b[2]),
new Plex (b, c),
new Printer (c, "", "\n")
}
).run ();
}
}
Implemntation Note
For information, here is the run method for this process:
public void run () {
Alternative alt = new Alternative (in); // in is the input channel array
while (true) {
out.write (in[alt.fairSelect ()].read ()); // out is the output channel
}
}
- Author:
- P.H.Welch
- See Also:
Plex2
,
Multiplex
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 |
Plex
public Plex(AltingChannelInput[] in,
ChannelOutput out)
- Construct a new Plex process with input channels
in and output channel out.
The ordering of the input channels makes no difference
to the behaviour of this process.
- 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.