<commit_before>package de.fernunihagen.dna.jkn.scalephant;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.commons.daemon.Daemon;
import org.apache.commons.daemon.DaemonContext;
import org.apache.commons.daemon.DaemonInitException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.fernunihagen.dna.jkn.scalephant.distribution.ZookeeperClient;
import de.fernunihagen.dna.jkn.scalephant.network.server.NetworkConnectionService;

public class ScalephantMain implements Daemon {

	/**
	 * The instances to manage
	 */
	protected final List<ScalephantService> services = new ArrayList<ScalephantService>();
	
	/**
	 * The Logger
	 */
	private final static Logger logger = LoggerFactory.getLogger(ScalephantMain.class);

	@Override
	public void init(final DaemonContext ctx) throws DaemonInitException, Exception {
		logger.info("Init the scalephant");
		
		final ScalephantConfiguration scalephantConfiguration = ScalephantConfigurationManager.getConfiguration();
		
		// The zookeeper client
		services.add(createZookeeperClient(scalephantConfiguration));

		// The network conenction handler
		services.add(createConnectionHandler());		
	}

	/**
	 * Returns a new instance of the connection handler
	 * @return
	 */
	protected NetworkConnectionService createConnectionHandler() {
		return new NetworkConnectionService();
	}

	/**
	 * Returns a new instance of the zookeeper client
	 * @param scalephantConfiguration
	 * @return
	 */
	protected ZookeeperClient createZookeeperClient(
			final ScalephantConfiguration scalephantConfiguration) {
		
		final Collection<String> zookeepernodes = scalephantConfiguration.getZookeepernodes();
		final String clustername = scalephantConfiguration.getClustername();
		final String localIp = scalephantConfiguration.getLocalip();
		final int localPort = scalephantConfiguration.getNetworkListenPort();
		
		final String instanceName = localIp + ":" + Integer.toString(localPort);
		
		return new ZookeeperClient(zookeepernodes, clustername, instanceName);
	}

	@Override
	public void start() throws Exception {
		logger.info("Starting up the scalephant - version: " + Const.VERSION);	
		
		// Init all services
		for(ScalephantService service : services) {
			logger.info("Starting service: " + service.getServicename());
			service.init();
		}
	}

	@Override<commit_msg>Added server main dir check<commit_after>package de.fernunihagen.dna.jkn.scalephant;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.commons.daemon.Daemon;
import org.apache.commons.daemon.DaemonContext;
import org.apache.commons.daemon.DaemonInitException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.fernunihagen.dna.jkn.scalephant.distribution.ZookeeperClient;
import de.fernunihagen.dna.jkn.scalephant.network.server.NetworkConnectionService;

public class ScalephantMain implements Daemon {

	/**
	 * The instances to manage
	 */
	protected final List<ScalephantService> services = new ArrayList<ScalephantService>();
	
	/**
	 * The Logger
	 */
	private final static Logger logger = LoggerFactory.getLogger(ScalephantMain.class);

	@Override
	public void init(final DaemonContext ctx) throws DaemonInitException, Exception {
		logger.info("Init the scalephant");
		
		final ScalephantConfiguration scalephantConfiguration = ScalephantConfigurationManager.getConfiguration();
		
		// The zookeeper client
		services.add(createZookeeperClient(scalephantConfiguration));

		// The network conenction handler
		services.add(createConnectionHandler());		
	}

	/**
	 * Returns a new instance of the connection handler
	 * @return
	 */
	protected NetworkConnectionService createConnectionHandler() {
		return new NetworkConnectionService();
	}

	/**
	 * Returns a new instance of the zookeeper client
	 * @param scalephantConfiguration
	 * @return
	 */
	protected ZookeeperClient createZookeeperClient(
			final ScalephantConfiguration scalephantConfiguration) {
		
		final Collection<String> zookeepernodes = scalephantConfiguration.getZookeepernodes();
		final String clustername = scalephantConfiguration.getClustername();
		final String localIp = scalephantConfiguration.getLocalip();
		final int localPort = scalephantConfiguration.getNetworkListenPort();
		
		final String instanceName = localIp + ":" + Integer.toString(localPort);
		
		return new ZookeeperClient(zookeepernodes, clustername, instanceName);
	}

	@Override
	public void start() throws Exception {
		logger.info("Starting up the scalephant - version: " + Const.VERSION);	
		
		if (! runBaseChecks() ) {
			logger.warn("Some of the base checks have failed, exiting");
			System.exit(0);
		}
		
		// Init all services
		for(ScalephantService service : services) {
			logger.info("Starting service: " + service.getServicename());
			service.init();
		}
	}

	/**
	 * Run some base checks to ensure, the services could be started
	 * @return
	 */
	protected boolean runBaseChecks() {
		final String dataDir = ScalephantConfigurationManager.getConfiguration().getDataDirectory();
		final File dataDirHandle = new File(dataDir);
		
		// Ensure that the server main dir does exist
		if(! dataDirHandle.exists() ) {
			logger.error("Data Directory does not exist: " + dataDir);
			return false;
		}
		
		return true;
	}

	@Override
{'fraction_non_alphanumeric': 0.0931619154089808, 'fraction_numerical': 0.000931619154089808, 'mean_word_length': 4.944629014396456, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, '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': '5012957', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1449, 'n_words': 362}