Class ProcessReadInt

  • All Implemented Interfaces:
    CSProcess

    public class ProcessReadInt
    extends java.lang.Object
    implements CSProcess
    Reads one int from its input channel.

    Process Diagram

    Description

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

    ProcessReadInt 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 int All channels in this package carry integers.

    Example

    ProcessReadInt 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:
       ChannelInputInt in0, in1;
       .
       .
       .
       ProcessReadInt read0 = new ProcessReadInt (in0);
       ProcessReadInt read1 = new ProcessReadInt (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.H. Welch and P.D. Austin
    See Also:
    Parallel, ProcessRead, ProcessWrite, ProcessWriteInt
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int value
      The int read from the channel
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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 int value
        The int read from the channel
    • Constructor Detail

      • ProcessReadInt

        public ProcessReadInt​(ChannelInputInt in)
        Construct a new ProcessReadInt.
        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