<commit_before>package edu.sjsu.mithai.main;

import edu.sjsu.mithai.config.ConfigFileObservable;
import edu.sjsu.mithai.config.Configuration;
import edu.sjsu.mithai.data.DataGenerationTask;
import edu.sjsu.mithai.data.MetadataGenerationTask;
import edu.sjsu.mithai.data.SensorStore;
import edu.sjsu.mithai.mqtt.MQTTDataReceiverTask;
import edu.sjsu.mithai.mqtt.MQTTMetaDataRecieverTask;
import edu.sjsu.mithai.mqtt.MQTTPublisherTask;
import edu.sjsu.mithai.sensors.TemperatureSensor;
import edu.sjsu.mithai.spark.SparkStreamingObject;
import edu.sjsu.mithai.util.TaskManager;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import java.io.File;
import java.io.IOException;
import java.util.Observable;
import java.util.Observer;

import static edu.sjsu.mithai.config.MithaiProperties.EXPORTER_TYPE;
import static edu.sjsu.mithai.config.MithaiProperties.NUMBER_OF_SENSORS;

public class Mithai implements Observer {

    protected static Configuration configuration;
    protected SensorStore sensorStore;

    public static void main(String[] args) throws Exception {
        Mithai mithai = new Mithai();
        if(args.length<1)
            mithai.start(null);
        else
            mithai.start(args[0]);
    }

    protected void start(String arg) throws Exception {

        Logger.getLogger("org").setLevel(Level.ERROR);
        Logger.getLogger("akka").setLevel(Level.ERROR);

        ConfigFileObservable.getInstance().addObserver(this);

        Runtime.getRuntime().addShutdownHook(new ShutDownHook());

        //TODO file path will be provided by user
        if (arg == null || arg.equals("")) {
            File configFile = new File(Mithai.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
            configuration = new Configuration(configFile.getParent() + "/application.properties");
        } else
            configuration = new Configuration(arg);

        sensorStore = new SensorStore();

        loadDevices();

        setupHandlers();


        //Start tasks here
//        TaskManager.getInstance().submitTask(new ConfigMonitorTask(configuration));

        TaskManager.getInstance().submitTask(new MQTTDataReceiverTask(configuration));

        TaskManager.getInstance().submitTask(new MQTTMetaDataRecieverTask(configuration));

        TaskManager.getInstance().submitTask(new MQTTPublisherTask(configuration));

        TaskManager.getInstance().submitTask(new DataGenerationTask(configuration, sensorStore));

        TaskManager.getInstance().submitTask(new MetadataGenerationTask(configuration));

//        TaskManager.getInstance().submitTask(new HttpExporterTask(configuration));

        if (!configuration.getProperty(EXPORTER_TYPE).equals("HTTP")) {
//            TaskManager.getInstance().submitTask(new ExporterTask(configuration, Store.messageStore()));
        }

        // Start Streaming context
        Thread.sleep(14 * 1000);
        SparkStreamingObject.streamingContext().start();
//        // Stop all tasks and wait 60 seconds to finish them
//        TaskManager.getInstance().stopAll();

    }

    protected synchronized void loadDevices() {
        sensorStore.getDevices().clear();

        for (int i = 1; i<= Integer.parseInt(configuration.getProperty(NUMBER_OF_SENSORS)); i++) {
            sensorStore.addDevice(new TemperatureSensor("sensor" + i));
        }
    }

    protected synchronized void setupHandlers() {
        TaskManager.getInstance().addHandler(new MithaiHandler());
    }

    @Override
    public void update(Observable observable, Object o) {<commit_msg>Enables the HTTP expoter task<commit_after>package edu.sjsu.mithai.main;

import edu.sjsu.mithai.config.ConfigFileObservable;
import edu.sjsu.mithai.config.Configuration;
import edu.sjsu.mithai.data.DataGenerationTask;
import edu.sjsu.mithai.data.MetadataGenerationTask;
import edu.sjsu.mithai.data.SensorStore;
import edu.sjsu.mithai.export.HttpExporterTask;
import edu.sjsu.mithai.mqtt.MQTTDataReceiverTask;
import edu.sjsu.mithai.mqtt.MQTTMetaDataRecieverTask;
import edu.sjsu.mithai.mqtt.MQTTPublisherTask;
import edu.sjsu.mithai.sensors.TemperatureSensor;
import edu.sjsu.mithai.spark.SparkStreamingObject;
import edu.sjsu.mithai.util.TaskManager;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import java.io.File;
import java.io.IOException;
import java.util.Observable;
import java.util.Observer;

import static edu.sjsu.mithai.config.MithaiProperties.EXPORTER_TYPE;
import static edu.sjsu.mithai.config.MithaiProperties.NUMBER_OF_SENSORS;

public class Mithai implements Observer {

    protected static Configuration configuration;
    protected SensorStore sensorStore;

    public static void main(String[] args) throws Exception {
        Mithai mithai = new Mithai();
        if(args.length<1)
            mithai.start(null);
        else
            mithai.start(args[0]);
    }

    protected void start(String arg) throws Exception {

        Logger.getLogger("org").setLevel(Level.ERROR);
        Logger.getLogger("akka").setLevel(Level.ERROR);

        ConfigFileObservable.getInstance().addObserver(this);

        Runtime.getRuntime().addShutdownHook(new ShutDownHook());

        //TODO file path will be provided by user
        if (arg == null || arg.equals("")) {
            File configFile = new File(Mithai.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
            configuration = new Configuration(configFile.getParent() + "/application.properties");
        } else
            configuration = new Configuration(arg);

        sensorStore = new SensorStore();

        loadDevices();

        setupHandlers();


        //Start tasks here
//        TaskManager.getInstance().submitTask(new ConfigMonitorTask(configuration));

        TaskManager.getInstance().submitTask(new MQTTDataReceiverTask(configuration));

        TaskManager.getInstance().submitTask(new MQTTMetaDataRecieverTask(configuration));

        TaskManager.getInstance().submitTask(new MQTTPublisherTask(configuration));

        TaskManager.getInstance().submitTask(new DataGenerationTask(configuration, sensorStore));

        TaskManager.getInstance().submitTask(new MetadataGenerationTask(configuration));

        TaskManager.getInstance().submitTask(new HttpExporterTask(configuration));

        if (!configuration.getProperty(EXPORTER_TYPE).equals("HTTP")) {
//            TaskManager.getInstance().submitTask(new ExporterTask(configuration, Store.messageStore()));
        }

        // Start Streaming context
        Thread.sleep(14 * 1000);
        SparkStreamingObject.streamingContext().start();
//        // Stop all tasks and wait 60 seconds to finish them
//        TaskManager.getInstance().stopAll();

    }

    protected synchronized void loadDevices() {
        sensorStore.getDevices().clear();

        for (int i = 1; i<= Integer.parseInt(configuration.getProperty(NUMBER_OF_SENSORS)); i++) {
            sensorStore.addDevice(new TemperatureSensor("sensor" + i));
        }
    }

    protected synchronized void setupHandlers() {
        TaskManager.getInstance().addHandler(new MithaiHandler());
    }

    @Override
    public void update(Observable observable, Object o) {
{'fraction_non_alphanumeric': 0.1115257048092869, 'fraction_numerical': 0.0035931453841901604, 'mean_word_length': 3.7024041585445095, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '7312414', 'n_tokens_mistral': 2128, 'n_tokens_neox': 2021, 'n_words': 360}