<commit_before>package alma.acs.monitoring.blobber;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import alma.JavaContainerError.wrappers.AcsJContainerServicesEx;
import alma.MonitorArchiver.Controller;
import alma.MonitorArchiver.ControllerHelper;
import alma.MonitorCollectorErr.DeviceAlreadyRegistredEx;
import alma.MonitorCollectorErr.DeviceNotRegistredEx;
import alma.MonitorCollectorErr.RegisteringDeviceProblemEx;
import alma.MonitorCollectorErr.StartMonitoringProblemEx;
import alma.MonitorCollectorErr.StopMonitoringProblemEx;
import alma.TMCDB.MonitorBlob;
import alma.TMCDB.MonitorCollectorOperations;
import alma.TMCDB.MonitorDataBlock;
import alma.TMCDB.doubleBlobData;
import alma.TMCDB.doubleBlobDataSeqHelper;
import alma.TMCDB.doubleSeqBlobDataHelper;
import alma.TMCDB.doubleValueType;
import alma.TMCDB.propertySerailNumber;
import alma.acs.component.ComponentImplBase;
import alma.acs.component.ComponentLifecycleException;
import alma.acs.container.ContainerServices;

public class FileReaderCollectorImpl extends ComponentImplBase implements MonitorCollectorOperations {

	private static final String PREFIX = System.getProperty("alma.tmcdb.monitoring.filesDir") + File.separatorChar;

	public static final String[] monitoredComponents = {
		"CONTROL/CentralLO/ML",
		"CONTROL/CentralLO/MLD"
	};
	private static final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

	private Map<String, List<FileBasedMonitorPoint>>   m_files = new HashMap<String, List<FileBasedMonitorPoint>>();

	private static class FileBasedMonitorPoint {
		public BufferedReader reader;
		public long lastTimestamp;
		public String propertyname;
	}

    @Override
    public void initialize(ContainerServices inContainerServices)
            throws ComponentLifecycleException {
        super.initialize(inContainerServices);
        Controller controller;
		try {
			controller = ControllerHelper.narrow(m_containerServices.getComponent("ARCHIVE/TMCDB/MONITOR_CONTROL"));
		} catch (AcsJContainerServicesEx e) {
			throw new ComponentLifecycleException(e);
		}
        controller.registerCollector(name());
    }

	@Override
	public void registerMonitoredDevice(String componentName,
			String serialNumber) throws RegisteringDeviceProblemEx,
			DeviceAlreadyRegistredEx {
	}

	@Override
	public void registerMonitoredDeviceWithMultipleSerial(String componentName,
			propertySerailNumber[] serialNumbers)
			throws RegisteringDeviceProblemEx, DeviceAlreadyRegistredEx {
	}

	@Override
	public void deregisterMonitoredDevice(String componentName)
			throws DeviceNotRegistredEx {
	}

	@Override
	public void startMonitoring(String componentName)
			throws StartMonitoringProblemEx {

		String componentDirPath = PREFIX + componentName.replaceAll("/", "_");
		File componentDir = new File(componentDirPath);

		List<FileBasedMonitorPoint> monitorPointData = new ArrayList<FileBasedMonitorPoint>();
		for(String fileName: componentDir.list()) {
			FileBasedMonitorPoint mp = new FileBasedMonitorPoint();
			mp.propertyname = fileName.substring(0, fileName.lastIndexOf('.'));
			try {
				mp.reader = new BufferedReader(new FileReader(new File(componentDirPath + File.separator + fileName)));
				mp.reader.mark(80);
				mp.lastTimestamp = parseLine(mp.reader.readLine()).time;
				mp.reader.reset();
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} catch (ParseException e) {
				e.printStackTrace();
			}
			monitorPointData.add(mp);
		}

		m_files.put(componentName, monitorPointData);

	}

	@Override
	public void stopMonitoring(String componentName)
			throws StopMonitoringProblemEx {
		
		for(String component: m_files.keySet())
			if( component.equals(componentName) ) {
				try {
					for(FileBasedMonitorPoint mp: m_files.get(component) )
						mp.reader.close();
				} catch (IOException e) {}
			}

	}

	@Override
	public MonitorDataBlock[] getMonitorData() {<commit_msg>Adding dummy methods for enable/supress archiving and changing archiving interval.<commit_after>package alma.acs.monitoring.blobber;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import alma.JavaContainerError.wrappers.AcsJContainerServicesEx;
import alma.MonitorArchiver.Controller;
import alma.MonitorArchiver.ControllerHelper;
import alma.MonitorCollectorErr.DeviceAlreadyRegistredEx;
import alma.MonitorCollectorErr.DeviceNotRegistredEx;
import alma.MonitorCollectorErr.RegisteringDeviceProblemEx;
import alma.MonitorCollectorErr.StartMonitoringProblemEx;
import alma.MonitorCollectorErr.StopMonitoringProblemEx;
import alma.TMCDB.MonitorBlob;
import alma.TMCDB.MonitorCollectorOperations;
import alma.TMCDB.MonitorDataBlock;
import alma.TMCDB.doubleBlobData;
import alma.TMCDB.doubleBlobDataSeqHelper;
import alma.TMCDB.doubleSeqBlobDataHelper;
import alma.TMCDB.doubleValueType;
import alma.TMCDB.propertySerailNumber;
import alma.acs.component.ComponentImplBase;
import alma.acs.component.ComponentLifecycleException;
import alma.acs.container.ContainerServices;

public class FileReaderCollectorImpl extends ComponentImplBase implements MonitorCollectorOperations {

	private static final String PREFIX = System.getProperty("alma.tmcdb.monitoring.filesDir") + File.separatorChar;

	public static final String[] monitoredComponents = {
		"CONTROL/CentralLO/ML",
		"CONTROL/CentralLO/MLD"
	};
	private static final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

	private Map<String, List<FileBasedMonitorPoint>>   m_files = new HashMap<String, List<FileBasedMonitorPoint>>();

	private static class FileBasedMonitorPoint {
		public BufferedReader reader;
		public long lastTimestamp;
		public String propertyname;
	}

    @Override
    public void initialize(ContainerServices inContainerServices)
            throws ComponentLifecycleException {
        super.initialize(inContainerServices);
        Controller controller;
		try {
			controller = ControllerHelper.narrow(m_containerServices.getComponent("ARCHIVE/TMCDB/MONITOR_CONTROL"));
		} catch (AcsJContainerServicesEx e) {
			throw new ComponentLifecycleException(e);
		}
        controller.registerCollector(name());
    }

	@Override
	public void registerMonitoredDevice(String componentName,
			String serialNumber) throws RegisteringDeviceProblemEx,
			DeviceAlreadyRegistredEx {
	}

	@Override
	public void registerMonitoredDeviceWithMultipleSerial(String componentName,
			propertySerailNumber[] serialNumbers)
			throws RegisteringDeviceProblemEx, DeviceAlreadyRegistredEx {
	}

	@Override
	public void deregisterMonitoredDevice(String componentName)
			throws DeviceNotRegistredEx {
	}

	@Override
	public void startMonitoring(String componentName)
			throws StartMonitoringProblemEx {

		String componentDirPath = PREFIX + componentName.replaceAll("/", "_");
		File componentDir = new File(componentDirPath);

		List<FileBasedMonitorPoint> monitorPointData = new ArrayList<FileBasedMonitorPoint>();
		for(String fileName: componentDir.list()) {
			FileBasedMonitorPoint mp = new FileBasedMonitorPoint();
			mp.propertyname = fileName.substring(0, fileName.lastIndexOf('.'));
			try {
				mp.reader = new BufferedReader(new FileReader(new File(componentDirPath + File.separator + fileName)));
				mp.reader.mark(80);
				mp.lastTimestamp = parseLine(mp.reader.readLine()).time;
				mp.reader.reset();
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} catch (ParseException e) {
				e.printStackTrace();
			}
			monitorPointData.add(mp);
		}

		m_files.put(componentName, monitorPointData);

	}

	@Override
	public void stopMonitoring(String componentName)
			throws StopMonitoringProblemEx {
		
		for(String component: m_files.keySet())
			if( component.equals(componentName) ) {
				try {
					for(FileBasedMonitorPoint mp: m_files.get(component) )
						mp.reader.close();
				} catch (IOException e) {}
			}

	}

    @Override
    public void set_archiving_interval(String compName, String propName, long time) {
    }

    @Override
    public void enable_archiving(String compName, String propName) {
    }

    @Override
    public void suppress_archiving(String compName, String propName) {
    }

	@Override
	public MonitorDataBlock[] getMonitorData() {
{'fraction_non_alphanumeric': 0.08846672661870504, 'fraction_numerical': 0.0006744604316546763, 'mean_word_length': 5.570901033973412, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '5837334', 'n_tokens_mistral': 2783, 'n_tokens_neox': 2530, 'n_words': 510}