public void add ( BytesRef payload ) { // check space first // ba is the backing array for data if ( payload . length ( ) > ba . available ( ) ) { if ( autoFlush ) { flush ( ) ; } else { throw new EsHadoopIllegalStateException ( String . format ( "Auto-flush disabled and bulk buffer full; disable manual flush or increase " + "capacity [current size %s]; bailing out" , ba . capacity ( ) ) ) ; } } data . copyFrom ( payload ) ; dataEntries ++ ; if ( bufferEntriesThreshold > 0 && dataEntries >= bufferEntriesThreshold ) { if ( autoFlush ) { flush ( ) ; } else { // handle the corner case of manual flush that occurs only after the buffer is completely full (think size of 1) if ( dataEntries > bufferEntriesThreshold ) { throw new EsHadoopIllegalStateException ( String . format ( "Auto-flush disabled and maximum number of entries surpassed; disable manual " + "flush or increase capacity [current size %s]; bailing out" , bufferEntriesThreshold ) ) ; } } } }
Adds an entry to the bulk request potentially flushing if the request reaches capacity .