private void Initialize(ChannelHandlerContext ctx) { switch (_state) { case 1: return; case 2: return; } _state = 1; // .NET-specific: if (_executor == null) { _executor = new ExecutorService(); } var currentMillis = Convenient.CurrentTimeMillis(); _lastReadTime.Set(currentMillis); _lastWriteTime.Set(currentMillis); if (AllIdleTimeMillis > 0) { _cts = _executor.Schedule(AllIdleTimeoutTask, ctx, AllIdleTimeMillis); } }
/// <summary> /// Creates a new future object and creates a timer that fires failed after a timeout. /// </summary> /// <param name="serverPeerAddress"></param> /// <param name="timer">.NET-specific: CTS instead of timer.</param> /// <param name="delaySec">The delay in seconds.</param> public void Timeout(PeerAddress serverPeerAddress, ExecutorService timer, int delaySec) { _start = Convenient.CurrentTimeMillis(); var cts = timer.Schedule(DiscoverTimeoutTask, serverPeerAddress, TimeSpan.FromSeconds(delaySec).TotalMilliseconds); // ReSharper disable once MethodSupportsCancellation // cancel timeout if we are done Task.ContinueWith(tDelay => cts.Cancel()); }
/// <summary> /// Creates a new future object and creates a timer that fires failed after a timeout. /// </summary> /// <param name="serverPeerAddress"></param> /// <param name="timer">.NET-specific: CTS instead of timer.</param> /// <param name="delaySec">The delay in seconds.</param> public void Timeout(PeerAddress serverPeerAddress, ExecutorService timer, int delaySec) { _start = Convenient.CurrentTimeMillis(); var cts = timer.Schedule(DiscoverTimeoutTask, serverPeerAddress, TimeSpan.FromSeconds(delaySec).TotalMilliseconds); // ReSharper disable once MethodSupportsCancellation // cancel timeout if we are done Task.ContinueWith(tDelay => cts.Cancel()); }