예제 #1
0
        public void RemoveCache(byte[] upMsg)
        {
            UpTransmisstion[] upTrans = TransmissionUtil.DecompressAndDeserialize <UpTransmisstion>(upMsg);
            foreach (UpTransmisstion up in upTrans)
            {
                if (up.Code == UpTransmisstionCode.Ok)
                {
                    string key = up.Key;

                    try
                    {
                        byte[] data;
                        _masterCacheList.TryRemove(key, out data);
                        data = null;
                    }
                    catch (Exception ex)
                    {
                        Logger.Log.Error(true, "删除任务缓存异常,key:" + key, ex);
                    }

                    try
                    {
                        _masterCache.DeleteCache(up.Key);
                    }
                    catch (Exception ex)
                    {
                        Logger.Log.Error(true, "删除目录缓存异常,key:" + key, ex);
                    }

                    Logger.Log.Info(false, $"{up.Key},删除任务,内存计算任务数量:" + _masterCacheList.Count.ToString());
                }
            }
            upTrans = null;
            upMsg   = null;
        }
예제 #2
0
        public void AddTask(byte[] taskMsg)
        {
            try
            {
                DownTransmission[] downTrans = TransmissionUtil.DecompressAndDeserialize <DownTransmission>(taskMsg);

                foreach (DownTransmission down in downTrans)
                {
                    byte[] data = TransmissionUtil.SerializeAndCompress <DownTransmission>(down);

                    _slaveCache.WriteCache(down.Key, data);

                    _slaveCacheList.TryAdd(down.Key, down);

                    SendBackOk(down);

                    Logger.Log.Info(false, $"{down.Key},增加任务,内存计算任务数量:" + _slaveCacheList.Count.ToString());

                    data = null;
                }

                downTrans = null;
                taskMsg   = null;
            }
            catch (Exception ex)
            {
                Logger.Log.Error(true, "任务解析异常:", ex);
            }
        }
예제 #3
0
        private void LoadCache()
        {
            if (GlobalConfig.Config.NodeType == NodeType.Slave)
            {
                ConcurrentDictionary <string, byte[]> dic = _slaveCache.GetCacheDictionary();

                foreach (KeyValuePair <string, byte[]> kv in dic)
                {
                    if (kv.Value != null && kv.Value.Length > 0)
                    {
                        try
                        {
                            DownTransmission[] downTrans = TransmissionUtil.DecompressAndDeserialize <DownTransmission>(kv.Value);

                            foreach (DownTransmission down in downTrans)
                            {
                                _slaveCacheList.TryAdd(kv.Key, down);
                            }

                            downTrans = null;
                        }
                        catch (Exception ex)
                        {
                            Logger.Log.Info(true, "加载子节点任务:", ex);
                        }
                    }
                }

                dic.Clear();
                dic = null;
            }
        }
예제 #4
0
        private void SendBackOk(DownTransmission downTrans)
        {
            UpTransmisstion upTransmisstion = new UpTransmisstion()
            {
                Key  = downTrans.Key,
                Code = UpTransmisstionCode.Ok,
                Desc = UpTransmisstion.GetDesc(UpTransmisstionCode.Ok),
            };

            byte[] data = TransmissionUtil.SerializeAndCompress <UpTransmisstion>(upTransmisstion);

            SlaveClient.Send(data);

            upTransmisstion = null;
            data            = null;
        }
예제 #5
0
        private void SendBackOk(DownTransmission downTrans)
        {
            UpTransmisstion upTransmisstion = new UpTransmisstion()
            {
                Key  = downTrans.Key,
                Code = UpTransmisstionCode.Ok,
                Desc = UpTransmisstion.GetDesc(UpTransmisstionCode.Ok),
            };

            byte[] data = TransmissionUtil.SerializeAndCompress <UpTransmisstion>(upTransmisstion);

            string remoteInfo;

            _channelMessageHandler.Send(String.Empty, data, out remoteInfo);

            upTransmisstion = null;
            data            = null;
        }
예제 #6
0
        private void ParallelCalculate(ICalculateContext context)
        {
            if (context == null)
            {
                Logger.Log.Info(true, "ParallelCalculate参数(context)为空");
                return;
            }

            try
            {
                bool isCalc = true;
                if (context.CalculateType == CalculateType.Expression)
                {
                    foreach (IMetaData md in context.CalculateInpute.DataSource)
                    {
                        if (_winList.ContainsKey(md.TagId))
                        {
                            md.TagName  = _winList[md.TagId].Current.TagName;
                            md.TagTime  = _winList[md.TagId].Current.TagTime;
                            md.TagValue = _winList[md.TagId].Current.TagValue;
                        }
                        else
                        {
                            isCalc = false;
                            break;
                        }
                    }
                }

                if (isCalc)
                {
                    if (_channelMessageHandler.ClientCount > 0)
                    {
                        #region
                        CalculateContext calcContext = (CalculateContext)context;

                        DownTransmission downTrans = new DownTransmission(DownTransmission.GetNewTransmissionId(calcContext.Name, calcContext.LeftTime, context.RightTime), calcContext);

                        byte[] data = TransmissionUtil.SerializeAndCompress <DownTransmission>(downTrans);

                        if (data != null && data.Length > 0)
                        {
                            _masterCache.WriteCache(downTrans.Key, data);

                            _masterCacheList.TryAdd(downTrans.Key, data);

                            Logger.Log.Info(false, $"{downTrans.Key},增加任务,内存计算任务数量:" + _masterCacheList.Count.ToString());
                        }

                        calcContext = null;
                        downTrans   = null;
                        data        = null;
                        #endregion
                    }
                    else
                    {
                        #region
                        if (_workList.Count <= 0)
                        {
                            if (_defaultWorker == null)
                            {
                                _defaultWorker = Worker.Worker.GetDefaultWorker();
                            }

                            _defaultWorker.DoWork(context);
                        }
                        else
                        {
                            IWorker worker = GetPollWorker();
                            if (worker != null)
                            {
                                worker.DoWork(context);
                            }
                        }
                        #endregion
                    }
                }
                context.CalculateInpute.DataSource = null;
                context = null;
            }
            catch (Exception ex)
            {
                Logger.Log.Info(true, $"{context.Name}-{context.Desc}-线程({Thread.CurrentThread.ManagedThreadId.ToString("0000")}):【{context.LeftTime.ToString()}-{context.RightTime.ToString()}】,异常:", ex);
            }
        }