<commit_before>package com.neverwinterdp.scribengin.storage.kafka.sink;

import com.neverwinterdp.kafka.producer.AckKafkaWriter;
import com.neverwinterdp.kafka.producer.KafkaWriter;
import com.neverwinterdp.scribengin.storage.PartitionStreamConfig;
import com.neverwinterdp.scribengin.storage.Record;
import com.neverwinterdp.scribengin.storage.sink.SinkPartitionStreamWriter;

//TODO: Allow the writer write to the assigned partition and configure the send time out
public class KafkaSinkPartitionStreamWriter implements SinkPartitionStreamWriter {
  private PartitionStreamConfig descriptor;
  private KafkaWriter writer ;
  private String topic;
  
  public KafkaSinkPartitionStreamWriter(PartitionStreamConfig descriptor) {
    this.descriptor = descriptor;
    this.writer = new AckKafkaWriter(descriptor.attribute("name"), descriptor.attribute("broker.list")) ;
    this.topic = descriptor.attribute("topic");
  }
  
  @Override
  public void append(Record record) throws Exception {
    writer.send(topic, record, 5000);
  }


  @Override
  public void close() throws Exception {
    writer.close();
  }

  @Override
  public void rollback() throws Exception {
  }

  @Override
  public void commit() throws Exception {
    writer.commit();
  }

  @Override
  public void prepareCommit() {

  }

  @Override<commit_msg>fix kafka stream commit, flush buffer in prepare phase<commit_after>package com.neverwinterdp.scribengin.storage.kafka.sink;

import com.neverwinterdp.kafka.producer.AckKafkaWriter;
import com.neverwinterdp.kafka.producer.KafkaWriter;
import com.neverwinterdp.scribengin.storage.PartitionStreamConfig;
import com.neverwinterdp.scribengin.storage.Record;
import com.neverwinterdp.scribengin.storage.sink.SinkPartitionStreamWriter;

//TODO: Allow the writer write to the assigned partition and configure the send time out
public class KafkaSinkPartitionStreamWriter implements SinkPartitionStreamWriter {
  private PartitionStreamConfig descriptor;
  private KafkaWriter writer ;
  private String topic;
  
  public KafkaSinkPartitionStreamWriter(PartitionStreamConfig descriptor) {
    this.descriptor = descriptor;
    this.writer = new AckKafkaWriter(descriptor.attribute("name"), descriptor.attribute("broker.list")) ;
    this.topic = descriptor.attribute("topic");
  }
  
  @Override
  public void append(Record record) throws Exception {
    writer.send(topic, record, 5000);
  }


  @Override
  public void close() throws Exception {
    writer.close();
  }

  @Override
  public void rollback() throws Exception {
  }

  @Override
  public void commit() throws Exception {
  }

  @Override
  public void prepareCommit() throws Exception {
    writer.commit();
  }

  @Override
{'fraction_non_alphanumeric': 0.08453303802141011, 'fraction_numerical': 0.0029531192321889995, 'mean_word_length': 4.942982456140351, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3442831', 'n_tokens_mistral': 774, 'n_tokens_neox': 760, 'n_words': 183}