示例#1
0
 public void Prepare()
 {
     //logger.Info("type of interval:" + yml["acq"]["interval"].GetType());
     logger.Info("Yaml:\n" + yml);
     //Dictionary<string, Tuple<string, int>> targets = new Dictionary<string, Tuple<string, int>>();
     foreach (var ele in yml["cnc"])
     {
         logger.Info(ele);
         string ip   = ele["ip"].ToString();
         int    port = (int)ele["port"];
         string url  = ip + ":" + port;
         //targets[url] = new Tuple<string, int>(ip, port);
         if (targetHandles.ContainsKey(url))
         {
             continue;
         }
         try
         {
             var cr = new CncReader(ip, port);
             var ks = new KafkaSender(yml["kafka"]["ip"].ToString() + ":" + yml["kafka"]["port"].ToString());
             targetHandles[url] = new Tuple <CncReader, KafkaSender>(cr, ks);
             targetWorkers[url] = new Thread(new ParameterizedThreadStart(Worker));
         }
         catch (Exception e)
         {
             logger.Error(e.Message);
         }
     }
     logger.Info("Prepare over!");
 }
示例#2
0
        private static void Worker(Object obj)
        {
            SelfParam   sp     = (SelfParam)obj;
            var         self   = sp.Self;
            var         id     = sp.Id;
            CncReader   reader = self.targetHandles[id].Item1;
            KafkaSender sender = self.targetHandles[id].Item2;

            while (isWorking)
            {
                //logger.Info("Task#" + id + " started!");
                string resp = reader.read();
                sender.Send(self.yml["kafka"]["topic"].ToString(), resp);
                //logger.Info("Gen msg - " + resp);
                Thread.Sleep((int)self.yml["acq"]["interval"]);
            }
        }