<commit_before>package gr.ntua.vision.monitoring.sinks;

import gr.ntua.vision.monitoring.events.MonitoringEvent;
import gr.ntua.vision.monitoring.sockets.Socket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * This is providing utility methods for transmitting an event through a socket.
 */
@SuppressWarnings("unused")
abstract class AbstractSink implements EventSink {
    /***/
    private static final Logger log    = LoggerFactory.getLogger(AbstractSink.class);
    /***/
    private volatile boolean    closed = false;
    /***/
    private final Socket        sock;


    /**
     * Constructor.
     * 
     * @param sock
     */
    public AbstractSink(final Socket sock) {
        this.sock = sock;
    }


    /**
     * @see gr.ntua.vision.monitoring.sinks.EventSink#close()
     */
    @Override
    public void close() {
        sock.close();
        closed = true;
    }


    /**
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "#<" + getClass().getSimpleName() + ": " + sock + ">";
    }


    /**
     * Transmit the string.
     * 
     * @param str
     *            a string.
     */
    protected void send(final String str) {
        if (closed)
            return;

        // log.trace("sending: {}", str);
        sock.send(str);
    }


    /**
     * Serialize the event.
     * 
     * @param e
     *            the event.
     * @return a string representation for the event.
     */
    protected String serialize(final MonitoringEvent e) {
        if (sock.isZMQPUB()) {
            final String topic = e.topic();

            if (topic == null)
                throw new Error("event with null topic");

            return topic + " " + e.serialize();
        }

        return e.serialize();
    }
}<commit_msg>for non-topiced events, make up a special one<commit_after>package gr.ntua.vision.monitoring.sinks;

import gr.ntua.vision.monitoring.events.MonitoringEvent;
import gr.ntua.vision.monitoring.sockets.Socket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * This is providing utility methods for transmitting an event through a socket.
 */
@SuppressWarnings("unused")
abstract class AbstractSink implements EventSink {
    /***/
    private static final Logger log    = LoggerFactory.getLogger(AbstractSink.class);
    /***/
    private volatile boolean    closed = false;
    /***/
    private final Socket        sock;


    /**
     * Constructor.
     * 
     * @param sock
     */
    public AbstractSink(final Socket sock) {
        this.sock = sock;
    }


    /**
     * @see gr.ntua.vision.monitoring.sinks.EventSink#close()
     */
    @Override
    public void close() {
        sock.close();
        closed = true;
    }


    /**
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "#<" + getClass().getSimpleName() + ": " + sock + ">";
    }


    /**
     * Transmit the string.
     * 
     * @param str
     *            a string.
     */
    protected void send(final String str) {
        if (closed)
            return;

        // log.trace("sending: {}", str);
        sock.send(str);
    }


    /**
     * Serialize the event.
     * 
     * @param e
     *            the event.
     * @return a string representation for the event.
     */
    protected String serialize(final MonitoringEvent e) {
        final String ser = e.serialize();

        if (sock.isZMQPUB()) {
            final String topic = e.topic();

            return (topic != null ? topic : "*") + " " + ser;
        }

        return ser;
    }
}
{'fraction_non_alphanumeric': 0.12709305517430688, 'fraction_numerical': 0.0010979961570134504, 'mean_word_length': 1.8625294579732914, 'pattern_counts': {'":': 2, '<': 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': '6021994', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1069, 'n_words': 258}