Task based dispatcher
Inheritance: MessageDispatcher
 public TaskDispatcherConfigurator(Config config, IDispatcherPrerequisites prerequisites) : base(config, prerequisites)
 {
     _instance = new TaskDispatcher(this);
 }
Esempio n. 2
0
        /// <summary>
        ///     Froms the configuration.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns>MessageDispatcher.</returns>
        public MessageDispatcher FromConfig(string path)
        {
            //TODO: this should not exist, it is only here because we dont serialize dispathcer when doing remote deploy..
            if (string.IsNullOrEmpty(path))
            {
                var disp = new ThreadPoolDispatcher
                {
                    Throughput = 100
                };
                return disp;
            }

            Config config = _system.Settings.Config.GetConfig(path);
            string type = config.GetString("type");
            int throughput = config.GetInt("throughput");
            long throughputDeadlineTime = config.GetMillisDuration("throughput-deadline-time").Ticks;
            //shutdown-timeout
            //throughput-deadline-time
            //attempt-teamwork
            //mailbox-requirement

            MessageDispatcher dispatcher;
            switch (type)
            {
                case "Dispatcher":
                    dispatcher = new ThreadPoolDispatcher();
                    break;
                case "TaskDispatcher":
                    dispatcher = new TaskDispatcher();
                    break;
                case "PinnedDispatcher":
                    dispatcher = new SingleThreadDispatcher();
                    break;
                case "SynchronizedDispatcher":
                    dispatcher = new CurrentSynchronizationContextDispatcher();
                    break;
                default:
                    Type dispatcherType = Type.GetType(type);
                    if (dispatcherType == null)
                    {
                        throw new NotSupportedException("Could not resolve dispatcher type " + type);
                    }
                    dispatcher = (MessageDispatcher) Activator.CreateInstance(dispatcherType);
                    break;
            }

            dispatcher.Throughput = throughput;
            if (throughputDeadlineTime > 0)
            {
                dispatcher.ThroughputDeadlineTime = throughputDeadlineTime;
            }
            else
            {
                dispatcher.ThroughputDeadlineTime = null;
            }

            return dispatcher;
        }
Esempio n. 3
0
        /// <summary>
        ///     Froms the configuration.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns>MessageDispatcher.</returns>
        public MessageDispatcher FromConfig(string path)
        {
            //TODO: this should not exist, it is only here because we dont serialize dispathcer when doing remote deploy..
            if (string.IsNullOrEmpty(path))
            {
                var disp = new ThreadPoolDispatcher
                {
                    Throughput = 100
                };
                return(disp);
            }

            Config config                 = _system.Settings.Config.GetConfig(path);
            string type                   = config.GetString("type");
            int    throughput             = config.GetInt("throughput");
            long   throughputDeadlineTime = config.GetTimeSpan("throughput-deadline-time").Ticks;
            //shutdown-timeout
            //throughput-deadline-time
            //attempt-teamwork
            //mailbox-requirement

            MessageDispatcher dispatcher;

            switch (type)
            {
            case "Dispatcher":
                dispatcher = new ThreadPoolDispatcher();
                break;

            case "TaskDispatcher":
                dispatcher = new TaskDispatcher();
                break;

            case "PinnedDispatcher":
                dispatcher = new SingleThreadDispatcher();
                break;

            case "SynchronizedDispatcher":
                dispatcher = new CurrentSynchronizationContextDispatcher();
                break;

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

            default:
                Type dispatcherType = Type.GetType(type);
                if (dispatcherType == null)
                {
                    throw new NotSupportedException("Could not resolve dispatcher type " + type + " for path " + path);
                }
                dispatcher = (MessageDispatcher)Activator.CreateInstance(dispatcherType);
                break;
            }

            dispatcher.Throughput = throughput;
            if (throughputDeadlineTime > 0)
            {
                dispatcher.ThroughputDeadlineTime = throughputDeadlineTime;
            }
            else
            {
                dispatcher.ThroughputDeadlineTime = null;
            }

            return(dispatcher);
        }
Esempio n. 4
0
 public TaskDispatcherConfigurator(Config config, IDispatcherPrerequisites prerequisites) : base(config, prerequisites)
 {
     _instance = new TaskDispatcher(this);
 }