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 byValveAPI
- 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 implementingValvereactive 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 booleanadd(T t)booleanaddAll(Collection<? extends T> c)voidclear()voidclose()booleancontains(Object o)booleancontainsAll(Collection<?> c)intdrainTo(Collection<? super T> c)intdrainTo(Collection<? super T> c, int maxElements)Telement()voidforEach(Consumer<? super T> action)voidhandle(BiConsumer<T,Pausable> onData, Consumer<Throwable> onError, Runnable onComplete)Register data handlers (callbacks).booleanisEmpty()Iterator<T>iterator()booleanoffer(T t)booleanoffer(T t, long timeout, TimeUnit unit)voidpause()Pause data chunks flow untilPausable.resume().Tpeek()Tpoll()Tpoll(long timeout, TimeUnit unit)voidput(T t)Inserts the specified element at the tail of this queue, waiting for space to become available if the queue is full.intremainingCapacity()Tremove()booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanremoveIf(Predicate<? super T> filter)voidresume()Resume data chunks flow afterPausable.pause().booleanretainAll(Collection<?> c)intsize()Spliterator<T>spliterator()Ttake()Object[]toArray()<T1> T1[]toArray(T1[] a)voidwhenDrain(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- ifdrainHandlerisnull
-
pause
public void pause()
Description copied from interface:PausablePause data chunks flow untilPausable.resume().
-
resume
public void resume()
Description copied from interface:PausableResume data chunks flow afterPausable.pause().
-
handle
public void handle(BiConsumer<T,Pausable> onData, Consumer<Throwable> onError, Runnable onComplete)
Description copied from interface:ValveRegister data handlers (callbacks).
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
add
public boolean add(T t)
- Specified by:
addin interfaceBlockingQueue<T>- Specified by:
addin interfaceCollection<T>- Specified by:
addin interfaceQueue<T>
-
addAll
public boolean addAll(Collection<? extends T> c)
- Specified by:
addAllin 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:
putin interfaceBlockingQueue<T>- Throws:
InterruptedExceptionNullPointerExceptionIllegalArgumentException- if Tank is closed
-
offer
public boolean offer(T t, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
offerin interfaceBlockingQueue<T>- Throws:
InterruptedException
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<T>
-
take
public T take() throws InterruptedException
- Specified by:
takein interfaceBlockingQueue<T>- Throws:
InterruptedException
-
poll
public T poll(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
pollin interfaceBlockingQueue<T>- Throws:
InterruptedException
-
remove
public boolean remove(Object o)
- Specified by:
removein interfaceBlockingQueue<T>- Specified by:
removein interfaceCollection<T>
-
drainTo
public int drainTo(Collection<? super T> c)
- Specified by:
drainToin interfaceBlockingQueue<T>
-
drainTo
public int drainTo(Collection<? super T> c, int maxElements)
- Specified by:
drainToin interfaceBlockingQueue<T>
-
removeIf
public boolean removeIf(Predicate<? super T> filter)
- Specified by:
removeIfin interfaceCollection<T>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAllin interfaceCollection<T>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAllin interfaceCollection<T>
-
size
public int size()
- Specified by:
sizein interfaceCollection<T>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<T>
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacityin interfaceBlockingQueue<T>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<T>
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceBlockingQueue<T>- Specified by:
containsin interfaceCollection<T>
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<T>
-
toArray
public <T1> T1[] toArray(T1[] a)
- Specified by:
toArrayin interfaceCollection<T>
-
spliterator
public Spliterator<T> spliterator()
- Specified by:
spliteratorin interfaceCollection<T>- Specified by:
spliteratorin interfaceIterable<T>
-
-