Example #1
0
 // Token: 0x0600043A RID: 1082 RVA: 0x0001CD5C File Offset: 0x0001AF5C
 private object ThreadPoolRoutine(object state)
 {
     UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask scheduledTask = state as UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask;
     if (scheduledTask == null)
     {
         throw new ArgumentException("Unexpected state object or null", "state");
     }
     try
     {
         bool      taskExecuted = false;
         Exception ex           = null;
         using (LocaleThreadState.EnsurePrimaryLocale())
         {
             if (!SmartThreadPool.IsWorkItemCanceled)
             {
                 try
                 {
                     taskExecuted = true;
                     this.taskRoutine(scheduledTask.TaskKey);
                 }
                 catch (Exception ex2)
                 {
                     ex = ex2;
                     this.log.Error(string.Format("Task {0} cought unhandled exception from task routine", scheduledTask), ex2);
                 }
             }
             if (scheduledTask.Callbacks != null)
             {
                 foreach (UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTaskCallback scheduledTaskCallback in scheduledTask.Callbacks)
                 {
                     try
                     {
                         scheduledTaskCallback.Callback(new UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTaskCallbackEventArgs(scheduledTask.TaskKey, scheduledTaskCallback.State, ex, taskExecuted));
                     }
                     catch (Exception ex3)
                     {
                         this.log.Error(string.Format("Task {0} callback failed", scheduledTask), ex3);
                     }
                 }
             }
         }
     }
     catch (Exception ex4)
     {
         this.log.Error(string.Format("Task {0} cought unhandled exception during task processing", scheduledTask), ex4);
     }
     finally
     {
         object obj = this.syncLock;
         lock (obj)
         {
             this.ongoingTasks.Remove(scheduledTask);
         }
     }
     return(null);
 }
Example #2
0
        internal void CallbackRoutine(
            UpdateTaskScheduler <int, Guid> .ScheduledTaskCallbackEventArgs state)
        {
            Action action = (Action)null;

            lock (this.syncLock)
            {
                DiscoveryNetObjectStatusManager.CallbackInfo callbackInfo;
                if (this.awaitingCallbacks.TryGetValue(state.State, out callbackInfo))
                {
                    if (callbackInfo.AwaitingCallsCount > 1)
                    {
                        --callbackInfo.AwaitingCallsCount;
                        if (DiscoveryNetObjectStatusManager.log.get_IsDebugEnabled())
                        {
                            DiscoveryNetObjectStatusManager.log.DebugFormat("Supressing callback for profile {0}, update request {1}, waiting for {2} more", (object)state.TaskKey, (object)state.State, (object)callbackInfo.AwaitingCallsCount);
                        }
                    }
                    else
                    {
                        action = callbackInfo.CallbackRoutine;
                        this.awaitingCallbacks.Remove(state.State);
                        if (DiscoveryNetObjectStatusManager.log.get_IsDebugEnabled())
                        {
                            DiscoveryNetObjectStatusManager.log.DebugFormat("Firing callback for profile {0}, update request {1}", (object)state.TaskKey, (object)state.State);
                        }
                    }
                }
                else
                {
                    DiscoveryNetObjectStatusManager.log.ErrorFormat("Callback for profile {0} with unknown update request {1} received", (object)state.TaskKey, (object)state.State);
                }
            }
            if (action == null)
            {
                return;
            }
            try
            {
                action();
            }
            catch (Exception ex)
            {
                DiscoveryNetObjectStatusManager.log.Error((object)string.Format("Callback handling routine for profile {0}, update request {1} failed", (object)state.TaskKey, (object)state.State), ex);
            }
        }
Example #3
0
        private void RequestUpdateInternal(
            List <int> profileIDs,
            Action updateFinishedCallback,
            TimeSpan waitForChangesDelay)
        {
            UpdateTaskScheduler <int, Guid> .ScheduledTaskCallback callback = (UpdateTaskScheduler <int, Guid> .ScheduledTaskCallback)null;
            if (updateFinishedCallback != null)
            {
                Guid guid = Guid.NewGuid();
                lock (this.syncLock)
                    this.awaitingCallbacks.Add(guid, new DiscoveryNetObjectStatusManager.CallbackInfo(updateFinishedCallback, profileIDs.Count));
                callback = new UpdateTaskScheduler <int, Guid> .ScheduledTaskCallback(new Action <UpdateTaskScheduler <int, Guid> .ScheduledTaskCallbackEventArgs>(this.CallbackRoutine), guid);

                if (DiscoveryNetObjectStatusManager.log.get_IsDebugEnabled())
                {
                    DiscoveryNetObjectStatusManager.log.DebugFormat("Registering awaiting callback for profiles {0}, request: {1}", (object)string.Join(", ", profileIDs.Select <int, string>((Func <int, string>)(p => p.ToString())).ToArray <string>()), (object)guid);
                }
            }
            foreach (int profileId in profileIDs)
            {
                this.scheduler.RequestUpdateAsync(profileId, callback, waitForChangesDelay);
            }
        }
Example #4
0
        public void RequestUpdateAsync(
            TTaskKey taskKey,
            UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTaskCallback callback,
            TimeSpan waitForChangesDelay)
        {
            UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask scheduledTask1 = new UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask();

            scheduledTask1.TaskKey          = taskKey;
            scheduledTask1.PlannedExecution = DateTime.UtcNow.Add(waitForChangesDelay);
            List <UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTaskCallback> scheduledTaskCallbackList;

            if (callback == null)
            {
                scheduledTaskCallbackList = (List <UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTaskCallback>)null;
            }
            else
            {
                scheduledTaskCallbackList = new List <UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTaskCallback>();
                scheduledTaskCallbackList.Add(callback);
            }
            scheduledTask1.Callbacks = scheduledTaskCallbackList;
            UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask scheduledTask2 = scheduledTask1;
            if (this.log.get_IsDebugEnabled())
            {
                this.log.DebugFormat("RequestUpdate for Task {0} - Enter", (object)taskKey);
            }
            lock (this.syncLock)
            {
                UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask scheduledTask3;
                if (this.scheduledTasks.TryFind(scheduledTask2, (IComparer <UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask>)UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask.IdentityComparer.Instance, ref scheduledTask3))
                {
                    if (scheduledTask2.PlannedExecution < scheduledTask3.PlannedExecution)
                    {
                        if (scheduledTask3.Callbacks != null)
                        {
                            if (scheduledTask2.Callbacks != null)
                            {
                                scheduledTask2.Callbacks.AddRange((IEnumerable <UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTaskCallback>)scheduledTask3.Callbacks);
                            }
                            else
                            {
                                scheduledTask2.Callbacks = scheduledTask3.Callbacks;
                            }
                        }
                        this.scheduledTasks.Remove(scheduledTask3, (IComparer <UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask>)UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask.IdentityComparer.Instance);
                        this.scheduledTasks.Enqueue(scheduledTask2);
                        if (this.log.get_IsInfoEnabled())
                        {
                            this.log.InfoFormat("Task {0} was rescheduled from {1} to {2}", (object)scheduledTask2, (object)scheduledTask3.PlannedExecution, (object)scheduledTask2.PlannedExecution);
                        }
                        Monitor.PulseAll(this.syncLock);
                    }
                    else
                    {
                        if (scheduledTask2.Callbacks != null)
                        {
                            if (scheduledTask3.Callbacks != null)
                            {
                                scheduledTask3.Callbacks.AddRange((IEnumerable <UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTaskCallback>)scheduledTask2.Callbacks);
                            }
                            else
                            {
                                scheduledTask3.Callbacks = scheduledTask2.Callbacks;
                            }
                        }
                        if (this.log.get_IsInfoEnabled())
                        {
                            this.log.InfoFormat("Task {0} has been scheduled already at {1}, requested time {2}", (object)scheduledTask2, (object)scheduledTask3.PlannedExecution, (object)scheduledTask2.PlannedExecution);
                        }
                    }
                }
                else
                {
                    this.scheduledTasks.Enqueue(scheduledTask2);
                    if (this.log.get_IsInfoEnabled())
                    {
                        this.log.InfoFormat("Task {0} has been scheduled for {1}", (object)scheduledTask2, (object)scheduledTask2.PlannedExecution);
                    }
                    Monitor.PulseAll(this.syncLock);
                }
            }
            if (!this.log.get_IsDebugEnabled())
            {
                return;
            }
            this.log.DebugFormat("RequestUpdate for Task {0} - Leave", (object)taskKey);
        }
Example #5
0
 public override int Compare(
     UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask x,
     UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask y)
 {
     return(DateTime.Compare(y.PlannedExecution, x.PlannedExecution));
 }
Example #6
0
 public int GetHashCode(
     UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask obj)
 {
     return(obj.TaskKey.GetHashCode());
 }
Example #7
0
 public bool Equals(
     UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask x,
     UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask y)
 {
     return(x.TaskKey.CompareTo((object)y.TaskKey) == 0);
 }
Example #8
0
 public override int Compare(
     UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask x,
     UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask y)
 {
     return(x.TaskKey.CompareTo((object)y.TaskKey));
 }
Example #9
0
 private void SchedulerRoutine()
 {
     this.log.Debug((object)"Scheduler: scheduling thread started");
     while (true)
     {
         UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask scheduledTask = (UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask)null;
         lock (this.syncLock)
         {
             if (this.ChangesActive)
             {
                 this.log.Debug((object)"Suspending Scheduler: ongoing changes detected");
                 Monitor.Wait(this.syncLock);
             }
             else if (this.scheduledTasks.get_Count() == 0)
             {
                 this.log.Debug((object)"Suspending Scheduler: no pending tasks to process");
                 Monitor.Wait(this.syncLock);
             }
             else
             {
                 DateTime utcNow = DateTime.UtcNow;
                 scheduledTask = this.scheduledTasks.Peek();
                 if (scheduledTask.PlannedExecution > utcNow)
                 {
                     TimeSpan timeout = scheduledTask.PlannedExecution.Subtract(utcNow);
                     if (this.log.get_IsDebugEnabled())
                     {
                         this.log.DebugFormat("Suspending Scheduler: woke up too early, next task {0} is scheduled for {1}, will be suspended for {2}", (object)scheduledTask, (object)scheduledTask.PlannedExecution, (object)timeout);
                     }
                     scheduledTask = (UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask)null;
                     Monitor.Wait(this.syncLock, timeout);
                 }
                 else if (this.ongoingTasks.Contains(scheduledTask))
                 {
                     this.scheduledTasks.Remove(scheduledTask, (IComparer <UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask>)UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask.IdentityComparer.Instance);
                     scheduledTask.PlannedExecution = utcNow.Add(this.postponeTaskDelay);
                     this.scheduledTasks.Enqueue(scheduledTask);
                     if (this.log.get_IsDebugEnabled())
                     {
                         this.log.DebugFormat("Scheduler: task {0} is being executed, rescheduling its next execution to {1}", (object)scheduledTask, (object)scheduledTask.PlannedExecution);
                     }
                     scheduledTask = (UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask)null;
                 }
                 else
                 {
                     scheduledTask = this.scheduledTasks.Dequeue();
                     this.ongoingTasks.Add(scheduledTask);
                     if (this.log.get_IsDebugEnabled())
                     {
                         this.log.DebugFormat("Scheduler: Task {0} is planed to get executed now", (object)scheduledTask);
                     }
                 }
             }
         }
         if (scheduledTask != null)
         {
             // ISSUE: method pointer
             this.processingGroup.QueueWorkItem(new WorkItemCallback((object)this, __methodptr(ThreadPoolRoutine)), (object)scheduledTask);
             if (this.log.get_IsDebugEnabled())
             {
                 this.log.DebugFormat("Scheduler: Task {0} was executed", (object)scheduledTask);
             }
         }
         Thread.Sleep(this.mandatorySchedulerDelay);
     }
 }
Example #10
0
        // Token: 0x06000438 RID: 1080 RVA: 0x0001C914 File Offset: 0x0001AB14
        public void RequestUpdateAsync(TTaskKey taskKey, UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTaskCallback callback, TimeSpan waitForChangesDelay)
        {
            UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask scheduledTask = new UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask();

            scheduledTask.TaskKey          = taskKey;
            scheduledTask.PlannedExecution = DateTime.UtcNow.Add(waitForChangesDelay);
            object callbacks;

            if (callback == null)
            {
                callbacks = null;
            }
            else
            {
                (callbacks = new List <UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTaskCallback>()).Add(callback);
            }
            scheduledTask.Callbacks = callbacks;
            UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask scheduledTask2 = scheduledTask;
            if (this.log.IsDebugEnabled)
            {
                this.log.DebugFormat("RequestUpdate for Task {0} - Enter", taskKey);
            }
            object obj = this.syncLock;

            lock (obj)
            {
                UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask scheduledTask3 = null;
                if (this.scheduledTasks.TryFind(scheduledTask2, UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask.IdentityComparer.Instance, out scheduledTask3))
                {
                    if (scheduledTask2.PlannedExecution < scheduledTask3.PlannedExecution)
                    {
                        if (scheduledTask3.Callbacks != null)
                        {
                            if (scheduledTask2.Callbacks != null)
                            {
                                scheduledTask2.Callbacks.AddRange(scheduledTask3.Callbacks);
                            }
                            else
                            {
                                scheduledTask2.Callbacks = scheduledTask3.Callbacks;
                            }
                        }
                        this.scheduledTasks.Remove(scheduledTask3, UpdateTaskScheduler <TTaskKey, TCallbackArg> .ScheduledTask.IdentityComparer.Instance);
                        this.scheduledTasks.Enqueue(scheduledTask2);
                        if (this.log.IsInfoEnabled)
                        {
                            this.log.InfoFormat("Task {0} was rescheduled from {1} to {2}", scheduledTask2, scheduledTask3.PlannedExecution, scheduledTask2.PlannedExecution);
                        }
                        Monitor.PulseAll(this.syncLock);
                    }
                    else
                    {
                        if (scheduledTask2.Callbacks != null)
                        {
                            if (scheduledTask3.Callbacks != null)
                            {
                                scheduledTask3.Callbacks.AddRange(scheduledTask2.Callbacks);
                            }
                            else
                            {
                                scheduledTask3.Callbacks = scheduledTask2.Callbacks;
                            }
                        }
                        if (this.log.IsInfoEnabled)
                        {
                            this.log.InfoFormat("Task {0} has been scheduled already at {1}, requested time {2}", scheduledTask2, scheduledTask3.PlannedExecution, scheduledTask2.PlannedExecution);
                        }
                    }
                }
                else
                {
                    this.scheduledTasks.Enqueue(scheduledTask2);
                    if (this.log.IsInfoEnabled)
                    {
                        this.log.InfoFormat("Task {0} has been scheduled for {1}", scheduledTask2, scheduledTask2.PlannedExecution);
                    }
                    Monitor.PulseAll(this.syncLock);
                }
            }
            if (this.log.IsDebugEnabled)
            {
                this.log.DebugFormat("RequestUpdate for Task {0} - Leave", taskKey);
            }
        }