Inheritance: TaskScheduler.PlanItem
Esempio n. 1
0
        private int ConsumerEntry(QueueTask task)
        {
            //Console.WriteLine("consumer: {0}", task.ChannelName);
            //QueueTask task = pi as QueueTask;
            IBrokerModule mod = task.Module;

            // Pop item from queue
            ChannelAnteroom ch = task.Anteroom;//MessageChannels.GetAnteroom(task.ChannelName);

            if (ch.InternalEmptyFlag)
            {
                return(1);
            }

            TaskQueue.Providers.TaskMessage message = ch.Next();

            if (message == null)
            {
                return(1);
            }
            //if (message == null)
            //{
            //    // this must be replaced with better way communication with message bus
            //    Console.WriteLine("Consumer empty, suspended: {0}", task.ChannelName);
            //    task.Suspended = true;
            //    return;
            //}
            TaskQueue.Providers.TaskMessage item = message;

            bool updated = ((IModConsumer)mod.MI).Push(task.Parameters, ref message);

            if (updated)
            {
                message.Processed     = true;
                message.ProcessedTime = DateTime.UtcNow;
            }

            updated = updated || (!Object.ReferenceEquals(item, message));// model is modified
            if (updated)
            {
                ch.Update(message);
            }
            ch.ChannelStatsOut.inc(); // inc stats
            return(0);
        }
Esempio n. 2
0
        private int TaskEntry(TaskScheduler.ThreadContext ti, TaskScheduler.PlanItem pi)
        {
            QueueTask task = pi as QueueTask;

            switch (task.Module.Role)
            {
            case ExecutionType.Consumer:
                return(ConsumerEntry(task));

                break;

            case ExecutionType.Producer:
                return(ProducerEntry(task));

                break;
            }
            return(1);
        }
Esempio n. 3
0
 private int IsolatedTaskEntry(TaskScheduler.ThreadContext ti, TaskScheduler.PlanItem pi)
 {
     QueueTask task = pi as QueueTask;
     try
     {
         ((IModIsolatedProducer)task.Module.MI).IsolatedProducer(task.Parameters);
     }
     catch (Exception e)
     {
         logger.Exception(e, "isolated call procedure", "module '{0}' will be turned off", task.ModuleName);
         ti.StopThread = true;
     }
     //task.Module.Producer(task.Parameters);
     while (!ti.StopThread)
     {
         System.Threading.Thread.Sleep(100);
     }
     ((IModIsolatedProducer)task.Module.MI).IsolatedProducerStop();
     return 1;
 }
Esempio n. 4
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();
        }
Esempio n. 5
0
 private int ProducerEntry(QueueTask task)
 {
     logger.Debug("(not implemented...) producer: {0}", task.ChannelName);
     return 1;
 }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
        // 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);
        }