Package io.helidon.common.reactive.valve
Class Tank<T>
- java.lang.Object
-
- io.helidon.common.reactive.valve.Tank<T>
-
- Type Parameters:
T
- a type of items produced byValve
API
- All Implemented Interfaces:
Pausable
,Valve<T>
,AutoCloseable
,Iterable<T>
,Collection<T>
,BlockingQueue<T>
,Queue<T>
public class Tank<T> extends Object implements Valve<T>, BlockingQueue<T>, AutoCloseable
Tank of events is a closeable FIFO queue with a limited size implementingValve
reactive API.
-
-
Constructor Summary
Constructors Constructor Description Tank(int capacity)
Creates new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(T t)
boolean
addAll(Collection<? extends T> c)
void
clear()
void
close()
boolean
contains(Object o)
boolean
containsAll(Collection<?> c)
int
drainTo(Collection<? super T> c)
int
drainTo(Collection<? super T> c, int maxElements)
T
element()
void
forEach(Consumer<? super T> action)
void
handle(BiConsumer<T,Pausable> onData, Consumer<Throwable> onError, Runnable onComplete)
Register data handlers (callbacks).boolean
isEmpty()
Iterator<T>
iterator()
boolean
offer(T t)
boolean
offer(T t, long timeout, TimeUnit unit)
void
pause()
Pause data chunks flow untilPausable.resume()
.T
peek()
T
poll()
T
poll(long timeout, TimeUnit unit)
void
put(T t)
Inserts the specified element at the tail of this queue, waiting for space to become available if the queue is full.int
remainingCapacity()
T
remove()
boolean
remove(Object o)
boolean
removeAll(Collection<?> c)
boolean
removeIf(Predicate<? super T> filter)
void
resume()
Resume data chunks flow afterPausable.pause()
.boolean
retainAll(Collection<?> c)
int
size()
Spliterator<T>
spliterator()
T
take()
Object[]
toArray()
<T1> T1[]
toArray(T1[] a)
void
whenDrain(Runnable drainHandler)
Provided handler is called a single time when internal capacity is maximally half full and instance is not closed.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, stream, toArray
-
-
-
-
Method Detail
-
whenDrain
public void whenDrain(Runnable drainHandler)
Provided handler is called a single time when internal capacity is maximally half full and instance is not closed.- Parameters:
drainHandler
- an handler of drain event- Throws:
NullPointerException
- ifdrainHandler
isnull
-
pause
public void pause()
Description copied from interface:Pausable
Pause data chunks flow untilPausable.resume()
.
-
resume
public void resume()
Description copied from interface:Pausable
Resume data chunks flow afterPausable.pause()
.
-
handle
public void handle(BiConsumer<T,Pausable> onData, Consumer<Throwable> onError, Runnable onComplete)
Description copied from interface:Valve
Register data handlers (callbacks).
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
add
public boolean add(T t)
- Specified by:
add
in interfaceBlockingQueue<T>
- Specified by:
add
in interfaceCollection<T>
- Specified by:
add
in interfaceQueue<T>
-
addAll
public boolean addAll(Collection<? extends T> c)
- Specified by:
addAll
in interfaceCollection<T>
-
offer
public boolean offer(T t)
-
put
public void put(T t) throws InterruptedException
Inserts the specified element at the tail of this queue, waiting for space to become available if the queue is full.- Specified by:
put
in interfaceBlockingQueue<T>
- Throws:
InterruptedException
NullPointerException
IllegalArgumentException
- if Tank is closed
-
offer
public boolean offer(T t, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
offer
in interfaceBlockingQueue<T>
- Throws:
InterruptedException
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<T>
-
take
public T take() throws InterruptedException
- Specified by:
take
in interfaceBlockingQueue<T>
- Throws:
InterruptedException
-
poll
public T poll(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
poll
in interfaceBlockingQueue<T>
- Throws:
InterruptedException
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceBlockingQueue<T>
- Specified by:
remove
in interfaceCollection<T>
-
drainTo
public int drainTo(Collection<? super T> c)
- Specified by:
drainTo
in interfaceBlockingQueue<T>
-
drainTo
public int drainTo(Collection<? super T> c, int maxElements)
- Specified by:
drainTo
in interfaceBlockingQueue<T>
-
removeIf
public boolean removeIf(Predicate<? super T> filter)
- Specified by:
removeIf
in interfaceCollection<T>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAll
in interfaceCollection<T>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAll
in interfaceCollection<T>
-
size
public int size()
- Specified by:
size
in interfaceCollection<T>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<T>
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacity
in interfaceBlockingQueue<T>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interfaceCollection<T>
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceBlockingQueue<T>
- Specified by:
contains
in interfaceCollection<T>
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection<T>
-
toArray
public <T1> T1[] toArray(T1[] a)
- Specified by:
toArray
in interfaceCollection<T>
-
spliterator
public Spliterator<T> spliterator()
- Specified by:
spliterator
in interfaceCollection<T>
- Specified by:
spliterator
in interfaceIterable<T>
-
-