<commit_before>package edu.umn.bulletinboard.server;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import edu.umn.bulletinboard.common.content.Article;
import edu.umn.bulletinboard.common.exception.IllegalIPException;
import edu.umn.bulletinboard.common.server.ServerInfo;
import edu.umn.bulletinboard.common.util.ConsistencyType;
import edu.umn.bulletinboard.common.util.IndentArticles;
import edu.umn.bulletinboard.common.util.LogUtil;
import edu.umn.bulletinboard.server.exceptions.InvalidArticleException;
import edu.umn.bulletinboard.server.storage.MemStore;

public class ServerBulletinBoardServiceImpl {
		private static final String CLASS_NAME = ServerBulletinBoardServiceImpl.class.getSimpleName();
	    
		public synchronized int post(String article) throws RemoteException {
			final String method = CLASS_NAME + ".post()";
			LogUtil.log(method, "Posting " + article );
	        return Server.getCoodinatorServerRMIObjectHandle().writeToCoordinatingServer(new Article(-1, article) ,ServerConfig.getConsistencyType()) ;
	    }

	    public synchronized String read() throws RemoteException {
	    	final String method = CLASS_NAME + ".read()";
	    	LogUtil.log(method, "Reading articles");
	    	if(ServerConfig.getConsistencyType().equals(ConsistencyType.SEQUENTIAL)) {
	    		return IndentArticles.getArticlesStr(MemStore.getInstance().getAllArticles());
	    	}
	    	List<Article> readFromCoordinatingServer = Server.getCoodinatorServerRMIObjectHandle().readFromCoordinatingServer(ServerConfig.getConsistencyType());
	        return IndentArticles.getArticlesStr(IndentArticles.getArticleMap(readFromCoordinatingServer));
	    }

	    public synchronized Article choose(int id) throws RemoteException {
	    	final String method = CLASS_NAME + ".read()";
	    	LogUtil.log(method, "Choose for id : " + id);
	    	if(ServerConfig.getConsistencyType().equals(ConsistencyType.SEQUENTIAL)) {
	    		return MemStore.getInstance().getArticle(id);
	    	}
	    	return Server.getCoodinatorServerRMIObjectHandle().chooseFromCoordinatingServer(id, ServerConfig.getConsistencyType());
	    }

	    public synchronized int reply(int id, Article reply) throws RemoteException {
	    	final String method = CLASS_NAME + ".reply()";
	    	LogUtil.log(method, "Reply : " + reply + " for id : "+ id);
	        return Server.getCoodinatorServerRMIObjectHandle().replyToCoordinatingServer(id, reply, ServerConfig.getConsistencyType());
	    }
	    
	    public synchronized void writeToServer(int articleId, String articleText) throws RemoteException {
	    	final String method = CLASS_NAME + ".writeToServer()";
	    	LogUtil.log(method, "Writing " + articleId + ":" + articleText + " to current server");
	    	try {
				MemStore.getInstance().addArticle(new Article(articleId, articleText));
			} catch (InvalidArticleException e) {
				throw new RemoteException("Invalid article", e);
			}
	    }

	    public synchronized Article readFromServer(int articleId) throws RemoteException {
	    	final String method = CLASS_NAME + ".readFromServer()";
	    	LogUtil.log(method, "Reading " + articleId + " from server");
	        return MemStore.getInstance().getArticle(articleId);
	    }

	    public synchronized int getLatestArticleId() throws RemoteException {
	        Map<Integer, Article> allArticles = MemStore.getInstance().getAllArticles();
	        Set<Integer> keySet = allArticles.keySet();
	        int max = -1;
	        for (Integer integer : keySet) {
				if(integer > max) {
					max = integer;
				}
			}
	        return max;
	    }

	    public synchronized void addServer(int serverId) throws RemoteException, IllegalIPException {
	    	// TODO
	    	Server.getServers().add(new ServerInfo(serverId, null,  1));
	    }

		public synchronized List<Article> readFromServer() {
			final String method = CLASS_NAME + ".readFromServer()";
	    	LogUtil.log(method, "Reading all articles from server");
			return new ArrayList(MemStore.getInstance().getAllArticles().values());
		}

		public synchronized void sync(List<Article> articles) {
			final String method = CLASS_NAME + ".sync()";
			Map<Integer, Article> allArticles = MemStore.getInstance().getAllArticles();
			for (Article article : articles) {
				int id = article.getId();
				if(allArticles.containsKey(id)) {
					Article currentArticle = allArticles.get(id);
					List<Integer> replies = currentArticle.getReplies();
					List<Integer> newReplies = article.getReplies();
					List<Integer> list = new ArrayList<Integer>();
					list.addAll(newReplies);
					list.removeAll(replies);
					for (Integer integer : list) {
						currentArticle.getReplies().add(integer);
					}
				}else{
					try {
						MemStore.getInstance().addArticle(article);
					} catch (InvalidArticleException e) {
						LogUtil.log(method, "Invalid article: " + article + " in sync. Will try again in next sync.");
					}
				}
			}
			
		}

}
<commit_msg>more logging<commit_after>package edu.umn.bulletinboard.server;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import edu.umn.bulletinboard.common.content.Article;
import edu.umn.bulletinboard.common.exception.IllegalIPException;
import edu.umn.bulletinboard.common.server.ServerInfo;
import edu.umn.bulletinboard.common.util.ConsistencyType;
import edu.umn.bulletinboard.common.util.IndentArticles;
import edu.umn.bulletinboard.common.util.LogUtil;
import edu.umn.bulletinboard.server.exceptions.InvalidArticleException;
import edu.umn.bulletinboard.server.storage.MemStore;

public class ServerBulletinBoardServiceImpl {
		private static final String CLASS_NAME = ServerBulletinBoardServiceImpl.class.getSimpleName();
	    
		public synchronized int post(String article) throws RemoteException {
			final String method = CLASS_NAME + ".post()";
			LogUtil.log(method, "Posting " + article );
	        return Server.getCoodinatorServerRMIObjectHandle().writeToCoordinatingServer(new Article(-1, article) ,ServerConfig.getConsistencyType()) ;
	    }

	    public synchronized String read() throws RemoteException {
	    	final String method = CLASS_NAME + ".read()";
	    	LogUtil.log(method, "Reading articles");
	    	if(ServerConfig.getConsistencyType().equals(ConsistencyType.SEQUENTIAL)) {
	    		LogUtil.log(method, "Returing articles str for memstore : " + MemStore.getInstance().getAllArticles().toString());
	    		return IndentArticles.getArticlesStr(MemStore.getInstance().getAllArticles());
	    	}
	    	List<Article> readFromCoordinatingServer = Server.getCoodinatorServerRMIObjectHandle().readFromCoordinatingServer(ServerConfig.getConsistencyType());
	        return IndentArticles.getArticlesStr(IndentArticles.getArticleMap(readFromCoordinatingServer));
	    }

	    public synchronized Article choose(int id) throws RemoteException {
	    	final String method = CLASS_NAME + ".read()";
	    	LogUtil.log(method, "Choose for id : " + id);
	    	if(ServerConfig.getConsistencyType().equals(ConsistencyType.SEQUENTIAL)) {
	    		return MemStore.getInstance().getArticle(id);
	    	}
	    	return Server.getCoodinatorServerRMIObjectHandle().chooseFromCoordinatingServer(id, ServerConfig.getConsistencyType());
	    }

	    public synchronized int reply(int id, Article reply) throws RemoteException {
	    	final String method = CLASS_NAME + ".reply()";
	    	LogUtil.log(method, "Reply : " + reply + " for id : "+ id);
	        return Server.getCoodinatorServerRMIObjectHandle().replyToCoordinatingServer(id, reply, ServerConfig.getConsistencyType());
	    }
	    
	    public synchronized void writeToServer(int articleId, String articleText) throws RemoteException {
	    	final String method = CLASS_NAME + ".writeToServer()";
	    	LogUtil.log(method, "Writing " + articleId + ":" + articleText + " to current server");
	    	try {
				MemStore.getInstance().addArticle(new Article(articleId, articleText));
			} catch (InvalidArticleException e) {
				throw new RemoteException("Invalid article", e);
			}
	    }

	    public synchronized Article readFromServer(int articleId) throws RemoteException {
	    	final String method = CLASS_NAME + ".readFromServer()";
	    	LogUtil.log(method, "Reading " + articleId + " from server");
	        return MemStore.getInstance().getArticle(articleId);
	    }

	    public synchronized int getLatestArticleId() throws RemoteException {
	        Map<Integer, Article> allArticles = MemStore.getInstance().getAllArticles();
	        Set<Integer> keySet = allArticles.keySet();
	        int max = -1;
	        for (Integer integer : keySet) {
				if(integer > max) {
					max = integer;
				}
			}
	        return max;
	    }

	    public synchronized void addServer(int serverId) throws RemoteException, IllegalIPException {
	    	// TODO
	    	Server.getServers().add(new ServerInfo(serverId, null,  1));
	    }

		public synchronized List<Article> readFromServer() {
			final String method = CLASS_NAME + ".readFromServer()";
	    	LogUtil.log(method, "Reading all articles from server");
			return new ArrayList(MemStore.getInstance().getAllArticles().values());
		}

		public synchronized void sync(List<Article> articles) {
			final String method = CLASS_NAME + ".sync()";
			Map<Integer, Article> allArticles = MemStore.getInstance().getAllArticles();
			for (Article article : articles) {
				int id = article.getId();
				if(allArticles.containsKey(id)) {
					Article currentArticle = allArticles.get(id);
					List<Integer> replies = currentArticle.getReplies();
					List<Integer> newReplies = article.getReplies();
					List<Integer> list = new ArrayList<Integer>();
					list.addAll(newReplies);
					list.removeAll(replies);
					for (Integer integer : list) {
						currentArticle.getReplies().add(integer);
					}
				}else{
					try {
						MemStore.getInstance().addArticle(article);
					} catch (InvalidArticleException e) {
						LogUtil.log(method, "Invalid article: " + article + " in sync. Will try again in next sync.");
					}
				}
			}
			
		}

}

{'fraction_non_alphanumeric': 0.11052891744933267, 'fraction_numerical': 0.0005931784478497281, 'mean_word_length': 3.9906265416872224, 'pattern_counts': {'":': 2, '<': 23, '<?xml version=': 0, '>': 25, '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': '6206732', 'n_tokens_mistral': 3249, 'n_tokens_neox': 2849, 'n_words': 598}