<commit_before><commit_msg>add a convenient BatchProcessEventListener to broadcast a poison record at the end of batch execution<commit_after>package org.easybatch.core.util;

import org.easybatch.core.api.RecordDispatcher;
import org.easybatch.core.api.event.global.BatchProcessEventListener;
import org.easybatch.core.record.PoisonRecord;

/**
 * A utility batch event listener that broadcasts a poison record at the end of batch
 * using a delegate {@link RecordDispatcher}.
 *
 * @author <NAME> (<EMAIL>)
 */
public class PoisonRecordBroadcaster implements BatchProcessEventListener {

    private RecordDispatcher recordDispatcher;

    /**
     * Create a new {@link PoisonRecordBroadcaster}.
     * @param recordDispatcher the delegate {@link RecordDispatcher} used to dispatch the poison record
     */
    public PoisonRecordBroadcaster(RecordDispatcher recordDispatcher) {
        this.recordDispatcher = recordDispatcher;
    }

    @Override
    public void beforeBatchStart() {

    }

    @Override
    public void afterBatchEnd() {
        try {
            recordDispatcher.dispatchRecord(new PoisonRecord());
        } catch (Exception e) {
            throw new RuntimeException("Unable to broadcast poison record");
        }
    }

    @Override
    public void onException(Throwable throwable) {

    }
}
{'fraction_non_alphanumeric': 0.07849056603773585, 'fraction_numerical': 0.0, 'mean_word_length': 3.6041666666666665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3526605', 'n_tokens_mistral': 350, 'n_tokens_neox': 322, 'n_words': 101}