<commit_before>package com.codespair.mockstocks.service.kafka.spring.producer;

import com.codespair.mockstocks.config.GeneratorConfigProperties;
import com.codespair.mockstocks.config.KafkaConfigProperties;
import com.codespair.mockstocks.model.StockQuote;
import com.codespair.mockstocks.service.utils.StockExchangeMaps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Random;

/**
 * This class on startup try to start generating random stockquotes unless disabled(default) in the configuration
 */
@Slf4j
@Service
public class StockQuoteGenerator {

    @Autowired
    private GeneratorConfigProperties generatorConfigProperties;

    @Autowired
    private KafkaConfigProperties kafkaConfigProperties;

    @Autowired
    private StockExchangeMaps stockExchangeMaps;

    @Autowired
    private StockQuoteProducerClient kafkaProducerClient;

    @Async
    public void startGenerator() throws InterruptedException {
        if(generatorConfigProperties.isEnabled()) {
            log.info("Starting random quote generation in {} milliseconds, with interval: {} milliseconds between each quote",
                    generatorConfigProperties.getStartDelayMilliseconds(), generatorConfigProperties.getIntervalMilliseconds());
            try {
                Thread.sleep(generatorConfigProperties.getStartDelayMilliseconds());
                while(true) {
                    StockQuote stockQuote = stockExchangeMaps.randomStockSymbol();
                    stockQuote = enrich(stockQuote);
                    kafkaProducerClient.send(kafkaConfigProperties.getStockQuote().getTopic(), null, stockQuote);
                    Thread.sleep(generatorConfigProperties.getIntervalMilliseconds());
                }
            }
            catch(InterruptedException e) {
                log.warn(e.getMessage());
                throw e;
            }
        }
    }

    public StockQuote enrich(StockQuote stockQuote) {
        Random random = new Random();
        int upTo = 1000;
        stockQuote.setHigh(new BigDecimal(random.nextFloat() * upTo));
        stockQuote.setLow(new BigDecimal(random.nextFloat() * upTo));
        stockQuote.setLastTrade(new BigDecimal(random.nextFloat() * upTo));
        return stockQuote;
    }
}<commit_msg>some work improving kafka producer, moving away from spring kafka<commit_after>package com.codespair.mockstocks.service.kafka.spring.producer;

import com.codespair.mockstocks.config.GeneratorConfigProperties;
import com.codespair.mockstocks.config.KafkaConfigProperties;
import com.codespair.mockstocks.model.StockQuote;
import com.codespair.mockstocks.service.utils.StockExchangeMaps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.PreDestroy;
import java.math.BigDecimal;
import java.util.Random;

/**
 * This class on startup try to start generating random stockquotes unless disabled(default) in the configuration
 */
@Slf4j
@Service
public class StockQuoteGenerator {

    @Autowired
    private GeneratorConfigProperties generatorConfigProperties;

    @Autowired
    private KafkaConfigProperties kafkaConfigProperties;

    @Autowired
    private StockExchangeMaps stockExchangeMaps;

    @Autowired
    private StockQuoteProducerClient kafkaProducerClient;

    @Async
    public void startGenerator() throws InterruptedException {
        if(generatorConfigProperties.isEnabled()) {
            log.info("Starting random quote generation in {} milliseconds, with interval: {} milliseconds between each quote",
                    generatorConfigProperties.getStartDelayMilliseconds(), generatorConfigProperties.getIntervalMilliseconds());
            try {
                Thread.sleep(generatorConfigProperties.getStartDelayMilliseconds());
                while(true) {
                    StockQuote stockQuote = stockExchangeMaps.randomStockSymbol();
                    stockQuote = enrich(stockQuote);
                    kafkaProducerClient.send(kafkaConfigProperties.getStockQuote().getTopic(), null, stockQuote);
                    Thread.sleep(generatorConfigProperties.getIntervalMilliseconds());
                }
            }
            catch(InterruptedException e) {
                log.warn(e.getMessage());
                throw e;
            }
        }
    }

    public StockQuote enrich(StockQuote stockQuote) {
        Random random = new Random();
        int upTo = 1000;
        stockQuote.setHigh(new BigDecimal(random.nextFloat() * upTo));
        stockQuote.setLow(new BigDecimal(random.nextFloat() * upTo));
        stockQuote.setLastTrade(new BigDecimal(random.nextFloat() * upTo));
        return stockQuote;
    }

    @PreDestroy
    public void closeProducer() {
        kafkaProducerClient.close();
    }
}
{'fraction_non_alphanumeric': 0.08198977585528903, 'fraction_numerical': 0.0027526543452615023, 'mean_word_length': 3.27120067170445, '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': '3234368', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1261, 'n_words': 252}