Inheritance: IBrokerModule
Example #1
0
        public void HostModule(string interfaceName, ModMod mod, IBroker b)
        {
            Type iface = null;

            if (ModInterfaces.ContainsKey(interfaceName))
            {
                iface = ModInterfaces[interfaceName];
            }
            else if (ModLocalInterfaces.ContainsKey(interfaceName))
            {
                iface = ModLocalInterfaces[interfaceName];
            }
            else
            {
                logger.Error("the module at {0} not found", interfaceName);
                return;
                // error
            }
            var tc = typeof(IModConsumer);

            mod.Role        = tc.IsAssignableFrom(iface) ? ExecutionType.Consumer : ExecutionType.Producer;
            mod.MI          = (IMod)Activator.CreateInstance(iface);
            mod.ModAssembly = loadedInterfaces[interfaceName];
            if (Modules.ContainsKey(mod.UniqueName))
            {
                logger.Error("the module: {0} at {1} already registered", mod.UniqueName, interfaceName);
                return;
            }
            Modules.Add(mod.UniqueName, mod);

            // TODO: Extract to broker context
            mod.MI.Initialise(b, mod);
            MetaTask[] tasks = mod.MI.RegisterTasks(mod);
            if (tasks != null)
            {
                foreach (MetaTask t in tasks)
                {
                    b.RegisterTempTask(t, mod);
                }
            }
        }
Example #2
0
        public void HostModule(string interfaceName, ModMod mod, IBroker b)
        {
            Type iface = null;
            if (ModInterfaces.ContainsKey(interfaceName))
            {
                iface = ModInterfaces[interfaceName];
            }
            else if (ModLocalInterfaces.ContainsKey(interfaceName))
            {
                iface = ModLocalInterfaces[interfaceName];
            }
            else
            {
                logger.Error("the module at {0} not found", interfaceName);
                return;
                // error
            }
            var tc = typeof(IModConsumer);
            mod.Role = tc.IsAssignableFrom(iface) ? ExecutionType.Consumer : ExecutionType.Producer;
            mod.MI = (IMod)Activator.CreateInstance(iface);
            mod.ModAssembly = loadedInterfaces[interfaceName];
            if (Modules.ContainsKey(mod.UniqueName))
            {
                logger.Error("the module: {0} at {1} already registered", mod.UniqueName, interfaceName);
                return;
            }
            Modules.Add(mod.UniqueName, mod);

            // TODO: Extract to broker context
            mod.MI.Initialise(b, mod);
            MetaTask[] tasks = mod.MI.RegisterTasks(mod);
            if (tasks != null)
                foreach (MetaTask t in tasks)
                {
                    b.RegisterTempTask(t, mod);
                }
        }
Example #3
0
        private void ExitMod(string name)
        {
            ModMod m = GetByName(name);

            m.ExitEntry();
        }
Example #4
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);
        }