org.jcsp.nxt.lang
Class AltingChannelInput

java.lang.Object
  extended by org.jcsp.nxt.lang.Guard
      extended by org.jcsp.nxt.lang.AltingChannelInput
All Implemented Interfaces:
ChannelInput
Direct Known Subclasses:
One2OneChannelImpl

public abstract class AltingChannelInput
extends Guard
implements ChannelInput

This extends Guard and ChannelInput to enable a process to choose between many object input (and other) events.

Description

AltingChannelInput extends Guard and ChannelInput to enable a process to choose between many object input (and other) events. The methods inherited from Guard are of no concern to users of this package.

Example

 import org.jcsp.lang.*;
 
 public class AltingExample implements CSProcess {
 
   private final AltingChannelInput in0, in1;
   
   public AltingExample (final AltingChannelInput in0,
                         final AltingChannelInput in1) {
     this.in0 = in0;
     this.in1 = in1;
   }
 
   public void run () {
 
     final Guard[] altChans = {in0, in1};
     final Alternative alt = new Alternative (altChans);
 
     while (true) {
       switch (alt.select ()) {
         case 0:
           System.out.println ("in0 read " + in0.read ());
         break;
         case 1:
           System.out.println ("in1 read " + in1.read ());
         break;
       }
     }
 
   }
 
 }
 

Author:
P.D.Austin and P.H.Welch
See Also:
org.jcsp.lang.Guard, org.jcsp.lang.Alternative

Constructor Summary
AltingChannelInput()
           
 
Method Summary
abstract  boolean pending()
          Returns whether there is data pending on this channel.
 
Methods inherited from class org.jcsp.nxt.lang.Guard
disable, enable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jcsp.nxt.lang.ChannelInput
read
 

Constructor Detail

AltingChannelInput

public AltingChannelInput()
Method Detail

pending

public abstract boolean pending()
Returns whether there is data pending on this channel.

Note: if there is, it won't go away until you read it. But if there isn't, there may be some by the time you check the result of this method.

Returns:
state of the channel.