CSP for Java
(JCSP) 1.0-rc4

jcsp.plugNplay
Class ProcessRead

java.lang.Object
  |
  +--jcsp.plugNplay.ProcessRead
All Implemented Interfaces:
CSProcess

public class ProcessRead
extends Object
implements CSProcess

Reads one Object from its input channel.

Process Diagram

       _______________
  in  |               |
 -->--|  ProcessRead  |
      |_______________|
 

Description

ProcessRead is a process that performs a single read from its in channel and then terminates. It stores the read Object in the public value field of this process (which is safe to examine after the process has terminated and before it is next run).

ProcessRead declaration, construction and use should normally be localised within a single method -- so we feel no embarassment about its public field. Its only (envisaged) purpose is as described in the example below.

Channel Protocols

Input Channels
in java.lang.Object The in Channel can accept data of any Class.

Example

ProcessRead is designed to simplify reading in parallel from channels. Make as many instances as there are channels, binding each instance to a different channel, together with a Parallel object in which to run them:
   ChannelInput in0, in1;
   .
   .
   .
   ProcessRead read0 = new ProcessRead (in0);
   ProcessRead read1 = new ProcessRead (in1);
   CSProcess parRead01 = new Parallel (new CSProcess[] {in0, in1});
 
The above is best done once, before any looping over the parallel read commences. A parallel read can now be performed at any time (and any number of times) by executing:
     parRead01.run ();
 
This terminates when, and only when, both reads have completed -- the events may occur in any order. The values read may then be found in read0.value and read1.value, where they may be safely accessed up until the time that parRead01 is run again.

Author:
P.D.Austin
See Also:
Parallel, ProcessWrite, ProcessReadInt, ProcessWriteInt

Field Summary
 Object value
          The Object read from the channel
 
Constructor Summary
ProcessRead(ChannelInput in)
          Construct a new ProcessRead.
 
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
 

Field Detail

value

public Object value
The Object read from the channel
Constructor Detail

ProcessRead

public ProcessRead(ChannelInput in)
Construct a new ProcessRead.
Parameters:
in - the channel from which to read
Method Detail

run

public void run()
The main body of this process.
Specified by:
run in interface CSProcess

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.