public void produce ( final ConsumerRecords < byte [ ] , byte [ ] > element ) throws InterruptedException , WakeupException , ClosedException { checkNotNull ( element ) ; synchronized ( lock ) { while ( next != null && ! wakeupProducer ) { lock . wait ( ) ; } wakeupProducer = false ; // if there is still an element, we must have been woken up if ( next != null ) { throw new WakeupException ( ) ; } // if there is no error, then this is open and can accept this element else if ( error == null ) { next = element ; lock . notifyAll ( ) ; } // an error marks this as closed for the producer else { throw new ClosedException ( ) ; } } }
Hands over an element from the producer . If the Handover already has an element that was not yet picked up by the consumer thread this call blocks until the consumer picks up that previous element .