Token(long scheduledTime, int id, long delay, ITimerTask task) { ScheduledTime = scheduledTime; Id = id; Delay = delay; Task = task; }
public HashedWheelTimeout(HashedWheelTimer timer, ITimerTask timerTask, long deadline) { _timer = timer; TimerTask = timerTask; Deadline = deadline; Interlocked.Exchange(ref _state, HashedWheelTimeoutState.Init); }
public void ScheduleRepeated(ITimerTask task, long period) { lock (this) { if (_communicator == null) { throw new Ice.CommunicatorDestroyedException(); } var token = new Token(Time.CurrentMonotonicTimeMillis() + period, ++_tokenId, period, task); try { _tasks.Add(task, token); _tokens.Add(token, null); } catch (System.ArgumentException) { Debug.Assert(false); } if (token.ScheduledTime < _wakeUpTime) { Monitor.Pulse(this); } } }
public void Schedule(ITimerTask task, long delay) { lock (_mutex) { if (_communicator == null) { throw new CommunicatorDestroyedException(); } var token = new Token(Time.CurrentMonotonicTimeMillis() + delay, ++_tokenId, 0, task); try { _tasks.Add(task, token); _tokens.Add(token, null); } catch (System.ArgumentException) { Debug.Assert(false); } if (token.ScheduledTime < _wakeUpTime) { Monitor.Pulse(_mutex); } } }
/// <summary> /// 使用实现定时接口ITimerTask的实例创建定时任务 /// </summary> /// <param name="info"></param> /// <param name="_ins"></param> /// <returns></returns> public static Thread CreateTimerTaskService(TimerInfo info, ITimerTask _ins) { TimerTaskService tus = new TimerTaskService(info, _ins); //创建启动线程 Thread ThreadTimerTaskService = new Thread(new ThreadStart(tus.Start)); return(ThreadTimerTaskService); }
public void Dispose() { (this._task as IDisposable)?.Dispose(); this.Prev?.Dispose(); this.Next?.Dispose(); this._task = null; this._timer = null; this.Bucket = null; this.Prev = null; this.Next = null; }
public ITimeout NewTimeout(ITimerTask task, TimeSpan delay) { Guard.ArgumentNotNull(task, nameof(task)); this.Start(); var now = DateTime.UtcNow.Ticks; // 添加任务到下一个时间刻度。 // 任务被处理后会被装进 HashedWheelBucket 桶。 long deadline = now + (long)(delay.TotalMilliseconds * 10000L) - startTime; HashedWheelTimeout timeout = new HashedWheelTimeout(this, task, deadline); _timeouts.Enqueue(timeout); return(timeout); }
public static void RegisterNewAction(ITimerTask task) { if (timer == null) { timer = new DispatcherTimer(); timer.Tick += (s, e) => Tick(); } if (tasks == null) { tasks = new List <ITimerTask>(); } tasks.Add(task); ReconfigurateTimer(); }
public bool Cancel(ITimerTask task) { lock (this) { if (_communicator == null) { return(false); } if (!_tasks.TryGetValue(task, out Token? token)) { return(false); } _tasks.Remove(task); _tokens.Remove(token); return(true); } }
/// <summary> /// Schedules the specified TimerTask for one-time execution after the specified delay. /// </summary> /// <param name="task"></param> /// <param name="span"></param> /// <returns>a handle which is associated with the specified task</returns> public ITimeout NewTimeout(ITimerTask task, TimeSpan span) { if (task == null) { throw new ArgumentNullException(nameof(task)); } if (_cancellationTokenSource != default && _cancellationTokenSource.Token.IsCancellationRequested) { throw new InvalidOperationException("cannot be started once stopped"); } var pendingTimeoutsCount = _pendingTimeouts.IncrementAndGet(); if (_maxPendingTimeouts > 0 && pendingTimeoutsCount > _maxPendingTimeouts) { _pendingTimeouts.DecrementAndGet(); throw new InvalidOperationException( $"Number of pending timeouts ({pendingTimeoutsCount}) is greater than or equal to maximum allowed pending timeouts ({_maxPendingTimeouts})"); } Start(); // Add the timeout to the timeout queue which will be processed on the next tick. // During processing all the queued HashedWheelTimeouts will be added to the correct HashedWheelBucket. var deadline = DateTimeHelper.TotalMilliseconds + (long)span.TotalMilliseconds - StartTime; // Guard against overflow. if (span.Milliseconds > 0 && deadline < 0) { deadline = long.MaxValue; } var timeout = new HashedWheelTimeout(this, task, deadline); _timeouts.Enqueue(timeout); return(timeout); }
public VideoInformationHandler(IVideoPlayerHandler videoPlayerHandler, Form1 mainForm) { _timerTask = new VideoInformationTimerTask(videoPlayerHandler, mainForm); _timerHandler = new TimerHandler(_timerTask); }
public TimerHandler(ITimerTask timerTask) { _timerTask = timerTask; }
private System.Timers.Timer time; //定时器 /// <summary> /// 根据定时信息和执行具体任务的实例构造定时任务服务 /// </summary> /// <param name="_timer">定时信息</param> /// <param name="_interface">执行具体任务的实例</param> private TimerTaskService(TimerInfo _timer, ITimerTask _interface) { timerInfo = _timer; TimerTaskInstance = _interface; }
public IoThreadBoundTimerTask(INiftyClientChannel channel, ITimerTask timerTask) { this.channel = channel; this.timerTask = timerTask; }
public static void scheduleHashedWheel(ITimerTask timerTask, TimeSpan timeSpan) { HashedWheelTimer.NewTimeout(timerTask, timeSpan); }
public static void AnExceptionWasThrownBy(this IInternalLogger logger, ITimerTask task, Exception t) { logger.Warn($"An exception was thrown by {task.GetType().Name}.", t); }
public HashedWheelTimeout(HashedWheelTimer timer, ITimerTask task, long deadline) { this._timer = timer; this._task = task; this.Deadline = deadline; }
public VideoFragmentHandler(IVideoPlayerHandler videoPlayerHandler) { _videoPlayerHandler = videoPlayerHandler; _timerTask = new VideoTimerTask(_videoPlayerHandler); _timerHandler = new TimerHandler(_timerTask); }
public TimerTaskTests() { _cut = new TimerTask(); }