public Optional < List < NmeaMessage > > add ( NmeaMessage nmea ) { // use compare-and-swap semantics instead of synchronizing to squeak a // bit more performance out of this. Contention is expected to be low so // this should help. while ( true ) { if ( adding . compareAndSet ( false , true ) ) { Optional < List < NmeaMessage >> result = doAdd ( nmea ) ; adding . set ( false ) ; return result ; } } }
Returns the complete message only once the whole group of messages has arrived otherwise returns null .