- All Known Implementing Classes:
Channel,CollectSource
A channel can be closed in two ways:
- using
done()ordoneOrClosed(), indicating that no more elements will be sent - using
error(Throwable)orerrorOrClosed(Throwable), indicating an error
A channel can be closed only once. Subsequent calls to done() or error(Throwable) will throw
ChannelClosedException, or return the original closing reason (when using doneOrClosed() or errorOrClosed(Throwable)).
Closing the channel is thread-safe.
-
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.default booleandefault boolean
-
Method Details
-
done
void done()Close 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.- Throws:
ChannelClosedException- When the channel is already closed.
-
doneOrClosed
Object doneOrClosed()Close 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.- Returns:
- Either
null, orChannelClosed, when the channel is already closed.
-
error
Close 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.- Parameters:
reason- The reason of the error. Notnull.- Throws:
ChannelClosedException- When the channel is already closed.
-
errorOrClosed
Close 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.- Returns:
- Either
null, orChannelClosed, when the channel is already closed.
-
isClosedForSend
default boolean isClosedForSend()- Returns:
trueif no more values can be sent to this channel;Sink.send(Object)will throwChannelClosedExceptionor returnChannelClosed(in the or-closed variant).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 usingisClosedForReceive().
-
isClosedForReceive
default boolean isClosedForReceive()- Returns:
trueif no more values can be received from this channel;Source.receive()will throwChannelClosedExceptionor returnChannelClosed(in the or-closed variant).When closed for receive, sending values is also not possible,
isClosedForSend()will returntrue.When
false, values might be received from the channel, when callingSource.receive(), but it's not guaranteed that some values will be available. They might be received concurrently, or filtered out if the channel is created usingSource.collectAsView(Function)orSource.filterAsView(Predicate).
-
closedForSend
ChannelClosed closedForSend()- 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 usingisClosedForReceive().
-
closedForReceive
ChannelClosed closedForReceive()- 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,
isClosedForSend()will returntrue.
-