Example #1
0
        private MessageDispatcherConfigurator ConfiguratorFrom(Config cfg)
        {
            if (cfg.IsNullOrEmpty())
            {
                throw ConfigurationException.NullOrEmptyConfig <MessageDispatcherConfigurator>();
            }

            if (!cfg.HasPath("id"))
            {
                throw new ConfigurationException($"Missing dispatcher `id` property in config: {cfg.Root}");
            }

            var id   = cfg.GetString("id", null);
            var type = cfg.GetString("type", null);


            MessageDispatcherConfigurator dispatcher;

            /*
             * Fallbacks are added here in order to preserve backwards compatibility with versions of AKka.NET prior to 1.1,
             * before the ExecutorService system was implemented
             */
            switch (type)
            {
            case "Dispatcher":
                dispatcher = new DispatcherConfigurator(cfg, Prerequisites);
                break;

            case "TaskDispatcher":
                dispatcher = new DispatcherConfigurator(TaskExecutorConfig.WithFallback(cfg), Prerequisites);
                break;

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

            case "ForkJoinDispatcher":
                dispatcher = new DispatcherConfigurator(ForkJoinExecutorConfig.WithFallback(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(dispatcher);
        }
Example #2
0
        private MessageDispatcherConfigurator ConfiguratorFrom(Config cfg)
        {
            if (!cfg.HasPath("id")) throw new ConfigurationException($"Missing dispatcher `id` property in config: {cfg.Root}");

            var id = cfg.GetString("id");
            var type = cfg.GetString("type");


            MessageDispatcherConfigurator dispatcher;
            /*
             * Fallbacks are added here in order to preserve backwards compatibility with versions of AKka.NET prior to 1.1,
             * before the ExecutorService system was implemented
             */
            switch (type)
            {
                case "Dispatcher":
                    dispatcher = new DispatcherConfigurator(cfg, Prerequisites);
                    break;
                case "TaskDispatcher":
                    dispatcher = new DispatcherConfigurator(TaskExecutorConfig.WithFallback(cfg), Prerequisites);
                    break;
                case "PinnedDispatcher":
                    dispatcher = new PinnedDispatcherConfigurator(cfg, Prerequisites);
                    break;
                case "ForkJoinDispatcher":
                    dispatcher = new DispatcherConfigurator(ForkJoinExecutorConfig.WithFallback(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 dispatcher;
        }