public AddressChangeHelper(AddedChangedCallback addressChanged) { Fx.Assert(addressChanged != null, "addressChanged expected to be non-null"); this.addressChanged = addressChanged; this.timer = new IOThreadTimer(new Action <object>(FireAddressChange), null, true); NetworkChange.NetworkAddressChanged += OnAddressChange; }
void OnReceiveOpen(Open open) { Action <Open> openCallback = this.Settings.OnOpenCallback; if (openCallback != null) { openCallback(open); } this.Negotiate(open); StateTransition stateTransition; this.TransitState("R:OPEN", StateTransition.ReceiveOpen, out stateTransition); if (stateTransition.To == AmqpObjectState.OpenReceived) { this.SendOpen(); } if (this.isInitiator && this.Settings.IdleTimeOut.Value != uint.MaxValue) { this.heartBeatInterval = (int)(this.Settings.IdleTimeOut.Value * 3 / 8); if (this.heartBeatInterval < 500) { this.heartBeatInterval = 500; } this.heartBeatTimer = new IOThreadTimer(OnHeartBeatTimer, this, false); this.heartBeatTimer.Set(this.heartBeatInterval); Utils.Trace(TraceLevel.Info, "{0}: enabled heart beat timer ({1}ms)", this, this.heartBeatInterval); } this.CompleteOpen(stateTransition.From == AmqpObjectState.Start, null); }
internal void StartCheckForAvailability(string path) { bool flag = false; if (this.availableEntities.ContainsKey(path)) { if (this.availableEntities.TryUpdate(path, false, true)) { flag = true; } } else if (this.availableEntities.TryAdd(path, false)) { flag = true; } if (flag && this.availabilityTimers.TryAdd(path, null)) { IOThreadTimer oThreadTimer = new IOThreadTimer(new Action <object>(this.AvailabilityCallback), path, false); if (this.availabilityTimers.TryUpdate(path, oThreadTimer, null) && !this.Closed) { oThreadTimer.Set(this.PingPrimaryInterval); return; } oThreadTimer.Cancel(); } }
public TransmissionStrategy(ReliableMessagingVersion reliableMessagingVersion, TimeSpan initRtt, int maxWindowSize, bool requestAcks, UniqueId id) { if (initRtt < TimeSpan.Zero) { if (DiagnosticUtility.ShouldTrace(TraceEventType.Warning)) { TraceUtility.TraceEvent(TraceEventType.Warning, TraceCode.WsrmNegativeElapsedTimeDetected, SR.TraceCodeWsrmNegativeElapsedTimeDetected, this); } initRtt = ReliableMessagingConstants.UnknownInitiationTime; } if (maxWindowSize <= 0) { throw Fx.AssertAndThrow("Argument maxWindow size must be positive."); } _id = id; _maxWindowSize = _lossWindowSize = maxWindowSize; _meanRtt = Math.Min((long)initRtt.TotalMilliseconds, Constants.MaxMeanRtt >> Constants.TimeMultiplier) << Constants.TimeMultiplier; _serrRtt = _meanRtt >> 1; _window = new SlidingWindow(maxWindowSize); _slowStartThreshold = maxWindowSize; _timeout = Math.Max(((200 << Constants.TimeMultiplier) * 2) + _meanRtt, _meanRtt + (_serrRtt << Constants.ChebychevFactor)); QuotaRemaining = int.MaxValue; _retryTimer = new IOThreadTimer(new Func <object, Task>(OnRetryElapsed), null, true); _requestAcks = requestAcks; _reliableMessagingVersion = reliableMessagingVersion; }
private UtilityExtension() { this.ackTimer = new IOThreadTimer(new Action <object>(this.AcknowledgeLoop), null, false); this.pendingSends = 0; this.pruneTimer = new IOThreadTimer(new Action <object>(this.VerifyCheckPoint), null, false); this.pruneInterval = TimeSpan.FromMilliseconds((double)(0x2710 + new Random(Process.GetCurrentProcess().Id).Next(0x2710))); }
internal WaitForEventsAsyncResult(InstanceHandle handle, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { this.handle = handle; this.timeout = timeout; if (this.timeout != TimeSpan.Zero && this.timeout != TimeSpan.MaxValue) { this.timer = new IOThreadTimer(WaitForEventsAsyncResult.timeoutCallback, this, false); } List <InstancePersistenceEvent> existingReadyEvents = this.handle.StartWaiting(this, this.timer, this.timeout); if (existingReadyEvents == null) { if (this.timeout == TimeSpan.Zero) { this.handle.CancelWaiting(this); throw Fx.Exception.AsError(new TimeoutException(SRCore.WaitForEventsTimedOut(TimeSpan.Zero))); } } else { this.readyEvents = existingReadyEvents; Complete(true); } }
public MsmqSubqueueLockingQueue(string formatName, string hostname, int accessMode) : base(formatName, accessMode) { this.lockCollectionInterval = TimeSpan.FromMinutes(5.0); this.timerLock = new object(); if (string.Compare(hostname, string.Empty, StringComparison.OrdinalIgnoreCase) == 0) { this.validHostName = TryGetHostName(formatName, out hostname); } else { this.validHostName = true; } this.disposed = false; this.lockQueueName = base.formatName + ";" + GenerateLockQueueName(); this.lockQueueForReceive = new MsmqQueue(this.lockQueueName, 1, 1); this.lockQueueForMove = new MsmqQueue(this.lockQueueName, 4); this.mainQueueForMove = new MsmqQueue(base.formatName, 4); this.lockCollectionTimer = new IOThreadTimer(new Action <object>(this.OnCollectionTimer), null, false); if (string.Compare(hostname, "localhost", StringComparison.OrdinalIgnoreCase) == 0) { this.hostname = null; } else { this.hostname = hostname; } }
UtilityExtension() { ackTimer = new IOThreadTimer(new Action <object>(AcknowledgeLoop), null, false); pendingSends = 0; pruneTimer = new IOThreadTimer(new Action <object>(VerifyCheckPoint), null, false); pruneInterval = TimeSpan.FromMilliseconds(PruneIntervalMilliseconds + new Random(Process.GetCurrentProcess().Id).Next(PruneIntervalMilliseconds)); }
public MsmqSubqueueLockingQueue(string formatName, string hostname, int accessMode) : base(formatName, accessMode) { // The hostname will be empty for MsmqIntegrationBinding if (string.Compare(hostname, string.Empty, StringComparison.OrdinalIgnoreCase) == 0) { this.validHostName = MsmqSubqueueLockingQueue.TryGetHostName(formatName, out hostname); } else { this.validHostName = true; } this.disposed = false; this.lockQueueName = this.formatName + ";" + MsmqSubqueueLockingQueue.GenerateLockQueueName(); this.lockQueueForReceive = new MsmqQueue(this.lockQueueName, UnsafeNativeMethods.MQ_RECEIVE_ACCESS, UnsafeNativeMethods.MQ_DENY_RECEIVE_SHARE); this.lockQueueForMove = new MsmqQueue(this.lockQueueName, UnsafeNativeMethods.MQ_MOVE_ACCESS); this.mainQueueForMove = new MsmqQueue(this.formatName, UnsafeNativeMethods.MQ_MOVE_ACCESS); this.lockCollectionTimer = new IOThreadTimer(new Action <object>(OnCollectionTimer), null, false); if (string.Compare(hostname, "localhost", StringComparison.OrdinalIgnoreCase) == 0) { this.hostname = null; } else { this.hostname = hostname; } }
void StartSchedule() { this.currentSendIndex = -1; this.timer = new IOThreadTimer(this.onTimerCallback, this, false); this.startTicks = Ticks.Now; Schedule(0); }
public virtual void ResetTimer(bool fireImmediately, TimeSpan?taskIntervalOverride) { TimeSpan timeTillNextPoll = this.taskInterval; if (taskIntervalOverride.HasValue) { if (taskIntervalOverride.Value < this.taskInterval) { timeTillNextPoll = taskIntervalOverride.Value; } } lock (ThisLock) { if (!this.timerCancelled) { if (this.taskTimer == null) { this.taskTimer = new IOThreadTimer(new Action <object>(this.OnTimerFired), null, false); } this.taskTimer.Set(fireImmediately ? TimeSpan.Zero : timeTillNextPoll); } } }
bool RemoveTimer(IPeerNeighbor neighbor) { IOThreadTimer timer = null; bool removed = false; // Remove the timer from the table and cancel it. Do this if Connector is // still open. Otherwise, Close method will have already cancelled the timers. lock (ThisLock) { if (this.state == State.Opened && this.timerTable.TryGetValue(neighbor, out timer)) { removed = this.timerTable.Remove(neighbor); } } if (timer != null) { timer.Cancel(); if (!removed) { throw Fx.AssertAndThrow("Neighbor key should have beeen removed from the table"); } } return(removed); }
private void Done(bool completedSynchronously) { ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? TraceUtility.ExtractActivity(this.reply) : null; using (ServiceModelActivity.BoundOperation(activity)) { if (this.timer != null) { this.timer.Cancel(); this.timer = null; } lock (this.parent.ThisLock) { this.parent.RequestCompleting(this); } if (this.sendException != null) { base.Complete(completedSynchronously, this.sendException); } else if (this.timedOut) { base.Complete(completedSynchronously, this.parent.GetReceiveTimeoutException(this.timeout)); } else { base.Complete(completedSynchronously); } } }
private void OnReceiveOpen(Open open) { StateTransition stateTransition = base.TransitState("R:OPEN", StateTransition.ReceiveOpen); this.Negotiate(open); base.NotifyOpening(open); uint num = open.IdleTimeOut(); if (num < 60000) { base.CompleteOpen(false, new AmqpException(AmqpError.NotAllowed, SRAmqp.AmqpIdleTimeoutNotSupported(num, (uint)60000))); return; } if (stateTransition.To == AmqpObjectState.OpenReceived) { this.SendOpen(); } if (this.isInitiator) { Error error = null; if (open.Properties != null && open.Properties.TryGetValue <Error>("com.microsoft:open-error", out error)) { base.CompleteOpen(stateTransition.From == AmqpObjectState.Start, new AmqpException(error)); return; } } if (num != -1) { this.heartBeatInterval = (int)(num * 7 / 8); this.heartBeatTimer = new IOThreadTimer(new Action <object>(AmqpConnection.OnHeartBeatTimer), this, false); this.heartBeatTimer.Set(this.heartBeatInterval); } base.CompleteOpen(stateTransition.From == AmqpObjectState.Start, null); }
protected override void OnNotifyPrimarySendResult(string path, bool success) { IOThreadTimer oThreadTimer; if (success) { if (this.primaryFailureTimers.TryRemove(path, out oThreadTimer)) { oThreadTimer.Cancel(); return; } } else if (!this.primaryFailureTimers.ContainsKey(path)) { Tuple <SendAvailabilityPairedNamespaceOptions, string> tuple = new Tuple <SendAvailabilityPairedNamespaceOptions, string>(this, path); if (base.FailoverInterval == TimeSpan.Zero) { SendAvailabilityPairedNamespaceOptions.OnPrimaryFailedIntervalExpired(tuple); return; } IOThreadTimer oThreadTimer1 = new IOThreadTimer(new Action <object>(SendAvailabilityPairedNamespaceOptions.OnPrimaryFailedIntervalExpired), tuple, false); if (this.primaryFailureTimers.TryAdd(path, oThreadTimer1)) { oThreadTimer1.Set(base.FailoverInterval); } } }
public IotHubConnection(IotHubConnectionString connectionString, AccessRights accessRights) { this.connectionString = connectionString; this.accessRights = accessRights; this.faultTolerantSession = new FaultTolerantAmqpObject <AmqpSession>(this.CreateSessionAsync, this.CloseConnection); this.refreshTokenTimer = new IOThreadTimer(s => ((IotHubConnection)s).OnRefreshToken(), this, false); }
void CancelTimerIfNeeded() { if (this.Count == 0 && this.purgingTimer != null) { this.purgingTimer.Cancel(); this.purgingTimer = null; } }
private void StartTimerIfNeeded() { if ((this.purgingMode == PurgingMode.TimerBasedPurge) && (this.purgingTimer == null)) { this.purgingTimer = new IOThreadTimer(PurgeCallback, this, false); this.purgingTimer.Set(this.purgeInterval); } }
public DuplexSessionChannel(ChannelManagerBase channelManager, IDuplexSessionChannel innerChannel, System.ServiceModel.Channels.MessageVersion messageVersion, bool enableKeepAlive) : base(channelManager, innerChannel) { this.innerChannel = innerChannel; this.messageVersion = messageVersion; this.enableKeepAlive = enableKeepAlive; this.pingTimer = new IOThreadTimer(SocketConnectionChannelFactory <TChannel> .DuplexSessionChannel.pingCallbackStatic, this, false); this.suppressPing = false; }
private void CancelSendTimer() { if (this.sendTimer != null) { this.sendTimer.Cancel(); this.sendTimer = null; } }
private void CancelReceiveTimer() { if (this.receiveTimer != null) { this.receiveTimer.Cancel(); this.receiveTimer = null; } }
internal AsyncWaiter(TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { if (timeout != TimeSpan.MaxValue) { this.timer = new IOThreadTimer(SingletonManager <TSingleton> .AsyncWaiter.timerCallback, this, true); this.timer.Set(timeout); } }
private void CancelTimerIfNeeded() { if ((this.Count == 0) && (this.purgingTimer != null)) { this.purgingTimer.Cancel(); this.purgingTimer = null; } }
public void Attach(IPeerNeighbor host) { Fx.AssertAndThrow(this.securityManager.AuthenticationMode == PeerAuthenticationMode.Password, "Invalid AuthenticationMode!"); Fx.AssertAndThrow(host != null, "unrecognized host!"); this.host = host; this.timer = new IOThreadTimer(new Action <object>(this.OnTimeout), null, true); this.timer.Set(Timeout); }
void StopTimer() { if (this.timer != null) { this.timer.Cancel(); this.timer = null; } }
public TokenRenewer(TokenProvider tokenProvider, string appliesTo, string action) { this.tokenProvider = tokenProvider; this.appliesTo = appliesTo; this.action = action; this.renewTimer = new IOThreadTimer(AmqpRelay.TokenRenewer.onRenewToken, this, false); this.syncRoot = new object(); }
internal PeerDefaultCustomResolverClient() { this.address = null; this.binding = null; this.defaultLifeTime = TimeSpan.FromHours(1); clientId = Guid.NewGuid(); timer = new IOThreadTimer(new Action <object>(RegistrationExpired), this, false); }
void CancelRetryTimer() { if (this.timer != null) { this.timer.Cancel(); this.timer = null; } }
private void CancelTimerIfNeeded() { if (Count == 0 && _purgingTimer != null) { _purgingTimer.Cancel(); _purgingTimer = null; } }
internal TransactionWaitAsyncResult(Transaction transaction, PersistenceContext persistenceContext, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { bool completeSelf = false; TransactionException exception = null; this.PersistenceContext = persistenceContext; this.thisLock = new object(); if (null != transaction) { // We want an "blocking" dependent transaction because we want to ensure the transaction // does not commit successfully while we are still waiting in the queue for the PC transaction // lock. this.dependentTransaction = transaction.DependentClone(DependentCloneOption.BlockCommitUntilComplete); } else { this.dependentTransaction = null; } // Put a lock around this and Complete() in case the transaction we are queueing up behind // finishes and we end up calling Complete() before we actually finish constructing this // object by creating the DependentClone and setting up the IOThreadTimer. lock (ThisLock) { if (persistenceContext.QueueForTransactionLock(transaction, this)) { // If we were given a transaction in our constructor, we need to // create a volatile enlistment on it and complete the // dependent clone that we created. This will allow the transaction to commit // successfully when the time comes. if (null != transaction) { // We are not going async, so we need to complete our dependent clone now. this.dependentTransaction.Complete(); exception = this.CreateVolatileEnlistment(transaction); } completeSelf = true; } else { // If the timeout value is not TimeSpan.MaxValue, start a timer. if (timeout != TimeSpan.MaxValue) { this.timer = new IOThreadTimer(TimeoutCallbackAction, this, true); this.timer.Set(timeout); } } } // We didn't want to call Complete while holding the lock. if (completeSelf) { base.Complete(true, exception); } }
internal WaitForEventsAsyncResult(InstanceHandle handle, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { this.handle = handle; this.timeout = timeout; if (this.timeout != TimeSpan.Zero && this.timeout != TimeSpan.MaxValue) { this.timer = new IOThreadTimer(WaitForEventsAsyncResult.timeoutCallback, this, false); } List<InstancePersistenceEvent> existingReadyEvents = this.handle.StartWaiting(this, this.timer, this.timeout); if (existingReadyEvents == null) { if (this.timeout == TimeSpan.Zero) { this.handle.CancelWaiting(this); throw Fx.Exception.AsError(new TimeoutException(SRCore.WaitForEventsTimedOut(TimeSpan.Zero))); } } else { this.readyEvents = existingReadyEvents; Complete(true); } }
List<InstancePersistenceEvent> StartWaiting(WaitForEventsAsyncResult result, IOThreadTimer timeoutTimer, TimeSpan timeout) { lock (ThisLock) { if (this.waitResult != null) { throw Fx.Exception.AsError(new InvalidOperationException(SRCore.WaitAlreadyInProgress)); } if (!IsValid) { throw Fx.Exception.AsError(new OperationCanceledException(SRCore.HandleFreed)); } if (this.boundOwnerEvents != null && this.boundOwnerEvents.Count > 0) { Fx.Assert(Owner != null, "How do we have owner events without an owner."); List<InstancePersistenceEvent> readyEvents = Store.SelectSignaledEvents(this.boundOwnerEvents, Owner); if (readyEvents != null) { Fx.Assert(readyEvents.Count != 0, "Should not return a zero-length list."); return readyEvents; } } this.waitResult = result; // This is done here to be under the lock. That way it doesn't get canceled before it is set. if (timeoutTimer != null) { timeoutTimer.Set(timeout); } return null; } }