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

import gr.ntua.vision.monitoring.VismoConfiguration;
import gr.ntua.vision.monitoring.zmq.ZMQFactory;

import org.zeromq.ZContext;


/**
 * Configure and provide the system with the appropriate event sources.
 */
public class EventSourcesFactory {
    /** the configuration object. */
    private final VismoConfiguration  conf;
    /***/
    private final EventSourceListener listener;
    /***/
    private final ZMQFactory          socketFactory;


    /**
     * Constructor.
     * 
     * @param conf
     *            the configuration object.
     * @param listener
     */
    public EventSourcesFactory(final VismoConfiguration conf, final EventSourceListener listener) {
        this(conf, new ZMQFactory(new ZContext()), listener);
    }


    /**
     * Constructor.
     * 
     * @param conf
     *            the configuration object.
     * @param socketFactory
     * @param listener
     */
    public EventSourcesFactory(final VismoConfiguration conf, final ZMQFactory socketFactory, final EventSourceListener listener) {
        this.conf = conf;
        this.socketFactory = socketFactory;
        this.listener = listener;
    }


    /**
     * Setup the sources group for cloud head.
     * 
     * @return an {@link EventSources} object.
     */
    public EventSources buildForCloudHead() {
        return new EventSources().append(localSource()).append(sourceforAddress(withPort(conf.getCloudHeadPort())));
    }


    /**
     * Setup the sources group for cluster head.
     * 
     * @return an {@link EventSources} object.
     */
    public EventSources buildForClusterHead() {
        return new EventSources().append(localSource()).append(sourceforAddress(withPort(conf.getClusterHeadPort())));
    }


    /**
     * Setup the sources group for worker.
     * 
     * @return an {@link EventSources} object.
     */
    public EventSources buildForWorker() {
        return new EventSources().append(localSource());
    }


    /**
     * @return the localhost source.
     */
    private VismoEventSource localSource() {
        return sourceforAddress(conf.getProducersPoint());
    }


    /**
     * @param address
     * @return the event source for given address
     */
    private VismoEventSource sourceforAddress(final String address) {
        return new VismoEventSource(listener, socketFactory.newBoundPullSocket(address),
                socketFactory.newConnectedPushSocket(address));
    }


    /**
     * @param port
     * @return an address bound to all interfaces and the given port.
     */
    private static String withPort(final int port) {
        return "tcp://127.0.0.1:" + port;
    }
}
<commit_msg>binding on all available interfaces<commit_after>package gr.ntua.vision.monitoring.sources;

import gr.ntua.vision.monitoring.VismoConfiguration;
import gr.ntua.vision.monitoring.zmq.ZMQFactory;

import org.zeromq.ZContext;


/**
 * Configure and provide the system with the appropriate event sources.
 */
public class EventSourcesFactory {
    /** the configuration object. */
    private final VismoConfiguration  conf;
    /***/
    private final EventSourceListener listener;
    /***/
    private final ZMQFactory          socketFactory;


    /**
     * Constructor.
     * 
     * @param conf
     *            the configuration object.
     * @param listener
     */
    public EventSourcesFactory(final VismoConfiguration conf, final EventSourceListener listener) {
        this(conf, new ZMQFactory(new ZContext()), listener);
    }


    /**
     * Constructor.
     * 
     * @param conf
     *            the configuration object.
     * @param socketFactory
     * @param listener
     */
    public EventSourcesFactory(final VismoConfiguration conf, final ZMQFactory socketFactory, final EventSourceListener listener) {
        this.conf = conf;
        this.socketFactory = socketFactory;
        this.listener = listener;
    }


    /**
     * Setup the sources group for cloud head.
     * 
     * @return an {@link EventSources} object.
     */
    public EventSources buildForCloudHead() {
        return new EventSources().append(localSource()).append(sourceforAddress(withPort(conf.getCloudHeadPort())));
    }


    /**
     * Setup the sources group for cluster head.
     * 
     * @return an {@link EventSources} object.
     */
    public EventSources buildForClusterHead() {
        return new EventSources().append(localSource()).append(sourceforAddress(withPort(conf.getClusterHeadPort())));
    }


    /**
     * Setup the sources group for worker.
     * 
     * @return an {@link EventSources} object.
     */
    public EventSources buildForWorker() {
        return new EventSources().append(localSource());
    }


    /**
     * @return the localhost source.
     */
    private VismoEventSource localSource() {
        return sourceforAddress(conf.getProducersPoint());
    }


    /**
     * @param address
     * @return the event source for given address
     */
    private VismoEventSource sourceforAddress(final String address) {
        return new VismoEventSource(listener, socketFactory.newBoundPullSocket(address),
                socketFactory.newConnectedPushSocket(address));
    }

    /**
     * Check that we're running on a windows machine :(
     *
     * @return <code>true</code> if we're running on a windows machine.
     */
    private static boolean isWin() {
        return System.getProperty("os.name").toLowerCase().contains("win");
    }

    /**
     * @param port
     * @return an address bound to all interfaces and the given port.
     */
    private static String withPort(final int port) {
        if (isWin())
            return "tcp://127.0.0.1:" + port;

        return "tcp://*:" + port; // bind to all avail ifaces
    }
}

{'fraction_non_alphanumeric': 0.10315825609337453, 'fraction_numerical': 0.0020597322348094747, 'mean_word_length': 2.525105868118572, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '7593734', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1516, 'n_words': 407}