Package kilim

Class Cell<T>

java.lang.Object
kilim.Cell<T>
All Implemented Interfaces:
EventPublisher, PauseReason

public class Cell<T> extends Object implements PauseReason, EventPublisher
A cell is a single-space buffer that supports multiple producers and a single consumer, functionally identical to Mailbox bounded to a size of 1 (and hence optimized for this size)
  • Field Details

  • Constructor Details

    • Cell

      public Cell()
  • Method Details

    • get

      public T get(EventSubscriber eo)
      Non-blocking, nonpausing get.
      Parameters:
      eo - . If non-null (and if there is no message), registers this observer. The observer is notified with a MessageAvailable event when a put() is done.
      Returns:
      buffered message if there's one, or null
    • put

      public boolean put(T msg, EventSubscriber eo)
      Non-blocking, nonpausing put.
      Parameters:
      eo - . If non-null, registers this observer and calls it with an SpaceAvailable event when there's space.
      Returns:
      buffered message if there's one, or null
    • getnb

      public T getnb()
      Get, don't pause or block.
      Returns:
      stored message, or null if no message found.
    • get

      public T get() throws Pausable
      Returns:
      non-null message.
      Throws:
      Pausable
    • get

      public T get(long timeoutMillis) throws Pausable
      Returns:
      non-null message.
      Throws:
      Pausable
    • addSpaceAvailableListener

      public void addSpaceAvailableListener(EventSubscriber spcSub)
    • removeSpaceAvailableListener

      public void removeSpaceAvailableListener(EventSubscriber spcSub)
    • addMsgAvailableListener

      public void addMsgAvailableListener(EventSubscriber msgSub)
    • removeMsgAvailableListener

      public void removeMsgAvailableListener(EventSubscriber msgSub)
    • putnb

      public boolean putnb(T msg)
    • put

      public void put(T msg) throws Pausable
      Throws:
      Pausable
    • put

      public boolean put(T msg, int timeoutMillis) throws Pausable
      Throws:
      Pausable
    • putb

      public void putb(T msg)
    • putb

      public void putb(T msg, long timeoutMillis)
    • hasMessage

      public boolean hasMessage()
    • hasSpace

      public boolean hasSpace()
    • getb

      public T getb()
      retrieve a message, blocking the thread indefinitely. Note, this is a heavyweight block, unlike #get() that pauses the Fiber but doesn't block the thread.
    • getb

      public T getb(long timeoutMillis)
      retrieve a msg, and block the Java thread for the time given.
      Parameters:
      millis - . max wait time
      Returns:
      null if timed out.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isValid

      public boolean isValid(Task t)
      Description copied from interface: PauseReason
      True if the given task's reason for pausing is still valid.
      Specified by:
      isValid in interface PauseReason