Channels Next: NrpMachine Up: The SugarCubes Tool Box Previous: Introduction


The Channel  class defines unbounded fifo files.

class Channel
  protected Vector fifo = new Vector();

  public void put(Object obj){ fifo.addElement(obj); }

  public Object get(){ 
    Object res = fifo.firstElement(); 
    return res;

  public boolean isEmpty() { return fifo.isEmpty(); }

ChannelEnv  associates channels to names. The newChannel method always return a new channel with a unique name.

public class ChannelEnv
  private Hashtable channelEnv  = new Hashtable();
  private int localNum = 0;

  public Channel getChannel(String name)
     Channel c = (Channel)channelEnv.get(name);
     if (c==null){
       c = new Channel();
     return c;

  /* Strange name, is'nt it ? */
  public Channel newChannel(){
    return getChannel("@@@local@@@" + (localNum++));