Interface Source<T>

All Superinterfaces:
CloseableChannel
All Known Implementing Classes:
Channel, CollectSource

public interface Source<T> extends CloseableChannel
A channel source, which can be used to receive values from the channel. See Channel for more details.
  • Method Details

    • receive

      T receive() throws InterruptedException
      Receive a value from the channel.
      Throws:
      ChannelClosedException - When the channel is closed.
      InterruptedException
    • receiveOrClosed

      Object receiveOrClosed() throws InterruptedException
      Receive a value from the channel. Doesn't throw exceptions when the channel is closed, but returns a value.
      Returns:
      Either a value of type T, or ChannelClosed, when the channel is closed.
      Throws:
      InterruptedException
    • receiveClause

      SelectClause<T> receiveClause()
      Create a clause which can be used in Select.select(SelectClause[]). The clause will receive a value from the current channel.
    • receiveClause

      <U> SelectClause<U> receiveClause(Function<T,U> callback)
      Create a clause which can be used in Select.select(SelectClause[]). The clause will receive a value from the current channel, and transform it using the provided callback.
    • collectAsView

      default <V> Source<V> collectAsView(Function<T,V> f)
      Creates a view of this source, where the results of receive() will be transformed using the given function f. If f returns null, the value will be skipped, and another value will be received.

      The same logic applies to receive clauses created using this source, which can be used in Select.select(SelectClause[]).

      Parameters:
      f - The mapping / filtering function. If the function returns null, the value will be skipped.
      Returns:
      A source which is a view of this source, with the mapping / filtering function applied.
    • filterAsView

      default Source<T> filterAsView(Predicate<T> p)
      Creates a view of this source, where the results of receive() will be filtered using the given predicate p.

      The same logic applies to receive clauses created using this source, which can be used in Select.select(SelectClause[]).

      Parameters:
      p - The predicate to use for filtering.
      Returns:
      A source which is a view of this source, with the filtering function applied.
    • forEach

      default void forEach(Consumer<T> c) throws InterruptedException
      Invokes the given function for each received element. Blocks until the channel is done.
      Throws:
      ChannelErrorException - When there is an upstream error.
      InterruptedException
    • toList

      default List<T> toList() throws InterruptedException
      Accumulates all elements received from the channel into a list. Blocks until the channel is done.
      Throws:
      ChannelErrorException - When there is an upstream error.
      InterruptedException