<commit_before>/*
 * Copyright 2015-2016 Dark Phoenixs (Open-Source Organization).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.darkphoenixs.kafka.core;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.PartitionInfo;

import java.util.List;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;

/**
 * <p>Title: KafkaMessageNewSender</p>
 * <p>Description: Kafka消息新发送器</p>
 *
 * @param <K> the type of message key
 * @param <V> the type of message value
 * @author Victor.Zxy
 * @version 1.4.0
 * @see KafkaMessageSender
 * @since 2016 /7/25.
 */
public class KafkaMessageNewSender<K, V> implements KafkaMessageSender<K, V> {

    /**
     * Atomic singleton instance.
     */
    private static final AtomicReference<KafkaMessageNewSender> instance = new AtomicReference<>();

    /**
     * The producer is thread safe and sharing a single producer instance
     * across threads will generally be faster than having multiple instances.
     */
    private final KafkaProducer<K, V> kafkaProducer;

    /**
     * @param properties the properties
     */
    private KafkaMessageNewSender(Properties properties) {

        kafkaProducer = new KafkaProducer<>(properties);
    }

    /**
     * Gets or Create instance.
     *
     * @param properties the properties
     * @return the or create instance
     */
    public static KafkaMessageNewSender getOrCreateInstance(Properties properties) {

        if (instance.get() == null)

            instance.set(new KafkaMessageNewSender(properties));

        return instance.get();
    }

    /**
     * Gets topic partitions.
     *
     * @param topic the topic
     * @return the partitions
     */
    public List<PartitionInfo> getPartitions(String topic) {

        return kafkaProducer.partitionsFor(topic);
    }

    @Override
    public void send(String topic, V value) {

        kafkaProducer.send(new ProducerRecord<K, V>(topic, value));
    }

    @Override
    public void sendWithKey(String topic, K key, V value) {

        kafkaProducer.send(new ProducerRecord<>(topic, key, value));
    }

    @Override
    public void close() {

        // flush the producer
        kafkaProducer.flush();
    }

    @Override<commit_msg>fix issue<commit_after>/*
 * Copyright 2015-2016 <NAME> (Open-Source Organization).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.darkphoenixs.kafka.core;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.PartitionInfo;

import java.util.List;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;

/**
 * <p>Title: KafkaMessageNewSender</p>
 * <p>Description: Kafka消息新发送器</p>
 *
 * @param <K> the type of message key
 * @param <V> the type of message value
 * @author Victor.Zxy
 * @version 1.4.0
 * @see KafkaMessageSender
 * @since 2016 /7/25.
 */
public class KafkaMessageNewSender<K, V> implements KafkaMessageSender<K, V> {

    /**
     * Atomic singleton instance.
     */
    private static final AtomicReference<KafkaMessageNewSender> instance = new AtomicReference<KafkaMessageNewSender>();

    /**
     * The producer is thread safe and sharing a single producer instance
     * across threads will generally be faster than having multiple instances.
     */
    private final KafkaProducer<K, V> kafkaProducer;

    /**
     * @param properties the properties
     */
    private KafkaMessageNewSender(Properties properties) {

        kafkaProducer = new KafkaProducer<K, V>(properties);
    }

    /**
     * Gets or Create instance.
     *
     * @param properties the properties
     * @return the or create instance
     */
    public static KafkaMessageNewSender getOrCreateInstance(Properties properties) {

        if (instance.get() == null)

            instance.set(new KafkaMessageNewSender(properties));

        return instance.get();
    }

    /**
     * Gets topic partitions.
     *
     * @param topic the topic
     * @return the partitions
     */
    public List<PartitionInfo> getPartitions(String topic) {

        return kafkaProducer.partitionsFor(topic);
    }

    @Override
    public void send(String topic, V value) {

        kafkaProducer.send(new ProducerRecord<K, V>(topic, value));
    }

    @Override
    public void sendWithKey(String topic, K key, V value) {

        kafkaProducer.send(new ProducerRecord<K, V>(topic, key, value));
    }

    @Override
    public void close() {

        // flush the producer
        kafkaProducer.flush();
    }

    @Override
{'fraction_non_alphanumeric': 0.09657102869139259, 'fraction_numerical': 0.007697690692792162, 'mean_word_length': 3.1159107271418285, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3436980', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1585, 'n_words': 507}