I'm implementing a SerialDataEventListener from PI4J and need to receive packets of length 16 bytes from serial port. My listener waits until at least 16 bytes have arrived and sends those bytes to some packet processor.
But I'm wondering: what if PI4J calls my listener twice for two events of -let's say- 14 and 2 bytes? does PI4J wait (blocks) until I process the first 10 bytes?
Even if I use a SynchronizedDeque, it doesn't help as it is matter of which listener callback (for 2 bytes or for 14 bytes) will call the deque.add()'s method first.
If PI4J does not wait/block, I see no way of synchronizing with 100% certainty about order bytes while waiting for more than 1 byte.