Exemple #1
0
        private static void Clear()
        {
            LogProxy.InfoFormat(BEGINCLEAR, Data.Count);

            DateTime clearTime = DateTime.Now.AddMinutes(-TimeLimit);

            if (LockDicObj.TryEnterWriteLock(WriteLockTimeout))
            {
                try
                {
                    var keys = (from o in Data
                                where o.Value.SynTime < clearTime
                                select o.Key).ToArray();

                    foreach (var key in keys)
                    {
                        Data.Remove(key);
                    }
                }
                catch (Exception ex)
                {
                    LogProxy.Error(ex, false);
                }
                finally
                {
                    LockDicObj.ExitWriteLock();
                }
            }

            LogProxy.InfoFormat(ENDCLEAR, Data.Count);
        }
Exemple #2
0
        static SynServerService()
        {
            try
            {
                LogProxy.InfoFormat(CURRENTAPPID, AppId);

                ApplicationName = SynServerConfig.ApplicationName;

                if (SynServerConfig.Port > 0)
                {
                    Port = SynServerConfig.Port;
                }

                if (SynServerConfig.ClearInterval > 0)
                {
                    ClearInterval = SynServerConfig.ClearInterval * 1000;
                }

                if (SynServerConfig.TimeLimit > 0)
                {
                    TimeLimit = SynServerConfig.TimeLimit;
                }
            }
            catch (Exception ex)
            {
                LogProxy.Fatal(ex, true);
            }
        }
Exemple #3
0
        private static void CacheClear()
        {
            string[] typesKeys = GetTypesKeys();

            foreach (string typeName in typesKeys)
            {
                SingleTypeCacheConfig config = SingleTypeCacheConfig.Get(typeName);
                Dictionary <string, MyCacheObject> caches = GetCaches(typeName);

                #region 固定缓存
                if (config.IsFix)
                {
                    if (config.NextFixLoggingTime < DateTime.Now)
                    {
                        config.NextFixLoggingTime = DateTime.Now.AddMinutes(FixLoggingInterval);
                        LogProxy.InfoFormat(CACHEISFIX, typeName, caches.Count);
                    }

                    continue;
                }
                #endregion

                OverdueTimeCacheClear(caches, typeName, config);

                if (config.Size > 0)
                {
                    OverSizeCacheClear(caches, typeName, config);
                }
            }
        }
Exemple #4
0
        private static void OverdueTimeCacheClear(Dictionary <string, MyCacheObject> caches, string typeName, SingleTypeCacheConfig config)
        {
            LogProxy.InfoFormat(BEFOREOVERDUETIMECACHECLEARINFO, typeName, caches.Count);

            string[] objKeys = GetOverdueTimeKeys(caches, config);
            if (objKeys == null || objKeys.Length == 0)
            {
                return;
            }
            CacheClear(caches, objKeys, ClearType.OverdueTime, config);

            LogProxy.InfoFormat(AFTEROVERDUETIMECACHECLEAR, typeName, caches.Count);
        }
Exemple #5
0
        private static void LockClear()
        {
            string[] lockIds = GetOverdueLock();
            if (lockIds == null || lockIds.Length == 0)
            {
                return;
            }

            LogProxy.InfoFormat(OVERDUELOCKSIZE, lockIds.Length);

            foreach (string lockId in lockIds)
            {
                Release(lockId);
            }
        }
        private static void Update(SRO obj)
        {
            Type type = obj.GetType();

            IMyDbParameter[] prams;
            string           updateSql = SqlBuilder.UpdateBuilder(obj, out prams);

            if (string.IsNullOrEmpty(updateSql))
            {
                LogProxy.InfoFormat(OBJECTSISNOTMODIFIED, obj.GetType(), obj.Id);
                return;
            }

            Save(obj, updateSql, prams);
        }
Exemple #7
0
        public static T GetService <T>() where T : IService
        {
            Type type = typeof(T);

            if (!Services.ContainsKey(type))
            {
                LogProxy.InfoFormat(GETSERVICETYPENULL, type);
                return(default(T));
            }

            IService obj = Services[type];

            if (!obj.IsInitialized)
            {
                return(default(T));
            }

            return((T)obj);
        }
Exemple #8
0
        private static void OverSizeCacheClear(Dictionary <string, MyCacheObject> caches, string typeName, SingleTypeCacheConfig config)
        {
            int cnt = caches.Count;

            LogProxy.InfoFormat(BEFOREOVERSIZECACHECLEARINFO, typeName, cnt);

            if (cnt < config.Size * 1.2)
            {
                return;
            }

            int clearSum = (int)(cnt - config.Size * 0.8);

            LogProxy.InfoFormat(SIZEOVER, typeName, cnt - config.Size, clearSum);

            string[] objKeys = GetOverSizeKeys(caches, clearSum, config);
            if (objKeys == null || objKeys.Length == 0)
            {
                return;
            }
            CacheClear(caches, objKeys, ClearType.OverSize, config);

            LogProxy.InfoFormat(AFTEROVERSIZECACHECLEARINFO, typeName, caches.Count);
        }
Exemple #9
0
        private static void SynClientServiceInit()
        {
            SynClientCommConfig.Init();
            SynClientConfig.Init();

            ServerURI = SynClientCommConfig.ServerURI;

            if (SynClientCommConfig.PostDueTime > 0)
            {
                PostDueTime = SynClientCommConfig.PostDueTime * 1000;
            }

            if (SynClientCommConfig.PostPeriod > 0)
            {
                PostPeriod = SynClientCommConfig.PostPeriod;
            }

            if (SynClientCommConfig.GetDueTime > 0)
            {
                GetDueTime = SynClientCommConfig.GetDueTime * 1000;
            }

            if (SynClientCommConfig.GetPeriod > 0)
            {
                GetPeriod = SynClientCommConfig.GetPeriod;
            }

            if (SynClientCommConfig.PostTryInterval > 0)
            {
                PostTryInterval = SynClientCommConfig.PostTryInterval;
            }

            if (SynClientCommConfig.PostTryMultiple > 0)
            {
                PostTryMultiple = SynClientCommConfig.PostTryMultiple;
            }

            if (SynClientCommConfig.PostTrys > 0)
            {
                PostTrys = SynClientCommConfig.PostTrys;
            }

            if (SynClientCommConfig.ClearInterval > 0)
            {
                ClearInterval = SynClientCommConfig.ClearInterval * 1000;
            }

            SynServerService = (ISynServerService)Activator.GetObject(typeof(ISynServerService), ServerURI);

            TimerCallback callback;

            callback  = new TimerCallback(PostCallbackMethod);
            PostTimer = new Timer(callback, null, PostDueTime, PostPeriod);

            CurrentIndex   = SynServerService.CurrentIndex;
            SynServerAppId = SynServerService.CurrentAppId;
            LogProxy.InfoFormat(SERVERNOTE, SynServerAppId, CurrentIndex);

            callback = new TimerCallback(GetCallbackMethod);
            GetTimer = new Timer(callback, null, GetDueTime, GetPeriod);

            Thread t = new Thread(SynClearThreadMethod);

            t.Start();
        }