public class Communicator<E>
extends java.lang.Object
We use an unbound queue since for every time user's bolt's executing or spout's emitting tuples, it is possible that unbounded # of tuples could be generated. And we could not stop them since the logic is inside their jars. So in order to avoid enqueue failure, we need an unbound queue.
However, in order to avoid GC issues and keep high performance, we would have a dynamical tuning Queue's expected capacity, see updateExpectedAvailableCapacity() below.
Constructor and Description |
---|
Communicator() |
Communicator(WakeableLooper producer,
WakeableLooper consumer)
Constructor for Communicator
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
int |
drainTo(java.util.Collection<? super E> c)
Removes all available elements from this queue and adds them to the given collection.
|
int |
drainTo(java.util.Collection<? super E> c,
int maxElements) |
void |
expectMoreItems() |
void |
expectNoMoreItems() |
int |
getCapacity() |
int |
getExpectedAvailableCapacity() |
void |
informConsumer() |
void |
informProducer() |
void |
init(int ipcapacity,
int ipexpectedQueueSize,
double ipcurrentSampleWeight) |
boolean |
isEmpty() |
boolean |
offer(E e)
Since it is an unbounded queue, the offer will always return true.
|
E |
peek() |
E |
poll()
Check if there is any item in the queue
|
int |
remainingCapacity() |
void |
setConsumer(WakeableLooper consumer) |
void |
setProducer(WakeableLooper producer) |
int |
size()
Get the number of items in queue
|
void |
updateExpectedAvailableCapacity() |
public Communicator(WakeableLooper producer, WakeableLooper consumer)
producer
- would be waken up when items are consumed from queue,
or set it to null if we don't want producer to be waken upconsumer
- would be waken up when items are produced into queue,
or set it to null if we don't want consumer to be waken uppublic Communicator()
public void setProducer(WakeableLooper producer)
public void setConsumer(WakeableLooper consumer)
public void init(int ipcapacity, int ipexpectedQueueSize, double ipcurrentSampleWeight)
public int size()
public int remainingCapacity()
public E poll()
public boolean offer(E e)
e
- Item to be insertedpublic E peek()
public int getCapacity()
public boolean isEmpty()
public void clear()
public int drainTo(java.util.Collection<? super E> c)
public int drainTo(java.util.Collection<? super E> c, int maxElements)
public void updateExpectedAvailableCapacity()
public int getExpectedAvailableCapacity()
public void expectNoMoreItems()
public void expectMoreItems()
public void informProducer()
public void informConsumer()