<commit_before>package at.ac.tuwien.dsg.myx.monitor.comp;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import at.ac.tuwien.dsg.myx.monitor.MyxProperties;
import at.ac.tuwien.dsg.myx.monitor.ed.EventDispatcher;
import at.ac.tuwien.dsg.myx.monitor.em.EventManager;
import at.ac.tuwien.dsg.myx.util.MyxMonitoringUtils;
import edu.uci.isr.myx.fw.AbstractMyxSimpleBrick;
import edu.uci.isr.myx.fw.IMyxName;

public class EventDispatcherComponent extends AbstractMyxSimpleBrick {

    public static final IMyxName INTERFACE_NAME_OUT_EVENTMANAGER = MyxMonitoringUtils.createName("event-manager");

    private ExecutorService executor;
    List<EventDispatcher> dispatchers;

    @Override
    public Object getServiceObject(IMyxName interfaceName) {
        return null;
    }

    @Override
    public void init() {
        Properties initProperties = MyxMonitoringUtils.getInitProperties(this);

        EventManager eventManager = (EventManager) MyxMonitoringUtils.getFirstRequiredServiceObject(this,
                INTERFACE_NAME_OUT_EVENTMANAGER);

        String[] dispatcherClassNames = (String[]) initProperties.get(MyxProperties.EVENT_DISPATCHER_CLASSES);

        executor = Executors.newCachedThreadPool();
        dispatchers = getDispatchers(dispatcherClassNames, eventManager);
    }

    /**
     * Get all {@link EventDispatcher} instances.
     * 
     * @param archRuntimeId
     * @param hostId
     * @param eventManager
     * @param dispatcherClassNames
     */
    private List<EventDispatcher> getDispatchers(String[] dispatcherClassNames, EventManager eventManager) {
        List<EventDispatcher> dispatchers = new ArrayList<>();
        if (dispatcherClassNames != null) {
            for (String dispatcherClassName : dispatcherClassNames) {
                try {
                    Class<?> eventDispatcherClass = Class.forName(dispatcherClassName);
                    if (!EventDispatcher.class.isAssignableFrom(eventDispatcherClass)) {
                        // we ignore non compatible dispatchers
                        continue;
                    }
                    Constructor<?> c = eventDispatcherClass.getConstructor(new Class<?>[] { String.class, String.class,
                            EventManager.class });
                    dispatchers.add((EventDispatcher) c.newInstance(eventManager));
                } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException
                        | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // we ignore non compatible dispatchers
                }
            }
        }
        return dispatchers;
    }

    @Override
    public void begin() {<commit_msg>fixed bug where not event dispatchers were spawned due to wrong constructor usage<commit_after>package at.ac.tuwien.dsg.myx.monitor.comp;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import at.ac.tuwien.dsg.myx.monitor.MyxProperties;
import at.ac.tuwien.dsg.myx.monitor.ed.EventDispatcher;
import at.ac.tuwien.dsg.myx.monitor.em.EventManager;
import at.ac.tuwien.dsg.myx.util.MyxMonitoringUtils;
import edu.uci.isr.myx.fw.AbstractMyxSimpleBrick;
import edu.uci.isr.myx.fw.IMyxName;

public class EventDispatcherComponent extends AbstractMyxSimpleBrick {

    public static final IMyxName INTERFACE_NAME_OUT_EVENTMANAGER = MyxMonitoringUtils.createName("event-manager");

    private ExecutorService executor;
    List<EventDispatcher> dispatchers;

    @Override
    public Object getServiceObject(IMyxName interfaceName) {
        return null;
    }

    @Override
    public void init() {
        Properties initProperties = MyxMonitoringUtils.getInitProperties(this);

        EventManager eventManager = (EventManager) MyxMonitoringUtils.getFirstRequiredServiceObject(this,
                INTERFACE_NAME_OUT_EVENTMANAGER);

        String[] dispatcherClassNames = (String[]) initProperties.get(MyxProperties.EVENT_DISPATCHER_CLASSES);

        executor = Executors.newCachedThreadPool();
        dispatchers = getDispatchers(dispatcherClassNames, eventManager);
    }

    /**
     * Get all {@link EventDispatcher} instances.
     * 
     * @param archRuntimeId
     * @param hostId
     * @param eventManager
     * @param dispatcherClassNames
     */
    private List<EventDispatcher> getDispatchers(String[] dispatcherClassNames, EventManager eventManager) {
        List<EventDispatcher> dispatchers = new ArrayList<>();
        if (dispatcherClassNames != null) {
            for (String dispatcherClassName : dispatcherClassNames) {
                try {
                    Class<?> eventDispatcherClass = Class.forName(dispatcherClassName);
                    if (!EventDispatcher.class.isAssignableFrom(eventDispatcherClass)) {
                        // we ignore non compatible dispatchers
                        continue;
                    }
                    Constructor<?> c = eventDispatcherClass.getConstructor(new Class<?>[] { EventManager.class });
                    dispatchers.add((EventDispatcher) c.newInstance(eventManager));
                } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException
                        | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // we ignore non compatible dispatchers
                }
            }
        }
        return dispatchers;
    }

    @Override
    public void begin() {
{'fraction_non_alphanumeric': 0.08383838383838384, 'fraction_numerical': 0.0, 'mean_word_length': 2.9370444002650764, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '3527882', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1539, 'n_words': 296}