예제 #1
0
        public void RegisterTempTask(MetaTask mst, IBrokerModule module)
        {
            QueueTask t = new QueueTask()
            {
                ModuleName = mst.ModuleName,

                //Description = mst.NameAndDescription,
                ChannelName = mst.ChannelName,
                Anteroom    = mst.ChannelName == null ? null : MessageChannels.GetAnteroom(mst.ChannelName),
                Parameters  = null,

                intervalType       = mst.intervalType,
                intervalValue      = mst.intervalValue,
                NameAndDescription = mst.NameAndDescription
            };

            if (t.Anteroom != null)
            {
                t.Anteroom.ChannelStatsIn  = Statistics.InitialiseModel(new BrokerStat("chan_in", mst.ChannelName));
                t.Anteroom.ChannelStatsOut = Statistics.InitialiseModel(new BrokerStat("chan_out", mst.ChannelName));
                //t.Anteroom.ChannelStatistic = Statistics.InitialiseModel(new BrokerStat("channel", mst.ChannelName));
            }
            //ModMod module = Modules.GetByName(t.ModuleName);
            //if (module == null)
            //    throw new Exception("required qmodule not found.");
            TaskScheduler.PlanItemEntryPoint ep = TaskEntry;
            if (t.intervalType == IntervalType.isolatedThread)
            {
                ep = IsolatedTaskEntry;
            }
            t.JobEntry = ep;
            t.Module   = module;
            t.Temp     = true;

            Tasks.Add(t);
            UpdatePlan();
        }
예제 #2
0
파일: Broker.cs 프로젝트: jangocheng/TaskMQ
        public void RegisterTempTask(MetaTask mst, IBrokerModule module)
        {
            if (module == null)
            {
                module = Modules.GetInstanceByName(mst.ModuleName);
                if (module == null)
                    throw new Exception("RegisterTempTask: required module not found: " + mst.ModuleName);
            }
            QueueTask t = new QueueTask()
            {
                ModuleName = mst.ModuleName,

                //Description = mst.NameAndDescription,
                ChannelName = mst.ChannelName,
                Anteroom = mst.ChannelName == null ? null : MessageChannels.GetAnteroom(mst.ChannelName),
                Parameters = null,

                intervalType = mst.intervalType,
                intervalValue = mst.intervalValue,
                NameAndDescription = mst.NameAndDescription
            };
            if (t.Anteroom != null && t.Anteroom.ChannelStatsIn == null)
            {
                t.Anteroom.ChannelStatsIn = Statistics.InitialiseModel(new BrokerStat("chan_in", mst.ChannelName));
                t.Anteroom.ChannelStatsOut = Statistics.InitialiseModel(new BrokerStat("chan_out", mst.ChannelName));
                //t.Anteroom.ChannelStatistic = Statistics.InitialiseModel(new BrokerStat("channel", mst.ChannelName));
            }
            if (module.Role == ExecutionType.Consumer)
            {
                MessageChannels.AssignMessageTypeToChannel(t.ChannelName, ((IModConsumer)module.MI).AcceptsModel, t.ModuleName);
            }
            //ModMod module = Modules.GetByName(t.ModuleName);
            //if (module == null)
            //    throw new Exception("required qmodule not found.");
            TaskScheduler.PlanItemEntryPoint ep = TaskEntry;
            if (t.intervalType == IntervalType.isolatedThread)
            {
                ep = IsolatedTaskEntry;
            }
            t.JobEntry = ep;

            t.Module = module;
            t.Temporary = true;

            //if (module.Role == ExecutionType.Consumer)
            //{
            //    if (!typeof(IModConsumer).IsAssignableFrom(module.MI.GetType()))
            //    {
            //        throw new Exception("Consumer module required a consumer interface");
            //    }
            //    if (t.ChannelName == null)
            //    {
            //        throw new Exception("Consumer module required a channel");
            //    }
            //    else
            //    {
            //        if (t.Anteroom.ChannelStatsIn == null && t.Anteroom.ChannelStatsIn == null)// first task for this channel?
            //        {
            //            // monitoring put operation
            //            t.Anteroom.ChannelStatsIn = Statistics.InitialiseModel(new BrokerStat("chan_in", t.ChannelName));
            //            t.Anteroom.ChannelStatsOut = Statistics.InitialiseModel(new BrokerStat("chan_out", t.ChannelName));
            //            // set selector
            //            TaskQueue.TQItemSelector selector = ((IModConsumer)module.MI).ConfigureSelector();
            //            // channel -> model(MType)
            //            MessageChannels.AssignMessageTypeToChannel(t.ChannelName, ((IModConsumer)module.MI).AcceptsModel, t.ModuleName);
            //            MessageChannel channel = MessageChannels.GetInstanceByName(t.ChannelName);
            //            channel.consumerSelector = selector;
            //        }
            //    }
            //}

            Tasks.Add(t);
            UpdatePlan();
        }
예제 #3
0
파일: Broker.cs 프로젝트: jangocheng/TaskMQ
        // bunch [channel~[message model], module[message model], +executionContext]
        // note: this is configure which channel is selected for custom module
        public void RegisterTask(string ChannelName, string moduleName,
            IntervalType it = IntervalType.intervalMilliseconds,
            long intervalValue = 100,
            Dictionary<string, object> parameters = null, string Description = "-")
        {
            ModMod module = Modules.GetInstanceByName(moduleName);
            MessageChannel channel = MessageChannels.GetInstanceByName(ChannelName);

            if (module == null)
                throw new Exception("RegisterTask: required module not found: " + moduleName);

            if (channel == null)
                throw new Exception("RegisterTask: required channel not found: " + ChannelName);

            TaskScheduler.PlanItemEntryPoint ep = TaskEntry;
            if (it == IntervalType.isolatedThread)
            {
                ep = IsolatedTaskEntry;
            }
            QueueTask t = new QueueTask()
            {
                Module = module,
                ModuleName = moduleName,

                //Description = Description,
                ChannelName = ChannelName,
                Anteroom = ChannelName == null ? null : MessageChannels.GetAnteroom(ChannelName),
                Parameters = parameters,

                intervalType = it,
                intervalValue = intervalValue,
                JobEntry = ep,

                NameAndDescription = Description
            };
            // task not required a channel only if module not implement consumer interface
            if (module.Role == ExecutionType.Consumer)
            {
                if (!typeof(IModConsumer).IsAssignableFrom(module.MI.GetType()))
                {
                    throw new Exception("Consumer module required a consumer interface");
                }
                if (ChannelName == null)
                {
                    throw new Exception("Consumer module required a channel");
                }
                else
                {
                    if (t.Anteroom.ChannelStatsIn == null && t.Anteroom.ChannelStatsIn == null)// first task for this channel?
                    {
                        // monitoring put operation
                        t.Anteroom.ChannelStatsIn = Statistics.InitialiseModel(new BrokerStat("chan_in", ChannelName));
                        t.Anteroom.ChannelStatsOut = Statistics.InitialiseModel(new BrokerStat("chan_out", ChannelName));
                        // set selector
                        TaskQueue.TQItemSelector selector = ((IModConsumer)module.MI).ConfigureSelector();
                        // channel -> model(MType)
                        MessageChannels.AssignMessageTypeToChannel(ChannelName, ((IModConsumer)module.MI).AcceptsModel, moduleName);
                        channel.consumerSelector = selector;
                    }
                }
            }
            Tasks.Add(t);
            UpdatePlan();
            //if (t.intervalType == TaskScheduler.IntervalType.isolatedThread)
            //    Scheduler.CreateIsolatedThreadForPlan(t);
        }