All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jcsp.lang.ProcessNetwork

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

public class ProcessNetwork
extends Object
implements Runnable

Description

The ProcessNetwork class enables a CSProcess to be executed independently from the CSProcess that started it running so as not to block to CSProcess which starts it. The class also provides methods to suspend, resume and stop all CSProcess's executed within the ProcessNetwork.

This class can be used to suspend a process network to save processor usage when the network is not required and then resume it when it is required again (For example when an Applet is not on the screen).

When the ProcessNetwork is not required after the processing has finished the stop method can be called to stop all the CSProcess's within the ProcessNetwork.

NOTE: CSProcess's within the ProcessNetwork should not make calls to their ProcessNetworks start, stop, suspend or resume methods as they will either cease to execute or not be running anyway.

Example

Process running asynchronously

This example demonstrates that the CSProcess is executed in the background and that the ProcessNetwork dies when the main program finishes.
 import jcsp.lang.*;
 public class ProcessNetworkExample1 {
   public static void pause(int time) {
     try {
       Thread.sleep(time);
     }
     catch(InterruptedException e) {
     }
   }
   public static void main(String[] argv) {
     new ProcessNetwork(new CSProcess() {
       public void run() {
         while (true) {
           System.out.println("Still running in the background");
           pause(500);
         }
       }
     }).start();
     System.out.println("I'm still executing as well");
     System.out.println("Wait a while");
     pause(5000);
     System.out.println("Woke up. Now I'm finished the ProcessNetwork should exit as well");
   }
 }
 

Controlling the ProcessNetwork

 import jcsp.lang.*;
 public class ProcessNetworkExample2 {
   public static void pause(int time) {
     try {
       Thread.sleep(time);
     }
     catch(InterruptedException e) {
     }
   }
   public static void main(String[] argv) {
     ProcessNetwork network = new ProcessNetwork(new CSProcess() {
       public void run() {
         while (true) {
           System.out.println("Still running in the background");
           pause(500);
         }
       }
     });
     network.start();
     pause(5000);
     System.out.println("Suspend the Network");
     network.suspend();
     pause(5000);
     System.out.println("Resume the Network");
     network.resume();
     pause(5000);
     System.out.println("Stop the Network");
     network.stop();
     pause(5000);
   }
 }
 

Author:
P.D.Austin

Constructor Index

 o ProcessNetwork(CSProcess)

Method Index

 o join()
 o resume()
Resumes all the CSProcess's executing in this ProcessNetwork.
 o run()
Runs the CSProcess.
 o start()
Starts the top level CSProcess running.
 o stop()
Permanently stops all the CSProcess's executing in this ProcessNetwork.
 o suspend()
Suspends all the CSProcess's executing in this ProcessNetwork.

Constructors

 o ProcessNetwork
 public ProcessNetwork(CSProcess process)
Parameters:
process - The CSProcess to be executed by this ProcessNetwork

Methods

 o start
 public void start()
Starts the top level CSProcess running.

 o stop
 public void stop()
Permanently stops all the CSProcess's executing in this ProcessNetwork.

 o suspend
 public void suspend()
Suspends all the CSProcess's executing in this ProcessNetwork.

 o resume
 public void resume()
Resumes all the CSProcess's executing in this ProcessNetwork.

 o join
 public void join()
 o run
 public synchronized void run()
Runs the CSProcess.


All Packages  Class Hierarchy  This Package  Previous  Next  Index