<commit_before>package edu.teco.dnd.eclipse;

import io.netty.util.internal.logging.InternalLoggerFactory;

import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collection;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

import edu.teco.dnd.eclipse.preferences.PreferencesNetwork;
import edu.teco.dnd.module.ModuleID;
import edu.teco.dnd.network.UDPMulticastBeacon;
import edu.teco.dnd.network.logging.Log4j2LoggerFactory;
import edu.teco.dnd.server.AddressBasedServerConfig;
import edu.teco.dnd.server.SimpleAddressBasedServerConfig;
import edu.teco.dnd.server.ServerManager;
import edu.teco.dnd.server.TCPUDPServerManager;
import edu.teco.dnd.util.NetConnection;

public class Activator extends AbstractUIPlugin {

	/**
	 * The logger for this class.
	 */
	private static final Logger LOGGER = LogManager.getLogger(Activator.class);

	private static Activator plugin;

	private ServerManager<AddressBasedServerConfig> serverManager = null;
	private ModuleID moduleID = null;

	static {
		InternalLoggerFactory.setDefaultFactory(new Log4j2LoggerFactory());
	}

	public static Activator getDefault() {
		return plugin;
	}

	@Override
	public void start(final BundleContext context) throws Exception {
		LOGGER.entry(context);
		super.start(context);
		plugin = this;
		serverManager = new TCPUDPServerManager();
		moduleID = new ModuleID();
		LOGGER.exit();
	}

	@Override
	public void stop(final BundleContext context) throws Exception {
		LOGGER.entry();
		super.stop(context);
		plugin = null;
		serverManager = null;
		moduleID = null;
		LOGGER.exit();
	}

	public ServerManager<AddressBasedServerConfig> getServerManager() {
		return serverManager;
	}

	/**
	 * Starts a server.
	 * 
	 * Use this method to start the server from within eclipse. Activator will get the address arguments from the
	 * preference store and pass them to the {@link ServerManager}. The ServerManager will do the main process of
	 * starting a server, but only Activator can access the Preferences to get the user input in eclipse.
	 * 
	 * When starting a server from outside of eclipse, you can't access the preferences set in eclipse. In that case,
	 * start the server directly through the {@link ServerManager}. You will also have to get the address arguments from
	 * somewhere else.
	 */
	public void startServer() {
		final AddressBasedServerConfig serverConfig =
				new SimpleAddressBasedServerConfig(moduleID, getListenAddresses(), getMulticastAddresses(),
						getAnnounceAddresses(), getAnnounceInterval());
		serverManager.startServer(serverConfig);
	}

	public void shutdownServer() {
		serverManager.shutdownServer();
	}

	@Override
	protected void initializeDefaultPreferences(IPreferenceStore store) {
		store.setDefault(PreferencesNetwork.LISTEN_PREFERENCE, "");
		store.setDefault(PreferencesNetwork.MULTICAST_PREFERENCE, "");
		store.setDefault(PreferencesNetwork.ANNOUNCE_PREFERENCE, "");
		store.setDefault(PreferencesNetwork.BEACON_PREFERENCE, UDPMulticastBeacon.DEFAULT_INTERVAL);
	}

	/**
	 * Returns the listen addresses stored in the Eclipse preferences.
	 * 
	 * @return the listen addresses stored in the Eclipse preferences
	 */
	private Collection<InetSocketAddress> getListenAddresses() {
		return getInetSocketAddresses(getPreference(PreferencesNetwork.LISTEN_PREFERENCE).split(" "));
	}
<commit_msg>Add JavaDoc for eclipse package<commit_after>package edu.teco.dnd.eclipse;

import io.netty.util.internal.logging.InternalLoggerFactory;

import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collection;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

import edu.teco.dnd.eclipse.preferences.Preferences;
import edu.teco.dnd.eclipse.preferences.PreferencesNetwork;
import edu.teco.dnd.module.ModuleID;
import edu.teco.dnd.network.UDPMulticastBeacon;
import edu.teco.dnd.network.logging.Log4j2LoggerFactory;
import edu.teco.dnd.server.AddressBasedServerConfig;
import edu.teco.dnd.server.SimpleAddressBasedServerConfig;
import edu.teco.dnd.server.ApplicationManager;
import edu.teco.dnd.server.ModuleManager;
import edu.teco.dnd.server.ServerManager;
import edu.teco.dnd.server.ServerStateListener;
import edu.teco.dnd.server.TCPUDPServerManager;
import edu.teco.dnd.util.NetConnection;

/**
 * This is the main class for the Eclipse plugin. It is implemented as a singleton and handles global variables such as
 * the {@link ServerManager}.
 */
public class Activator extends AbstractUIPlugin {
	private static final Logger LOGGER = LogManager.getLogger(Activator.class);

	private static Activator plugin;

	private ServerManager<AddressBasedServerConfig> serverManager = null;
	private ModuleID moduleID = null;

	static {
		// set Logger factory of Netty. Must be run as early as possible so that Netty has not created any Loggers
		// before the factory is set.
		InternalLoggerFactory.setDefaultFactory(new Log4j2LoggerFactory());
	}

	public static Activator getDefault() {
		return plugin;
	}

	@Override
	public void start(final BundleContext context) throws Exception {
		LOGGER.entry(context);
		super.start(context);
		plugin = this;
		serverManager = new TCPUDPServerManager();
		moduleID = new ModuleID();
		LOGGER.exit();
	}

	@Override
	public void stop(final BundleContext context) throws Exception {
		LOGGER.entry();
		super.stop(context);
		plugin = null;
		serverManager = null;
		moduleID = null;
		LOGGER.exit();
	}

	/**
	 * Returns a ServerManager that should be used for registering with a {@link ModuleManager} and/or a
	 * {@link ApplicationManager} as well as for registering as a {@link ServerStateListener} directly. You should not
	 * call {@link ServerManager#startServer(String, String, String, int)} or {@link ServerManager#shutdownServer()}
	 * directly. Use {@link #startServer()} and {@link #shutdownServer()} instead.
	 * 
	 * @return the ServerManager to use
	 */
	public ServerManager<AddressBasedServerConfig> getServerManager() {
		return serverManager;
	}

	/**
	 * Starts the server used to communicate with other Modules. The configuration for the server is retrieved from the
	 * {@link Preferences}.
	 */
	public void startServer() {
		final AddressBasedServerConfig serverConfig =
				new SimpleAddressBasedServerConfig(moduleID, getListenAddresses(), getMulticastAddresses(),
						getAnnounceAddresses(), getAnnounceInterval());
		serverManager.startServer(serverConfig);
	}

	public void shutdownServer() {
		serverManager.shutdownServer();
	}

	@Override
	protected void initializeDefaultPreferences(IPreferenceStore store) {
		store.setDefault(PreferencesNetwork.LISTEN_PREFERENCE, "");
		store.setDefault(PreferencesNetwork.MULTICAST_PREFERENCE, "");
		store.setDefault(PreferencesNetwork.ANNOUNCE_PREFERENCE, "");
		store.setDefault(PreferencesNetwork.BEACON_PREFERENCE, UDPMulticastBeacon.DEFAULT_INTERVAL);
	}

	/**
	 * Returns the listen addresses stored in the Eclipse preferences.
	 * 
	 * @return the listen addresses stored in the Eclipse preferences
	 */
	private Collection<InetSocketAddress> getListenAddresses() {
		return getInetSocketAddresses(getPreference(PreferencesNetwork.LISTEN_PREFERENCE).split(" "));
	}

{'fraction_non_alphanumeric': 0.09118262689691262, 'fraction_numerical': 0.0015698587127158557, 'mean_word_length': 5.408214585079631, 'pattern_counts': {'":': 0, '<': 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': '4031378', 'n_tokens_mistral': 2325, 'n_tokens_neox': 2206, 'n_words': 562}