A3PipeInstantiation and Capacity of the BoundedSynchedPipe
Not sure if its a real bug here, but while choosing the need pipe following code is executed:
if (pipe.capacity() != 0) {
new UnboundedSynchedPipe<T>(pipe.getSourcePort(), pipe.getTargetPort());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Connected (bounded) " + pipe.getSourcePort() + " and " + pipe.getTargetPort());
}
} else {
new BoundedSynchedPipe<T>(pipe.getSourcePort(), pipe.getTargetPort(), pipe.capacity());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Connected (unbounded) " + pipe.getSourcePort() + " and " + pipe.getTargetPort());
}
Intuitively I would think that a size of zero (or less) would imply an unbounded pipe and a real capacity could instead be used the instantiate a bounded pipe. Here it's the other way around.
The second issue affects the capacity.
Looking further in the code of the BoundedSynchedPipe
I found that the function getCapacity()
returns the capacity given to the constructor, but the used ObservableSpScArrayQueue
,(which extends the ConcurrentCircularArrayQueue
) does this:
public ConcurrentCircularArrayQueue(int capacity) {
int actualCapacity = Pow2.roundToPowerOfTwo(capacity);
mask = actualCapacity - 1;
buffer = SparsePaddedCircularArrayOffsetCalculator.allocate(actualCapacity);
}
So the capacity from getCapacity()
and the real capacity may differ.
A simple example would be:
ObservableSpScArrayQueue<Object> queue = new ObservableSpScArrayQueue<Object>(1);
System.out.println(queue.offer(1));
System.out.println(queue.offer(2));
System.out.println(queue.offer(3));
System.out.println(queue.offer(4));
System.out.println(queue.offer(5));
which results in:
- true
- true
- true
- true
- false