Package io.servicetalk.concurrent
Interface BlockingIterable.Processor<T>
-
- Type Parameters:
T
- the type of elements returned by theBlockingIterator
.
- All Superinterfaces:
java.lang.AutoCloseable
,BlockingIterable<T>
,CloseableIterable<T>
,java.lang.Iterable<T>
- Enclosing interface:
- BlockingIterable<T>
public static interface BlockingIterable.Processor<T> extends BlockingIterable<T>, java.lang.AutoCloseable
ABlockingIterable
that supports to dynamically emitting items usingnext(Object)
.If multiple
BlockingIterator
s are created by thisBlockingIterable
then an implementation will choose how to distribute the items emitted fromnext(Object)
to thoseBlockingIterator
s. There is no common guarantee about the nature of that distribution.Lifetime
There are two aspects of the lifetime of thisProcessor
, one from the producer side and one from the consumer side (BlockingIterator
.Producer Lifetime
A producer MUST invoke eitherclose()
(successful termination) orfail(Throwable)
(unsuccessful termination) to correctly terminate the producer side of thisProcessor
.Consumer Lifetime
A consumer can prematurely indicate termination by callingBlockingIterator.close()
. However, if a consumer receives a termination from the producer end (BlockingIterator.hasNext(long, TimeUnit)
returnsfalse
), then it need not callBlockingIterator.close()
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.servicetalk.concurrent.BlockingIterable
BlockingIterable.Processor<T>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
Closes thisBlockingIterable
and all the current or futureBlockingIterator
s.void
fail(java.lang.Throwable cause)
Terminates thisBlockingIterable
and all the current or futureBlockingIterator
s with a failure.void
next(T nextItem)
Emits the passednextItem
from theBlockingIterator
when called.-
Methods inherited from interface io.servicetalk.concurrent.BlockingIterable
forEach, forEach, iterator, spliterator
-
-
-
-
Method Detail
-
next
void next(@Nullable T nextItem) throws java.lang.Exception
Emits the passednextItem
from theBlockingIterator
when called.- Parameters:
nextItem
- to emit from theBlockingIterator
when called.- Throws:
java.lang.Exception
- If the item could not be emitted.
-
fail
void fail(java.lang.Throwable cause) throws java.lang.Exception
Terminates thisBlockingIterable
and all the current or futureBlockingIterator
s with a failure.After this method returns, any subsequent calls to
next(Object)
MUST throw anException
. All current and futureBlockingIterator
s created by thisBlockingIterable
MUST eventually throw anException
which is the same as passedcause
or wraps the same.- Parameters:
cause
- for the failure.- Throws:
java.lang.Exception
- If thisBlockingIterable
can not be terminated with a failure.
-
close
void close() throws java.lang.Exception
Closes thisBlockingIterable
and all the current or futureBlockingIterator
s.After this method returns, any subsequent calls to
next(Object)
MUST throw anException
. All current and futureBlockingIterator
s created by thisBlockingIterable
MUST eventually returnfalse
from the varioushasNext
methods.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.lang.Exception
- If closure failed.
-
-