All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----jcsp.lang.Sequential
NOTE: For those familiar with the OCCAM programming language the Sequential class is equivalent to the SEQ construct.
The CSProcess's are executed when the run() method is invoked.
CSProcess's can be added to the Sequential class either via the constructor or the addProcess methods. If a call to addProcess is called while the run() method is executing the CSProcess added will not be executed until the next time run() is invoked.
CSProcess's can be removed from the Sequential class via the removeProcess method. If a call to removeProcess is called while the run() method is executing the CSProcess removed will not be removed until the next time run() is invoked.
NOTE: This class in included for completeness, it is possible to obtain the same functionality by creating the CSProcess's and calling each instances run() method in sequence.
The following example demonstrates how to generate a new CSProcess which uses several other CSProcess's which run in Sequential and terminate. The example then shows how to run several CSProcess's in Sequential and wrap them up in another CSProcess.
import jcsp.lang.*; import jcsp.util.*; import jcsp.util.buildingblocks.*; class Swap implements CSProcess { private ChannelInput in1; private ChannelInput in2; private ChannelOutput out1; private ChannelOutput out2; public Swap(ChannelInput in1, ChannelInput in2, ChannelOutput out1, ChannelOutput out2) { this.in1 = in1; this.in2 = in2; this.out1 = out1; this.out2 = out2; } public void run() { ProcessRead[] inProcs = { new ProcessRead(in1), new ProcessRead(in2) }; ProcessWrite[] outProcs = { new ProcessWrite(out1), new ProcessWrite(out2) }; Sequential inPar = new Sequential(inProcs); Sequential outPar = new Sequential(outProcs); while (true) { inPar.run(); // read from Channel in1 then in2 outProcs[0].value = inProcs[1].value; outProcs[1].value = inProcs[0].value; outPar.run(); // write to Channel out 1 then out2 } } } public class SequentialExample { public static void main(String[] argv) { final Channel a = new One2OneChannel(); final Channel b = new One2OneChannel(); final Channel c = new One2OneChannel(); final Channel d = new One2OneChannel(); new Parallel(new CSProcess[] { new CSProcess() { public void run() { a.write(""); while (true) { Object o = c.read(); a.write(o + " \n"); } } }, new Nos(b), new Swap(a, b, c, d), new Printer(d) }).run(); } }
public Sequential()
public Sequential(CSProcess processes[])
public synchronized void addProcess(CSProcess process)
public synchronized void addProcess(CSProcess processes[])
public synchronized void removeProcess(CSProcess process)
public synchronized void run()
All Packages Class Hierarchy This Package Previous Next Index