<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DMT.Matcher.Module.Helper;
using DMT.Matcher.Module.Partition;

namespace DMT.Matcher.Module
{
    public class MatcherModule
    {
        #region static instance

        private static MatcherModule instance;

        internal static MatcherModule Instance
        {
            get
            {
                if (instance == null)
                {
                    throw new InvalidOperationException("Module has not been started yet.");
                }

                return instance;
            }
        }

        #endregion

        public readonly Guid Id;

        public MatcherModule()
        {
            this.Id = Guid.NewGuid();
        }

        public static MatcherModule StartModule(string[] argv)
        {
            if (instance != null)
            {
                throw new InvalidOperationException("Matcher module has already started.");
            }

            instance = new MatcherModule();
            instance.Start(argv);

            return instance;
        }

        private void Start(string[] argv)
        {
            MatcherStartArguments startArgs = new MatcherStartArguments(argv);

            // TODO: srart matcher service
            using (var client = PartitionServiceHelper.CreateClient(startArgs.PartitionServiceUri))
            {
                client.RegisterMatcher(new MatcherInfo() { Id = this.Id });
                // TODO: get partition, parse it
            }
        }
    }
}<commit_msg>exit matcher when cannot register with partitioner<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DMT.Matcher.Module.Helper;
using DMT.Matcher.Module.Partition;

namespace DMT.Matcher.Module
{
    public class MatcherModule
    {
        private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();

        #region static instance

        private static MatcherModule instance;

        internal static MatcherModule Instance
        {
            get
            {
                if (instance == null)
                {
                    throw new InvalidOperationException("Module has not been started yet.");
                }

                return instance;
            }
        }

        #endregion

        public readonly Guid Id;

        public MatcherModule()
        {
            this.Id = Guid.NewGuid();
        }

        public static MatcherModule StartModule(string[] argv)
        {
            if (instance != null)
            {
                throw new InvalidOperationException("Matcher module has already started.");
            }

            instance = new MatcherModule();
            instance.Start(argv);

            return instance;
        }

        private void Start(string[] argv)
        {
            MatcherStartArguments startArgs = new MatcherStartArguments(argv);

            // TODO: srart matcher service
            using (var client = PartitionServiceHelper.CreateClient(startArgs.PartitionServiceUri))
            {
                if (!client.RegisterMatcher(new MatcherInfo() { Id = this.Id }))
                {
                    logger.Fatal("Could not register with partitioning module. Shutting down.");
                    return;
                }
                // TODO: get partition, parse it
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.07552526973310619, 'fraction_numerical': 0.0, 'mean_word_length': 1.6038433111603843, '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': '7142874', 'n_tokens_mistral': 843, 'n_tokens_neox': 795, 'n_words': 221}