<commit_before>package edu.umn.pubsub.server.registery;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Set;

import edu.umn.pubsub.common.rmi.Communicate;
import edu.umn.pubsub.common.server.ServerInfo;
import edu.umn.pubsub.common.util.LogUtil;
import edu.umn.pubsub.server.Server;
import edu.umn.pubsub.server.cache.ServerInfoCache;

public class RegisteryServerGetListPoller implements Runnable{
	private final static String CLASS_NAME = RegisteryServerGetListPoller.class.getSimpleName(); 
	
	private final long POLL_INTERVAL = 60*1000;
	
	@Override
	public void run() {
		String method = CLASS_NAME + ".run()";
		while(true) {
			LogUtil.log(method, "Calling getList");
			Set<ServerInfo> registeredServers = RegisteryServerManager.getInstance().getList();
			if(registeredServers.isEmpty()) {
				LogUtil.log(method, "No active servers present. Will try again after " + POLL_INTERVAL + "ms");
				sleep(POLL_INTERVAL);
				continue;
			}
			Set<ServerInfo> currentSendableServers = ServerInfoCache.getInstance().getSendableServers();
			
			// remove the servers that no more registered.
			currentSendableServers.retainAll(registeredServers);
			// Remove all the servers that we are already connected to
			registeredServers.removeAll(currentSendableServers);
			
			
			if(registeredServers.isEmpty()) {
				LogUtil.log(method, "No new active servers to join to. Will try again after " + POLL_INTERVAL + "ms");
				sleep(POLL_INTERVAL);
				continue;
			}
			
			for (ServerInfo serverInfo : registeredServers) {
				LogUtil.log(method, "Binding to server: " + serverInfo.toString());
				
				Communicate client;
				try {
					client = (Communicate) Naming.lookup("rmi://" + serverInfo.getIp() + ":" + serverInfo.getPort() + 
							"/" + serverInfo.getBindingName());
				} catch (MalformedURLException e) {<commit_msg>#14 remove all servers if no active servers present<commit_after>package edu.umn.pubsub.server.registery;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Set;

import edu.umn.pubsub.common.rmi.Communicate;
import edu.umn.pubsub.common.server.ServerInfo;
import edu.umn.pubsub.common.util.LogUtil;
import edu.umn.pubsub.server.Server;
import edu.umn.pubsub.server.cache.ServerInfoCache;

public class RegisteryServerGetListPoller implements Runnable{
	private final static String CLASS_NAME = RegisteryServerGetListPoller.class.getSimpleName(); 
	
	private final long POLL_INTERVAL = 60*1000;
	
	@Override
	public void run() {
		String method = CLASS_NAME + ".run()";
		while(true) {
			LogUtil.log(method, "Calling getList");
			Set<ServerInfo> registeredServers = RegisteryServerManager.getInstance().getList();
			if(registeredServers.isEmpty()) {
				LogUtil.log(method, "No active servers present. Will try again after " + POLL_INTERVAL + "ms");
				LogUtil.log(method, "Removing all currentSendable servers");
				ServerInfoCache.getInstance().getSendableServers().clear();
				sleep(POLL_INTERVAL);
				continue;
			}
			Set<ServerInfo> currentSendableServers = ServerInfoCache.getInstance().getSendableServers();
			
			// remove the servers that no more registered.
			currentSendableServers.retainAll(registeredServers);
			// Remove all the servers that we are already connected to
			registeredServers.removeAll(currentSendableServers);
			
			
			if(registeredServers.isEmpty()) {
				LogUtil.log(method, "No new active servers to join to. Will try again after " + POLL_INTERVAL + "ms");
				sleep(POLL_INTERVAL);
				continue;
			}
			
			for (ServerInfo serverInfo : registeredServers) {
				LogUtil.log(method, "Binding to server: " + serverInfo.toString());
				
				Communicate client;
				try {
					client = (Communicate) Naming.lookup("rmi://" + serverInfo.getIp() + ":" + serverInfo.getPort() + 
							"/" + serverInfo.getBindingName());
				} catch (MalformedURLException e) {
{'fraction_non_alphanumeric': 0.11207537813042401, 'fraction_numerical': 0.0034713612695264073, 'mean_word_length': 4.473541383989145, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, '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': '1223810', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1221, 'n_words': 268}