<commit_before>package codeOrchestra.colt.core.jmdns;

import codeOrchestra.colt.core.http.CodeOrchestraRPCHttpServer;
import codeOrchestra.util.LocalhostUtil;

import javax.jmdns.JmDNS;
import javax.jmdns.ServiceInfo;
import java.io.IOException;
import java.net.InetAddress;

/**
 * @author <NAME>
 */
public class JmDNSFacade {

    public static final String NONE_PROJECT_NAME = "NONE";

    private static JmDNSFacade instance;

    public synchronized static JmDNSFacade getInstance() {
        if (instance == null) {
            instance = new JmDNSFacade();
        }
        return instance;
    }

    private ServiceInfo serviceInfo;
    private Object jmDNSObject;

    public JmDNSFacade() {
        updateServiceInfo(NONE_PROJECT_NAME);
        try {
            jmDNSObject = JmDNS.create(LocalhostUtil.getLocalhostIp());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void updateServiceInfo(String projectName) {
        serviceInfo = ServiceInfo.create("_colt._tcp.local.", getServiceName(projectName), CodeOrchestraRPCHttpServer.PORT, "COLT RPC");
    }

    private String getServiceName(String projectName) {
        return "colt::" + projectName + "::" + System.currentTimeMillis();
    }

    public void setProjectName(final String projectName) {
        new Thread(() -> {
            doSetProjectName(projectName);
        }).start();
    }

    private synchronized void doSetProjectName(String projectName) {
        ((JmDNS) jmDNSObject).unregisterService(serviceInfo);
        updateServiceInfo(projectName);
        try {
            ((JmDNS) jmDNSObject).registerService(serviceInfo);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void init() {
        new Thread(this::doInit).start();
    }

    private synchronized void doInit() {
        try {
            ((JmDNS) jmDNSObject).registerService(serviceInfo);
        } catch (IOException e) {
            // ignore
            e.printStackTrace();
        }
    }

    public void dispose() {
        new Thread(this::doDispose).start();
    }

    private synchronized void doDispose() {
        if (jmDNSObject != null) {
            ((JmDNS) jmDNSObject).unregisterService(serviceInfo);
            try {
                ((JmDNS) jmDNSObject).close();
            } catch (IOException e) {
                // ignore
            }
        }
    }


}<commit_msg>[CAS-545]<commit_after>package codeOrchestra.colt.core.jmdns;

import codeOrchestra.colt.core.http.CodeOrchestraRPCHttpServer;
import codeOrchestra.util.LocalhostUtil;

import javax.jmdns.JmDNS;
import javax.jmdns.ServiceInfo;
import java.io.IOException;

/**
 * @author <NAME>
 */
public class JmDNSFacade {

    public static final String NONE_PROJECT_NAME = "NONE";

    private static JmDNSFacade instance;

    public synchronized static JmDNSFacade getInstance() {
        if (instance == null) {
            instance = new JmDNSFacade();
        }
        return instance;
    }

    private ServiceInfo serviceInfo;
    private JmDNS jmDNSObject;

    public JmDNSFacade() {
        updateServiceInfo(NONE_PROJECT_NAME);
        try {
            jmDNSObject = JmDNS.create(LocalhostUtil.getLocalhostIp());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void updateServiceInfo(String projectName) {
        serviceInfo = ServiceInfo.create("_colt._tcp.local.", getServiceName(projectName), CodeOrchestraRPCHttpServer.PORT, "COLT RPC");
    }

    private String getServiceName(String projectName) {
        return "colt::" + projectName + "::" + System.currentTimeMillis();
    }

    public void setProjectName(final String projectName) {
        new Thread(() -> {
            doSetProjectName(projectName);
        }).start();
    }

    private synchronized void doSetProjectName(String projectName) {
        jmDNSObject.unregisterService(serviceInfo);
        updateServiceInfo(projectName);
        try {
            jmDNSObject.registerService(serviceInfo);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void init() {
        new Thread(this::doInit).start();
    }

    private synchronized void doInit() {
        try {
            jmDNSObject.registerService(serviceInfo);
        } catch (IOException e) {
            // ignore
            e.printStackTrace();
        }
    }

    public void dispose() {
        new Thread(this::doDispose).start();
    }

    private synchronized void doDispose() {
        if (jmDNSObject != null) {
            jmDNSObject.unregisterService(serviceInfo);
            try {
                jmDNSObject.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }


}
{'fraction_non_alphanumeric': 0.10395010395010396, 'fraction_numerical': 0.0006237006237006237, 'mean_word_length': 2.32480995162405, 'pattern_counts': {'":': 2, '<': 5, '<?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': '3132754', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1375, 'n_words': 269}