All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jcsp.lang.Sequential

java.lang.Object
   |
   +----jcsp.lang.Sequential

public class Sequential
extends Object
implements CSProcess

Description

The Sequential class enables the sequential execution of one or more CSProcess's which halts the execution of the current CSProcess until all of the CSProcess's finish execution.

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.

Example

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();
   }
 }
 

Author:
P.D.Austin
See Also:
CSProcess, ProcessNetwork

Constructor Index

 o Sequential()
Construct a new Sequential construct without any processes.
 o Sequential(CSProcess[])
Construct a new Sequential construct with the CSProcess's specified.

Method Index

 o addProcess(CSProcess)
Adds a new CSProcess to the Sequential construct.
 o addProcess(CSProcess[])
Adds a new CSProcess for each of the elements of the array to the Sequential construct.
 o removeProcess(CSProcess)
Removes a CSProcess from the Sequential construct.
 o run()
Executes each of the CSProcess's associated with this Object once in sequence.

Constructors

 o Sequential
 public Sequential()
Construct a new Sequential construct without any processes.

 o Sequential
 public Sequential(CSProcess processes[])
Construct a new Sequential construct with the CSProcess's specified.

Parameters:
processes - The processes to be executed in sequence

Methods

 o addProcess
 public synchronized void addProcess(CSProcess process)
Adds a new CSProcess to the Sequential construct. The CSProcess will be executed the next time run() is invoked.

Parameters:
process - The CSProcess to be added
 o addProcess
 public synchronized void addProcess(CSProcess processes[])
Adds a new CSProcess for each of the elements of the array to the Sequential construct. The CSProcess's will be executed the next time run() is invoked.

Parameters:
processes - The CSProcess's to be added
 o removeProcess
 public synchronized void removeProcess(CSProcess process)
Removes a CSProcess from the Sequential construct. The CSProcess will not be executed the next time run() is invoked.

Parameters:
process - The CSProcess to be removed
 o run
 public synchronized void run()
Executes each of the CSProcess's associated with this Object once in sequence. This method will return only when and if all the CSProcess's terminate.


All Packages  Class Hierarchy  This Package  Previous  Next  Index