CSP for Java
(JCSP) 1.0-rc4

jcsp.lang
Class ProcessNetwork

java.lang.Object
  |
  +--jcsp.lang.ProcessNetwork
All Implemented Interfaces:
Runnable

Deprecated. Use ProcessManager.

public class ProcessNetwork
extends Object
implements Runnable

This enables a CSProcess to be spawned concurrently with the process doing the spawning.

Description

The ProcessNetwork class enables a CSProcess to be spawned concurrently with the process doing the spawning. The class provides methods to start, suspend, resume, join and stop the spawned process. The process may, of course, be a Parallel network of processes to any depth of nesting.

This class is especially useful for managing a process network -- for example, in an Applet, where a convenient way to suspend execution is required for when the Applet is not on screen.

When a ProcessNetwork is not required any more, the stop method can be called to stop all its processes. However, a ProcessNetwork will self-terminate if all user (i.e. non-daemon threads) have terminated.

Note: processes within a ProcessNetwork should not make calls to their network's start, suspend, resume, join or stop methods.

Example

Spawning a ProcessNetwork

This example demonstrates that the CSProcess is executed concurrently with the spawning process and that it dies when that main process terminates. The CSProcess is an `infinite' serial process.
 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) {
 
     System.out.println ("*** start the network");
 
     new ProcessNetwork (
       new CSProcess () {
         public void run () {
           while (true) {
             System.out.println (":-) network running in the background");
             pause (500);
           }
         }
       }
     ).start ();
 
     System.out.println ("*** I'm still executing as well");
     System.out.println ("*** I'm going to take 5 ...");
     pause (5000);
     System.out.println ("*** I'll take another 5 ...");
     pause (5000);
     System.out.println ("*** I'll finish now ... so the network should as well.");
   }
 }
 

Managing a ProcessNetwork

This example demonstrates management of the CSProcess executing concurrently with the spawning process.
 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 (":-) network running in the background");
             pause (500);
           }
         }
       }
     );
 
     System.out.println ("*** start the network");
     network.start ();
     for (int i = 0; i < 5; i++) {
       pause (5000);
       System.out.println ("*** suspend the network (" + i + "/" + 4 + ")");
       network.suspend ();
       pause (5000);
       System.out.println ("*** resume the network (" + i + "/" + 4 + ")");
       network.resume ();
     }
     pause (5000);
     System.out.println ("*** stop the network");
     network.stop ();
     System.out.println ("*** and finish myself!");
   }
 }
 

Author:
P.D.Austin
See Also:
ProcessManager

Constructor Summary
ProcessNetwork(CSProcess process)
          Deprecated.  
 
Method Summary
 void join()
          Deprecated. Join the network (that is wait for the the network to terminate).
 void resume()
          Deprecated. Resume the network.
 void run()
          Deprecated. Run the network (that is start it and wait for it to terminate).
 void start()
          Deprecated. Start the network (but keep running ourselves).
 void stop()
          Deprecated. Stop (permanently) the network.
 void suspend()
          Deprecated. Suspend the network.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProcessNetwork

public ProcessNetwork(CSProcess process)
Deprecated. 
Parameters:
process - the CSProcess to be executed by this ProcessNetwork
Method Detail

start

public void start()
Deprecated. 
Start the network (but keep running ourselves).

stop

public void stop()
Deprecated. 
Stop (permanently) the network.

suspend

public void suspend()
Deprecated. 
Suspend the network.

resume

public void resume()
Deprecated. 
Resume the network.

join

public void join()
Deprecated. 
Join the network (that is wait for the the network to terminate).

run

public void run()
Deprecated. 
Run the network (that is start it and wait for it to terminate).
Specified by:
run in interface Runnable

CSP for Java
(JCSP) 1.0-rc4

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.