T
- type of elements for value streamspublic interface Sink<T> extends Consumer<T>
Consumer
used to conduct values through the stages of
a stream pipeline, with additional methods to manage size information,
control flow, etc. Before calling the accept()
method on a
Sink
for the first time, you must first call the begin()
method to inform it that data is coming (optionally informing the sink how
much data is coming), and after all data has been sent, you must call the
end()
method. After calling end()
, you should not call
accept()
without again calling begin()
. Sink
also
offers a mechanism by which the sink can cooperatively signal that it does
not wish to receive any more data (the cancellationRequested()
method), which a source can poll before sending more data to the
Sink
.
A sink may be in one of two states: an initial state and an active state.
It starts out in the initial state; the begin()
method transitions
it to the active state, and the end()
method transitions it back into
the initial state, where it can be re-used. Data-accepting methods (such as
accept()
are only valid in the active state.
Modifier and Type | Interface and Description |
---|---|
static class |
Sink.ChainedDouble<E_OUT>
Abstract
Sink implementation designed for creating chains of
sinks. |
static class |
Sink.ChainedInt<E_OUT>
Abstract
Sink implementation designed for creating chains of
sinks. |
static class |
Sink.ChainedLong<E_OUT>
Abstract
Sink implementation designed for creating chains of
sinks. |
static class |
Sink.ChainedReference<T,E_OUT>
Abstract
Sink implementation for creating chains of
sinks. |
static interface |
Sink.OfDouble
Sink that implements Sink<Double> , re-abstracts
accept(double) , and wires accept(Double) to bridge to
accept(double) . |
static interface |
Sink.OfInt
Sink that implements Sink<Integer> , re-abstracts
accept(int) , and wires accept(Integer) to bridge to
accept(int) . |
static interface |
Sink.OfLong
Sink that implements Sink<Long> , re-abstracts
accept(long) , and wires accept(Long) to bridge to
accept(long) . |
Modifier and Type | Method and Description |
---|---|
default void |
accept(double value)
Accepts a double value.
|
default void |
accept(int value)
Accepts an int value.
|
default void |
accept(long value)
Accepts a long value.
|
default void |
begin(long size)
Resets the sink state to receive a fresh data set.
|
default boolean |
cancellationRequested()
Indicates that this
Sink does not wish to receive any more data. |
default void |
end()
Indicates that all elements have been pushed.
|
default void begin(long size)
end()
,
you may call this method to reset the sink for another calculation.size
- The exact size of the data to be pushed downstream, if
known or -1
if unknown or infinite.
Prior to this call, the sink must be in the initial state, and after this call it is in the active state.
default void end()
Sink
is
stateful, it should send any stored state downstream at this time, and
should clear any accumulated state (and associated resources).
Prior to this call, the sink must be in the active state, and after this call it is returned to the initial state.
default boolean cancellationRequested()
Sink
does not wish to receive any more data.default void accept(int value)
IllegalStateException
- if this sink does not accept int valuesdefault void accept(long value)
IllegalStateException
- if this sink does not accept long valuesdefault void accept(double value)
IllegalStateException
- if this sink does not accept double values