<commit_before>﻿namespace NHibernate.ZMQLogPublisher
{
    using System;
    using System.Diagnostics;
    using System.Text;
    using System.Threading.Tasks;

    using ZMQ;

    public class Publisher
    {
        private static Context context;

        private static bool running;

        public static void Start()
        {
            running = true;
            context = new Context(1);
            
            new Task(ListenAndPublishLogMessages).Start();

            LoggerProvider.SetLoggersFactory(new ZmqLoggerFactory(context));
        }

        public static void Shutdown()
        {
            running = false;
            LoggerProvider.SetLoggersFactory(new NoLoggingLoggerFactory());
        }

        private static void ListenAndPublishLogMessages()
        {
            using (Socket publisher = context.Socket(SocketType.PUB), loggers = context.Socket(SocketType.PULL))
            {
                publisher.Bind("tcp://*:5555");
                publisher.Linger = 0;

                loggers.Bind("inproc://loggers");
                loggers.Linger = 0;

                while (running)
                {
                    var logMessage = loggers.Recv(Encoding.Unicode);

                    publisher.Send(logMessage, Encoding.Unicode);
                }
            }

            context.Dispose();
        }
    }
}<commit_msg>Wait for sockets to start before returning from Publisher.Start<commit_after>﻿namespace NHibernate.ZMQLogPublisher
{
    using System;
    using System.Diagnostics;
    using System.Text;
    using System.Threading.Tasks;

    using ZMQ;

    public class Publisher
    {
        private static Context context;

        private static bool running;

        public static void Start()
        {
            context = new Context(1);
            
            new Task(ListenAndPublishLogMessages).Start();

            while(!running)
            {
            }

            LoggerProvider.SetLoggersFactory(new ZmqLoggerFactory(context));
        }

        public static void Shutdown()
        {
            running = false;
            LoggerProvider.SetLoggersFactory(new NoLoggingLoggerFactory());
        }

        private static void ListenAndPublishLogMessages()
        {
            using (Socket publisher = context.Socket(SocketType.PUB), loggers = context.Socket(SocketType.PULL))
            {
                publisher.Bind("tcp://*:5555");
                publisher.Linger = 0;

                loggers.Bind("inproc://loggers");
                loggers.Linger = 0;
                running = true;
                
                while (running)
                {
                    var logMessage = loggers.Recv(Encoding.Unicode, timeout: 1000);
                    if(logMessage != null)
                    publisher.Send(logMessage, Encoding.Unicode);
                }
            }

            context.Dispose();
        }
    }
}
{'fraction_non_alphanumeric': 0.08532423208191127, 'fraction_numerical': 0.0061433447098976105, 'mean_word_length': 1.5398613518197575, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '122863', 'n_tokens_mistral': 759, 'n_tokens_neox': 705, 'n_words': 149}