Example #1
0
 public TaskQueue.RepresentedModel GetValidationModel(string MessageType, string ChannelName = null)
 {
     // find all modules with messageType and channelname
     MessageChannel channel = MessageChannels.GetChannelForMessage(MessageType);
     if (channel == null || channel.AssignedMessageModel == null)
         return null;
     return new TaskQueue.RepresentedModel(channel.AssignedMessageModel.GetType());
 }
        public ChannelAnteroom GetAnteroomByMessage(string mtName)
        {
            MessageChannel mc = GetChannelForMessage(mtName);

            if (mc == null)
            {
                return(null);
            }
            return(GetAnteroom(mc.UniqueName));
        }
Example #3
0
 public void AddMessageChannel(MessageChannel mc)
 {
     lock (MChannelsList)
     {
         MessageChannels.Add(mc.UniqueName, MChannelsList.Count);
         //MessageChannelsModels.Add(mc.MessageType, MChannelsList.Count);
         MChannelsList.Add(mc);
     }
     ChannelAnteroom ante = GetAnteroom(mc.UniqueName);
     try
     {
         ante.Queue.OptimiseForSelector();
     }
     catch (Exception e)
     {
         logger.Exception(e, "OptimiseForSelector", "error in selector optimisation");
     }
 }
        public void AddMessageChannel(MessageChannel mc)
        {
            lock (MChannelsList)
            {
                MessageChannels.Add(mc.UniqueName, MChannelsList.Count);
                //MessageChannelsModels.Add(mc.MessageType, MChannelsList.Count);
                MChannelsList.Add(mc);
            }
            ChannelAnteroom ante = GetAnteroom(mc.UniqueName);

            try
            {
                ante.Queue.OptimiseForSelector();
            }
            catch (Exception e)
            {
                logger.Exception(e, "OptimiseForSelector", "error in selector optimisation");
            }
        }
        /// <summary>
        /// assume now for one message type we have only one channel
        /// </summary>
        /// <param name="channelName"></param>
        /// <param name="m"></param>
        /// <param name="moduleName">For exception information if occured model conflicts</param>
        public void AssignMessageTypeToChannel(string channelName, TItemModel m, string moduleName)
        {
            int v;

            if (MessageChannels.TryGetValue(channelName, out v))
            {
                MessageChannel channel = MChannelsList[v];
                if (channel.AssignedMessageModel == null)
                {
                    channel.FirstModuleNameAssigned = moduleName;
                    channel.AssignedMessageType     = m.ItemTypeName;
                    channel.AssignedMessageModel    = m;
                    //if (!MessageTypes.ContainsKey(m.ItemTypeName))
                    MessageTypes.Add(m.ItemTypeName, v);
                }
            }
            else
            {
                throw new Exception("Error: assign message type model to channel: channel name " + channelName + "not exists");
            }
        }
        public ChannelAnteroom GetAnteroom(string name)
        {
            ChannelAnteroom anteroom = null;

            if (Anterooms.TryGetValue(name, out anteroom))
            {
                return(anteroom);
            }
            else
            {
                MessageChannel mc = GetInstanceByName(name);
                anteroom             = new ChannelAnteroom();
                anteroom.ChannelName = name;

                TaskQueue.Providers.QueueConnectionParameters qparams = Connections[mc.ConnectionName];
                anteroom.Queue = qparams.QueueInstance;
                //anteroom.Queue = (TaskQueue.ITQueue)Activator.CreateInstance(qparams.QueueInstance.GetType()); //Queues.GetQueue(mc.QueueName);
                try
                {
                    anteroom.Queue.InitialiseFromModel(new RepresentedModel(typeof(TaskMessage)), qparams);// schema free only queue providers (mongodb)
                    // set selector to queue
                    anteroom.Queue.SetSelector(mc.consumerSelector);
                }
                catch (QueueConnectionException e)
                {
                    logger.Warning(e.Message);
                }
                catch (Exception e)
                {
                    logger.Exception(e, "Anterooms.Add", "anteroom initialisation error");
                }

                Anterooms.Add(name, anteroom);

                return(anteroom);
            }

            return(null);
        }
Example #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);
        }