- All Implemented Interfaces:
CloseableChannel,Source<T>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddone()Close the channel, indicating that no more elements will be sent.Close the channel, indicating that no more elements will be sent.voidClose the channel, indicating an error.errorOrClosed(Throwable reason) Close the channel, indicating an error.receive()Receive a value from the channel.Create a clause which can be used inSelect.select(SelectClause[]).<U> SelectClause<U> receiveClause(Function<T, U> callback) Create a clause which can be used inSelect.select(SelectClause[]).Receive a value from the channel.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.softwaremill.jox.CloseableChannel
isClosedForReceive, isClosedForSendMethods inherited from interface com.softwaremill.jox.Source
collectAsView, filterAsView, forEach, toList
-
Constructor Details
-
CollectSource
A view on theoriginalsource, which transforms the received values using the provided functionf. Iffreturnsnull, 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:
original- The original source, from which values are received.f- The mapping / filtering function. If the function returnsnull, the value will be skipped.
-
-
Method Details
-
receive
Description copied from interface:SourceReceive a value from the channel.- Specified by:
receivein interfaceSource<V>- Throws:
InterruptedException
-
receiveOrClosed
Description copied from interface:SourceReceive a value from the channel. Doesn't throw exceptions when the channel is closed, but returns a value.- Specified by:
receiveOrClosedin interfaceSource<V>- Returns:
- Either a value of type
T, orChannelClosed, when the channel is closed. - Throws:
InterruptedException
-
receiveClause
Description copied from interface:SourceCreate a clause which can be used inSelect.select(SelectClause[]). The clause will receive a value from the current channel.- Specified by:
receiveClausein interfaceSource<V>
-
receiveClause
Description copied from interface:SourceCreate a clause which can be used inSelect.select(SelectClause[]). The clause will receive a value from the current channel, and transform it using the providedcallback.- Specified by:
receiveClausein interfaceSource<V>
-
done
public void done()Description copied from interface:CloseableChannelClose the channel, indicating that no more elements will be sent.Any elements that are already buffered will be delivered. Any send operations that are in progress will complete normally, when a receiver arrives. Any pending receive operations will complete with a channel closed result.
Subsequent
Sink.send(Object)operations will throwChannelClosedException.- Specified by:
donein interfaceCloseableChannel
-
doneOrClosed
Description copied from interface:CloseableChannelClose the channel, indicating that no more elements will be sent. Doesn't throw exceptions when the channel is closed, but returns a value.Any elements that are already buffered will be delivered. Any send operations that are in progress will complete normally, when a receiver arrives. Any pending receive operations will complete with a channel closed result.
Subsequent
Sink.send(Object)operations will throwChannelClosedException.- Specified by:
doneOrClosedin interfaceCloseableChannel- Returns:
- Either
null, orChannelClosed, when the channel is already closed.
-
error
Description copied from interface:CloseableChannelClose the channel, indicating an error.Any elements that are already buffered won't be delivered. Any send or receive operations that are in progress will complete with a channel closed result.
Subsequent
Sink.send(Object)andSource.receive()operations will throwChannelClosedException.- Specified by:
errorin interfaceCloseableChannel- Parameters:
reason- The reason of the error. Notnull.
-
errorOrClosed
Description copied from interface:CloseableChannelClose the channel, indicating an error. Doesn't throw exceptions when the channel is closed, but returns a value.Any elements that are already buffered won't be delivered. Any send or receive operations that are in progress will complete with a channel closed result.
Subsequent
Sink.send(Object)andSource.receive()operations will throwChannelClosedException.- Specified by:
errorOrClosedin interfaceCloseableChannel- Returns:
- Either
null, orChannelClosed, when the channel is already closed.
-
closedForSend
- Specified by:
closedForSendin interfaceCloseableChannel- Returns:
- Non-
nullif no more values can be sent to this channel;Sink.send(Object)will throwChannelClosedExceptionor returnChannelClosed(in the or-closed variant).nullif the channel is not closed, and values can be sent.When closed for send, receiving using
Source.receive()might still be possible, if the channel is done, and not in an error. This can be verified usingCloseableChannel.isClosedForReceive().
-
closedForReceive
- Specified by:
closedForReceivein interfaceCloseableChannel- Returns:
- Non-
nullif no more values can be received from this channel;Source.receive()will throwChannelClosedExceptionor returnChannelClosed(in the or-closed variant).nullif the channel is not closed, and values can be received.When closed for receive, sending values is also not possible,
CloseableChannel.isClosedForSend()will returntrue.
-