Package io.javago

Interface OutputChannel<T>

Type Parameters:
T - the type of messages handled by the channel
All Superinterfaces:
AutoCloseable, Iterable<T>
All Known Subinterfaces:
Channel<T>
All Known Implementing Classes:
BufferedQueueChannel

public interface OutputChannel<T> extends AutoCloseable, Iterable<T>
The OutputChannel interface defines the operations for a Go channel in Java that can send messages of a specified type. It extends AutoCloseable to support resource management and Iterable to allow for iteration over the messages in the channel.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the channel.
    boolean
    Waits until the channel has another message.
    boolean
    Waits until the channel has space for another message or is closed.
    boolean
    Checks if the channel is closed.
    boolean
    Checks if the channel is empty.
    boolean
    Checks if the channel is full.
    static <T> Channel<T>
    Creates a new channel with a default capacity.
    static <T> Channel<T>
    make(int capacity)
    Creates a new channel with the specified capacity.
    void
    send(T message)
    Sends a message through the channel, waiting if necessary for space to become available.

    Methods inherited from interface java.lang.Iterable

    forEach, iterator, spliterator
  • Method Details

    • send

      void send(T message)
      Sends a message through the channel, waiting if necessary for space to become available.
      Parameters:
      message - the message to be sent
      Throws:
      IllegalStateException - if the channel
    • isClosed

      boolean isClosed()
      Checks if the channel is closed.
      Returns:
      true if the channel is closed, false otherwise
    • close

      void close()
      Closes the channel. Once closed, no more messages can be sent, but any remaining messages can still be received. Closing an already closed channel has no effect.
      Specified by:
      close in interface AutoCloseable
    • isEmpty

      boolean isEmpty()
      Checks if the channel is empty.
      Returns:
      true if the channel is empty, false otherwise
    • isFull

      boolean isFull()
      Checks if the channel is full.
      Returns:
      true if the channel is full, false otherwise
    • hasSpace

      boolean hasSpace()
      Waits until the channel has space for another message or is closed.
      Returns:
      true if the channel has space, false if the channel is closed
    • hasNext

      boolean hasNext()
      Waits until the channel has another message.
      Returns:
      true if there are more messages, false if the channel is both closed and empty.
    • make

      static <T> Channel<T> make()
      Creates a new channel with a default capacity.
      Type Parameters:
      T - the type of messages handled by the channel
      Returns:
      a new Channel instance
    • make

      static <T> Channel<T> make(int capacity)
      Creates a new channel with the specified capacity.
      Type Parameters:
      T - the type of messages handled by the channel
      Parameters:
      capacity - the capacity of the channel
      Returns:
      a new Channel instance with the specified capacity