MessageDispatcherConfigurator for the ForkJoinDispatcher. Creates a single ForkJoinDispatcher instance and returns the same instance each time Dispatcher is called.
Inheritance: MessageDispatcherConfigurator
Esempio n. 1
0
        private MessageDispatcherConfigurator ConfiguratorFrom(Config cfg)
        {
            if (!cfg.HasPath("id"))
            {
                throw new ConfigurationException(string.Format("Missing dispatcher `id` property in config: {0}", cfg.Root));
            }

            var id                     = cfg.GetString("id");
            var type                   = cfg.GetString("type");
            var throughput             = cfg.GetInt("throughput");
            var throughputDeadlineTime = cfg.GetTimeSpan("throughput-deadline-time").Ticks;


            MessageDispatcherConfigurator dispatcher;

            switch (type)
            {
            case "Dispatcher":
                dispatcher = new ThreadPoolDispatcherConfigurator(cfg, Prerequisites);
                break;

            case "TaskDispatcher":
                dispatcher = new TaskDispatcherConfigurator(cfg, Prerequisites);
                break;

            case "PinnedDispatcher":
                dispatcher = new PinnedDispatcherConfigurator(cfg, Prerequisites);
                break;

            case "ForkJoinDispatcher":
                dispatcher = new ForkJoinDispatcherConfigurator(cfg, Prerequisites);
                break;

            case "SynchronizedDispatcher":
                dispatcher = new CurrentSynchronizationContextDispatcherConfigurator(cfg, Prerequisites);
                break;

            case null:
                throw new ConfigurationException("Could not resolve dispatcher for path " + id + ". type is null");

            default:
                Type dispatcherType = Type.GetType(type);
                if (dispatcherType == null)
                {
                    throw new ConfigurationException("Could not resolve dispatcher type " + type + " for path " + id);
                }
                dispatcher = (MessageDispatcherConfigurator)Activator.CreateInstance(dispatcherType, cfg, Prerequisites);
                break;
            }

            return(new DispatcherConfigurator(dispatcher, id, throughput, throughputDeadlineTime));
        }