示例#1
0
        protected override void DoStart()
        {
            WriteLog(MessageType.Trace, nameof(DoStart), "Entering");

            try
            {
                //pre-flight checks
                if (m_Provider == null)
                {
                    throw new AzosException(StringConsts.DAEMON_INVALID_STATE + "ObjectStoreService.DoStart(Provider=null)");
                }

                m_Provider.Start();

                m_Buckets = new List <Bucket>(m_BucketCount);
                for (var i = 0; i < m_BucketCount; i++)
                {
                    m_Buckets.Add(new Bucket());
                }

                base.DoStart();

                var clock = Stopwatch.StartNew();
                var now   = App.LocalizedTime;
                var all   = m_Provider.LoadAll();

                WriteLog(MessageType.Trace, nameof(DoStart), "Prep object list to load in " + clock.Elapsed);

                var cnt = 0;
                foreach (var entry in all)
                {
                    entry.Status   = ObjectStoreEntryStatus.Normal;
                    entry.LastTime = now;

                    var bucket = getBucket(entry.Key);
                    bucket.Add(entry.Key, entry);

                    cnt++;
                }
                WriteLog(MessageType.Trace, nameof(DoStart), "Have loaded {0} objects in {1} ".Args(cnt, clock.Elapsed));


                m_Thread              = new Thread(threadSpin);
                m_Thread.Name         = "ObjectStoreDaemon Thread";
                m_Thread.IsBackground = false;

                m_Thread.Start();
            }
            catch (Exception error)
            {
                AbortStart();

                if (m_Thread != null)
                {
                    m_Thread.Join();
                    m_Thread = null;
                }

                WriteLog(MessageType.CatastrophicError, nameof(DoStart), "Leaked exception: " + error.ToMessageWithType(), error);
                throw error;
            }

            WriteLog(MessageType.Trace, nameof(DoStart), "Exiting");
        }
示例#2
0
        protected override void DoStart()
        {
            log(MessageType.Info, "Entering DoStart()", null);

            try
            {
                //pre-flight checks
                if (m_Provider == null)
                {
                    throw new AzosException(StringConsts.SERVICE_INVALID_STATE + "ObjectStoreService.DoStart(Provider=null)");
                }

                m_Provider.Start();

                m_Buckets = new List <Bucket>(m_BucketCount);
                for (var i = 0; i < m_BucketCount; i++)
                {
                    m_Buckets.Add(new Bucket());
                }

                base.DoStart();

                var clock = Stopwatch.StartNew();
                var now   = App.LocalizedTime;
                var all   = m_Provider.LoadAll();

                log(MessageType.Info, "Prepared object list to load in " + clock.Elapsed, null);

                var cnt = 0;
                foreach (var entry in all)
                {
                    entry.Status   = ObjectStoreEntryStatus.Normal;
                    entry.LastTime = now;

                    var bucket = getBucket(entry.Key);
                    bucket.Add(entry.Key, entry);

                    cnt++;
                }
                log(MessageType.Info, string.Format("DoStart() has loaded {0} objects in {1} ", cnt, clock.Elapsed), null);


                m_Thread              = new Thread(threadSpin);
                m_Thread.Name         = "ObjectStoreService Thread";
                m_Thread.IsBackground = false;

                m_Thread.Start();
            }
            catch (Exception error)
            {
                AbortStart();

                if (m_Thread != null)
                {
                    m_Thread.Join();
                    m_Thread = null;
                }

                log(MessageType.CatastrophicError, "DoStart() exception: " + error.Message, null);
                throw error;
            }

            log(MessageType.Info, "Exiting DoStart()", null);
        }