<commit_before>package org.perfcake.message.sender;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Map;
import java.util.Random;

import org.apache.log4j.Logger;
import org.infinispan.cakery.MemcachedClient;
import org.perfcake.message.Message;
import org.perfcake.reporting.MeasurementUnit;

/**
 * An abstract sender for Hot Rod.
 * <p/>
 */
public class IspnCakeryMemcachedSender extends AbstractSender {

    private Logger log = Logger.getLogger(IspnCakeryMemcachedSender.class);
    // Every thread in the scenario is about to run init() but we need to run it only once.
    private boolean initDone = false;
    private int numOfEntries = 1;
    private int r = 0; // random

    private int requestSleepTimeMillis = 0;
    private Random rand = new Random();

    private String perfcakeAgentHost;

    static final String ENCODING = "UTF-8";
    private MemcachedClient mc1;


    /**
     * This method is called once by each thread for needed initializations.
     * It depends on test logic, but if we need firstly put data into the cache
     * and then process only gets, do filling part of init() only once
     * <p/>
     * initDone system property is used for driving this logic
     * when the first thread set it up, other threads can see it
     *
     * @throws Exception
     */
    @Override
    public void init() throws Exception {

        requestSleepTimeMillis = Integer.parseInt(System.getProperty("requestSleepTimeMillis"));

        log.info("requestSleepTimeMillis set to: " + requestSleepTimeMillis);

        numOfEntries = Integer.parseInt(System.getProperty("numberOfEntries"));
        initDone = Boolean.parseBoolean(System.getProperty("initDone"));

        perfcakeAgentHost = System.getProperty("perfcake.agent.host").replace(".", "");

        mc1 = new MemcachedClient(ENCODING, System.getProperty("memcached.host"), 11211, 10000); // to run against

        // need to decide according to some parent object because every thread has it's own init
        if (!initDone) {

            log.info("Setting system property initDone to value: true... other threads should see it.");
            // immediately let other threads know that this is Thread responsible for filling cache
            System.setProperty("initDone", "true");
            initDone = true;
            requestSleepTimeMillis = Integer.parseInt(System.getProperty("requestSleepTimeMillis"));

            long start = System.currentTimeMillis();
            log.info("Doing Init in " + this.getClass().getName());

            for (int i = 1; i <= numOfEntries; i++) {

                String entryKey = "person" + i + "appendix" + perfcakeAgentHost;
                String jsonPerson = createJsonPersonString(
                        "org.infinispan.odata.Person", "person" + i, "MALE", "John", "Smith", 24);

                if (i % 100 == 0) {
                    log.info("\n" + i + " entryKey = " + entryKey + "\n");
                }

                mc1.set(entryKey, jsonPerson);
            }

            log.info("\n Init method took: " + (System.currentTimeMillis() - start));
        } else {
            log.info("Init() method was already initialized by the first thread, skipping to doSend().");
        }

        log.info("\nThis is MEMCACHED Sender... init() was done, sleeping 30 seconds " +
                "to wait for other servers in a cluster\n");
        Thread.sleep(30000);

    }

    @Override
    public void close() {
        // nop
    }

    @Override
    public void preSend(final Message message, final Map<String, String> properties) throws Exception {
        super.preSend(message, properties);
    }

    @Override
    public Serializable doSend(final Message message, final Map<String, String> properties, final MeasurementUnit mu) throws Exception {
<commit_msg>wait 1 minute after init in Memcached Sender<commit_after>package org.perfcake.message.sender;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Map;
import java.util.Random;

import org.apache.log4j.Logger;
import org.infinispan.cakery.MemcachedClient;
import org.perfcake.message.Message;
import org.perfcake.reporting.MeasurementUnit;

/**
 * An abstract sender for Hot Rod.
 * <p/>
 */
public class IspnCakeryMemcachedSender extends AbstractSender {

    private Logger log = Logger.getLogger(IspnCakeryMemcachedSender.class);
    // Every thread in the scenario is about to run init() but we need to run it only once.
    private boolean initDone = false;
    private int numOfEntries = 1;
    private int r = 0; // random

    private int requestSleepTimeMillis = 0;
    private Random rand = new Random();

    private String perfcakeAgentHost;

    static final String ENCODING = "UTF-8";
    private MemcachedClient mc1;


    /**
     * This method is called once by each thread for needed initializations.
     * It depends on test logic, but if we need firstly put data into the cache
     * and then process only gets, do filling part of init() only once
     * <p/>
     * initDone system property is used for driving this logic
     * when the first thread set it up, other threads can see it
     *
     * @throws Exception
     */
    @Override
    public void init() throws Exception {

        requestSleepTimeMillis = Integer.parseInt(System.getProperty("requestSleepTimeMillis"));

        log.info("requestSleepTimeMillis set to: " + requestSleepTimeMillis);

        numOfEntries = Integer.parseInt(System.getProperty("numberOfEntries"));
        initDone = Boolean.parseBoolean(System.getProperty("initDone"));

        perfcakeAgentHost = System.getProperty("perfcake.agent.host").replace(".", "");

        mc1 = new MemcachedClient(ENCODING, System.getProperty("memcached.host"), 11211, 10000); // to run against

        // need to decide according to some parent object because every thread has it's own init
        if (!initDone) {

            log.info("Setting system property initDone to value: true... other threads should see it.");
            // immediately let other threads know that this is Thread responsible for filling cache
            System.setProperty("initDone", "true");
            initDone = true;
            requestSleepTimeMillis = Integer.parseInt(System.getProperty("requestSleepTimeMillis"));

            long start = System.currentTimeMillis();
            log.info("Doing Init in " + this.getClass().getName());

            for (int i = 1; i <= numOfEntries; i++) {

                String entryKey = "person" + i + "appendix" + perfcakeAgentHost;
                String jsonPerson = createJsonPersonString(
                        "org.infinispan.odata.Person", "person" + i, "MALE", "John", "Smith", 24);

                if (i % 100 == 0) {
                    log.info("\n" + i + " entryKey = " + entryKey + "\n");
                }

                mc1.set(entryKey, jsonPerson);
            }

            log.info("\n Init method took: " + (System.currentTimeMillis() - start));

            // sleep just in this loader/init thread
            log.info("\nThis is MEMCACHED Sender... init() was done, sleeping 60 seconds " +
                    "to wait for other servers in a cluster\n");
            Thread.sleep(60000);

        } else {
            log.info("Init() method was already initialized by the first thread, skipping to doSend().");
        }
    }

    @Override
    public void close() {
        // nop
    }

    @Override
    public void preSend(final Message message, final Map<String, String> properties) throws Exception {
        super.preSend(message, properties);
    }

    @Override
    public Serializable doSend(final Message message, final Map<String, String> properties, final MeasurementUnit mu) throws Exception {

{'fraction_non_alphanumeric': 0.1006426735218509, 'fraction_numerical': 0.008354755784061696, 'mean_word_length': 2.6190697674418604, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '2145374', 'n_tokens_mistral': 2152, 'n_tokens_neox': 2036, 'n_words': 683}