<commit_before>package ViewManager;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import com.datastax.driver.core.*;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import client.client.Client;

public class CommitLogReader {

	BufferedReader br;
	ViewManagerController vmc;

	public CommitLogReader() {

		try {
			br = new BufferedReader(new FileReader("logs//output.log"));
			vmc = new ViewManagerController();

		} catch (FileNotFoundException e) {

			e.printStackTrace();
		}

	}

	public void read() {

		Client.connectToCluster("192.168.56.101");

		String raw;
		try {
			raw = br.readLine();

			while (raw != null) {
				String[] splitRaw = raw.split(" - ");
				String jsonString = splitRaw[1];

				JSONObject json = (JSONObject) new JSONParser()
				.parse(jsonString);

				String type = json.get("type").toString();
				String table = json.get("table").toString();

				if (table.contains("groupby")) {
					if (type.equalsIgnoreCase("insert")||type.equalsIgnoreCase("update")){
						vmc.decideGroupBy(json,table);
					}
				}else if (table.contains("preagg_agg")) {
					if (type.equalsIgnoreCase("insert")||type.equalsIgnoreCase("update")){
						vmc.decidePreagg(json,table);
					}
				} else {

					if (table.contains("RJ_")) {
						if (type.equalsIgnoreCase("insert")){

							JSONObject data = (JSONObject) json.get("data");

							String bufferString = data.get("stream").toString();

							Stream s = Serialize.deserializeStream(bufferString);

							if(s.isDeleteOperation())
								vmc.propagateDeleteRJ(json);
							else
								vmc.propagateRJ(json);
						}

					} else {

						if (type.equals("insert")) {
							vmc.update(json);
						}

						if (type.equals("update")) {
							vmc.update(json);
						}

						if (type.equals("delete-row")) {
							vmc.cascadeDelete(json, true);
						}
					}
				}

				raw = br.readLine();
			}

			Client.getClusterInstance().close();

		} catch (IOException e) {
			e.printStackTrace();

		} catch (ParseException e) {
			e.printStackTrace();
		}

	}

	public static void main(String[] args) {

		CommitLogReader cmr = new CommitLogReader();
		cmr.read();

	}
}<commit_msg>before el merge 2<commit_after>package ViewManager;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import client.client.Client;

public class CommitLogReader {

	BufferedReader br;
	static TaskDistributor td;
	static RandomAccessFile raf;
	static ViewManagerController vmc;
	static String fileName = "logs//output.log";
	static long readPtr;

	public CommitLogReader() {

		try {
			raf = new RandomAccessFile(fileName, "rw");
			br = new BufferedReader(new FileReader("logs//output.log"));
			readPtr = -1;
			td = new TaskDistributor();

		} catch (FileNotFoundException e) {

			e.printStackTrace();
		}

	}

	/*public void read() {

		Client.connectToCluster("192.168.56.101");

		String raw;
		try {
			raw = br.readLine();

			while (raw != null) {
				String[] splitRaw = raw.split(" - ");
				String jsonString = splitRaw[1];

				JSONObject json = (JSONObject) new JSONParser()
				.parse(jsonString);

				String type = json.get("type").toString();
				String table = json.get("table").toString();

				if (table.contains("groupby")) {
					if (type.equalsIgnoreCase("insert")||type.equalsIgnoreCase("update")){
						vmc.decideGroupBy(json,table);
					}
				}else if (table.contains("preagg_agg")) {
					if (type.equalsIgnoreCase("insert")||type.equalsIgnoreCase("update")){
						vmc.decidePreagg(json,table);
					}
				} else {

					if (table.contains("RJ_")) {
						if (type.equalsIgnoreCase("insert")){

							JSONObject data = (JSONObject) json.get("data");

							String bufferString = data.get("stream").toString();

							Stream s = Serialize.deserializeStream(bufferString);

							if(s.isDeleteOperation())
								vmc.propagateDeleteRJ(json);
							else
								vmc.propagateRJ(json);
						}

					} else {

						if (type.equals("insert")) {
							vmc.update(json);
						}

						if (type.equals("update")) {
							vmc.update(json);
						}

						if (type.equals("delete-row")) {
							vmc.cascadeDelete(json, true);
						}
					}
				}

				raw = br.readLine();
			}

			Client.getClusterInstance().close();

		} catch (IOException e) {
			e.printStackTrace();

		} catch (ParseException e) {
			e.printStackTrace();
		}

	}*/

	public static void main(String[] args) {

		CommitLogReader cmr = new CommitLogReader();
		

		//======================================================

		// monitor a single file
		TimerTask task = new FileWatcher(new File(fileName)) {
			protected void onChange(File file) {
				readCL();
			}
		};

		Timer timer = new Timer();
		timer.schedule(task,new Date(),1000);

	}

	private static void readCL() {

		System.out.println("on change");
		
		String raw;
		int counter = 0;

		try {

			if(readPtr==-1){
				raw = raf.readLine();
				readPtr = raf.getFilePointer();
				counter++;
			}else{
				raf.seek(readPtr);
				raw = raf.readLine();
				readPtr = raf.getFilePointer();
				counter++;
			}

			while (raw != null) {
				String[] splitRaw = raw.split(" - ");
				String jsonString = splitRaw[1];

				JSONObject json = (JSONObject) new JSONParser().parse(jsonString);

				String type = json.get("type").toString();
				String table = json.get("table").toString();

				System.out.println(table);
				td.processRequest(json,type,table);
				System.out.println("back");

				if(counter<10){
					raw = raf.readLine();
					readPtr = raf.getFilePointer();
				}else{
					raw = null;
				}
			}

		} catch (IOException e) {
			e.printStackTrace();

		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

	public void closeCLREader(){
		try {
			raf.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		Client.getClusterInstance().close();
	}

}
{'fraction_non_alphanumeric': 0.1561712846347607, 'fraction_numerical': 0.00551007556675063, 'mean_word_length': 3.1414602346805736, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '4999902', 'n_tokens_mistral': 2612, 'n_tokens_neox': 2007, 'n_words': 394}