private List <InstancePersistenceEvent> StartWaiting(WaitForEventsAsyncResult result, IOThreadTimer timeoutTimer, TimeSpan timeout) { lock (this.ThisLock) { if (this.waitResult != null) { throw Fx.Exception.AsError(new InvalidOperationException(SRCore.WaitAlreadyInProgress)); } if (!this.IsValid) { throw Fx.Exception.AsError(new OperationCanceledException(SRCore.HandleFreed)); } if ((this.boundOwnerEvents != null) && (this.boundOwnerEvents.Count > 0)) { List <InstancePersistenceEvent> list = this.Store.SelectSignaledEvents(this.boundOwnerEvents, this.Owner); if (list != null) { return(list); } } this.waitResult = result; if (timeoutTimer != null) { timeoutTimer.Set(timeout); } return(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(); } }
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); } }
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 void Initialize(LinkedListNode <ReceiveAsyncResult> node) { this.node = node; if (this.timeout != TimeSpan.MaxValue) { timer = new IOThreadTimer(onTimer, this, false); timer.Set(timeout); } }
void SetFlushTimer() { if (flushTimer == null) { int flushSkew = Ticks.ToMilliseconds(Math.Min(flushTimeout / 10, Ticks.FromMilliseconds(maxFlushSkew))); flushTimer = new IOThreadTimer(new Action <object>(OnFlushTimer), null, true, flushSkew); } flushTimer.Set(Ticks.ToTimeSpan(flushTimeout)); }
internal void AfterReply(ref MessageRpc rpc) { if (rpc.Operation.IsTerminating && rpc.Channel.HasSession) { IOThreadTimer timer = new IOThreadTimer(new Action <object>(TerminatingOperationBehavior.AbortChannel), rpc.Channel.Binder.Channel, false); timer.Set(rpc.Channel.CloseTimeout); } }
public void Start() { MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWritePairedNamespaceStartSyphon(this.InstanceTrackingContext.Activity, this.SyphonId, this.options.PrimaryMessagingFactory.Address.ToString(), this.options.SecondaryMessagingFactory.Address.ToString(), this.options.BacklogQueueCount)); for (int i = 0; i < this.options.BacklogQueueCount; i++) { IOThreadTimer oThreadTimer = new IOThreadTimer(new Action <object>(this.BeginProcessQueue), (object)i, false); oThreadTimer.Set(this.options.SyphonRetryInterval); this.timers[i] = oThreadTimer; } }
private void StartTimerIfNeeded() { if (_purgingMode != PurgingMode.TimerBasedPurge) { return; } if (_purgingTimer == null) { _purgingTimer = new IOThreadTimer(PurgeCallback, this, false); _purgingTimer.Set(_purgeInterval); } }
public void BeginCheckPoint(PruneNeighborCallback pruneCallback) { if (this.isMonitoring) { return; } lock (throttleLock) { if (this.isMonitoring) { return; } this.checkPointPendingSends = this.pendingSends; this.pruneNeighbor = pruneCallback; this.expectedClearance = this.pendingSends / 2; this.isMonitoring = true; if (owner == null) { return; } pruneTimer.Set(pruneInterval); } }
private bool AddTimer(IPeerNeighbor neighbor) { bool flag = false; lock (this.ThisLock) { if ((this.state == State.Opened) && (neighbor.State == PeerNeighborState.Connecting)) { IOThreadTimer timer = new IOThreadTimer(new Action <object>(this.OnConnectTimeout), neighbor, true); timer.Set(this.config.ConnectTimeout); this.timerTable.Add(neighbor, timer); flag = true; } } return(flag); }
internal virtual void CleanupActivity(object state) { if (!opened) { return; } if (!isCleaning) { lock (ThisLock) { if (!isCleaning) { isCleaning = true; try { MeshEntry meshEntry = null; //acquire a write lock. from the reader/writer lock can we postpone until no contention? ICollection <string> keys = null; LiteLock ll = null; try { LiteLock.Acquire(out ll, gate); keys = meshId2Entry.Keys; } finally { LiteLock.Release(ll); } foreach (string meshId in keys) { meshEntry = GetMeshEntry(meshId); CleanupMeshEntry(meshEntry); } } finally { isCleaning = false; if (opened) { timer.Set(this.CleanupInterval); } } } } } }
// Add a timer for the specified neighbor to the timer table. The timer is only added // if Connector is open and the neighbor is in Connecting state. bool AddTimer(IPeerNeighbor neighbor) { bool added = false; lock (ThisLock) { if (state == State.Opened && neighbor.State == PeerNeighborState.Connecting) { IOThreadTimer timer = new IOThreadTimer(new Action <object>(OnConnectTimeout), neighbor, true); timer.Set(this.config.ConnectTimeout); this.timerTable.Add(neighbor, timer); added = true; } } return(added); }
void OnTimeout(object state) { if (disposed) { return; } lock (ThisLock) { if (disposed) { return; } active = (active + 1) % (buckets); tables[active] = NewCache(tables[active].Count); messagePruningTimer.Set(PruningTimout); } }
public virtual void Open() { ThrowIfOpened("Open"); if (this.refreshInterval <= TimeSpan.Zero) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("RefreshInterval", SR.GetString(SR.RefreshIntervalMustBeGreaterThanZero, this.refreshInterval)); } if (this.CleanupInterval <= TimeSpan.Zero) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("CleanupInterval", SR.GetString(SR.CleanupIntervalMustBeGreaterThanZero, this.cleanupInterval)); } //check that we are good to open timer = new IOThreadTimer(new Action <object>(CleanupActivity), null, false); timer.Set(CleanupInterval); opened = true; }
void FaultMessageQueueOnFailure() { lock (ThisLock) { this.queueState = QueueState.Faulted; // Drop pending messages. this.DropPendingMessages(true); // Throttling if (throttlingTimer == null) { throttlingTimer = new IOThreadTimer(new Action <object>(ThrottlingCallback), this, true, ThrottlingMaxSkewInMilliseconds); } throttlingTimer.Set(FailureThrottlingTimeout); } }
//creating this ListManager with n implies that the entries will be available for n minutes atmost. //in the n+1 minute, the timer message handler will kick in to clear older messages. //every minute, the public ListManager(uint buckets) { if (!(buckets > 1)) { throw Fx.AssertAndThrow("ListManager should be used atleast with 2 buckets"); } this.buckets = buckets; tables = new Dictionary <byte[], bool> [buckets]; for (uint i = 0; i < buckets; i++) { tables[i] = NewCache(InitialCount); } //create a timer and kickit off for 1 minute messagePruningTimer = new IOThreadTimer(new Action <object>(OnTimeout), null, false); messagePruningTimer.Set(PruningTimout); this.active = 0; this.disposed = false; this.thisLock = new object(); }
private void HandleUnplannedShutdown(MessagingFactory factory1, MessagingFactory factory2) { if (!this.Closed && (factory1.IsFaulted || factory1.IsClosedOrClosing) && (factory2.IsClosedOrClosing || factory2.IsFaulted)) { this.Close(); return; } if (factory1.IsFaulted && factory2.IsOpened) { Exception pairedMessagingFactoryException = new PairedMessagingFactoryException(SRClient.FaultingPairedMessagingFactory(factory2.Address.ToString(), factory1.Address.ToString())); factory2.Fault(pairedMessagingFactoryException); return; } if (factory1.IsClosedOrClosing && factory2.IsOpened) { IOThreadTimer oThreadTimer = new IOThreadTimer(new Action <object>(SendAvailabilityMessagePump.FaultingClose), new Tuple <MessagingFactory, MessagingFactory, SendAvailabilityMessagePump>(factory2, factory1, this), false); if (Interlocked.CompareExchange <IOThreadTimer>(ref this.closeTimer, oThreadTimer, null) == null) { oThreadTimer.Set(SendAvailabilityMessagePump.DefaultCloseTimeout); } } }
private void EndProcessQueue(IAsyncResult result) { TimeSpan zero = TimeSpan.Zero; try { try { AsyncResult <SendAvailabilityMessagePump.ProcessQueueAsyncResult> .End(result); } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWritePairedNamespaceMessagePumpProcessQueueFailed(exception)); } } finally { if (!this.CanPump()) { this.HandleUnplannedShutdown(); } else { int asyncState = (int)result.AsyncState; if ((int)this.timers.Length > asyncState && !this.Closed) { IOThreadTimer oThreadTimer = this.timers[asyncState]; oThreadTimer.Set((this.options.SyphonRetryInterval > zero ? this.options.SyphonRetryInterval : zero)); this.queuesInProcess[asyncState] = null; } } } }
private static void OnHeartBeatTimer(object state) { AmqpConnection amqpConnection = (AmqpConnection)state; if (amqpConnection.State != AmqpObjectState.Opened) { return; } bool flag = false; DateTime dateTime = amqpConnection.lastSendTime; DateTime utcNow = DateTime.UtcNow; DateTime dateTime1 = utcNow; if (utcNow.Subtract(dateTime) < TimeSpan.FromMilliseconds((double)amqpConnection.heartBeatInterval)) { flag = true; dateTime1 = dateTime; } try { if (!flag) { amqpConnection.SendBuffer(Frame.EncodeCommand(FrameType.Amqp, 0, null, 0)); } IOThreadTimer oThreadTimer = amqpConnection.heartBeatTimer; DateTime dateTime2 = dateTime1.AddMilliseconds((double)amqpConnection.heartBeatInterval); oThreadTimer.Set(dateTime2.Subtract(utcNow)); } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } MessagingClientEtwProvider.TraceClient <AmqpConnection, Exception>((AmqpConnection source, Exception ex) => MessagingClientEtwProvider.Provider.EventWriteAmqpLogError(source, "OnHeartBeatTimer", ex.Message), amqpConnection, exception); } }
bool EnqueueRetry() { bool result = false; int delay = this.GetRetryDelay(); if (this.timeoutHelper.RemainingTime().TotalMilliseconds > delay) { this.sqlCommand.Dispose(); IOThreadTimer iott = new IOThreadTimer(StartCommandCallback, new SqlCommandAsyncResult(CloneSqlCommand(this.sqlCommand), this.connectionString, this.eventTraceActivity, this.dependentTransaction, this.timeoutHelper.RemainingTime(), this.retryCount, this.maximumRetries, this.PrepareAsyncCompletion(onRetryCommandCallback), this), false); iott.Set(delay); if (TD.QueuingSqlRetryIsEnabled()) { TD.QueuingSqlRetry(this.eventTraceActivity, delay.ToString(CultureInfo.InvariantCulture)); } result = true; } return(result); }
void InitialConnection(object dummy) { // Are we open and is any maintenance activity occuring if (isOpen) { bool continueMaintenance = false; if (!isRunningMaintenance) { lock (ThisLock) { if (!isRunningMaintenance) { isRunningMaintenance = true; continueMaintenance = true; } } } if (continueMaintenance) { if (DiagnosticUtility.ShouldTraceInformation) { PeerMaintainerTraceRecord record = new PeerMaintainerTraceRecord(SR.GetString(SR.PeerMaintainerInitialConnect, this.config.MeshId)); TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.PeerMaintainerActivity, SR.GetString(SR.TraceCodePeerMaintainerActivity), record, this, null); } TimeoutHelper timeoutHelper = new TimeoutHelper(config.MaintainerTimeout); Exception exception = null; // The connection algorithm may be pluggable if we provide an api or metadata to enable it. // I am sure that research would be interested in doing such a thing. try { maintainerTimer.Cancel(); // No reconnect until after connect has succeeded using (IConnectAlgorithms connectAlgorithm = (IConnectAlgorithms) new TConnectAlgorithms()) { connectAlgorithm.Initialize(this, config, config.MinNeighbors, referralCache); if (referralCache.Count == 0) { ReadOnlyCollection <PeerNodeAddress> addresses = ResolveNewAddresses(timeoutHelper.RemainingTime(), false); connectAlgorithm.UpdateEndpointsCollection(addresses); } if (isOpen) { connectAlgorithm.Connect(timeoutHelper.RemainingTime()); } } } #pragma warning suppress 56500 // covered by FxCOP catch (Exception e) { if (Fx.IsFatal(e)) { throw; } DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); exception = e; // Exeption is saved and transferred } if (isOpen) { try { lock (ThisLock) { if (isOpen) { // No reconnect until after connect has succeeded if (neighborManager.ConnectedNeighborCount < 1) { maintainerTimer.Set(config.MaintainerRetryInterval); } else { maintainerTimer.Set(config.MaintainerInterval); } } } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); if (exception == null) { exception = e; // Exeption is saved and transferred via callback } } } lock (ThisLock) { isRunningMaintenance = false; } if (connectCallback != null) { connectCallback(exception); } } } }
// Register address for a node participating in a mesh identified by meshId with the resolver service public override object Register(string meshId, PeerNodeAddress nodeAddress, TimeSpan timeout) { if (opened) { long scopeId = -1; bool multipleScopes = false; if (nodeAddress.IPAddresses.Count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.MustRegisterMoreThanZeroAddresses))); } foreach (IPAddress address in nodeAddress.IPAddresses) { if (address.IsIPv6LinkLocal) { if (scopeId == -1) { scopeId = address.ScopeId; } else if (scopeId != address.ScopeId) { multipleScopes = true; break; } } } List <IPAddress> addresslist = new List <IPAddress>(); foreach (IPAddress address in nodeAddress.IPAddresses) { if (!multipleScopes || (!address.IsIPv6LinkLocal && !address.IsIPv6SiteLocal)) { addresslist.Add(address); } } if (addresslist.Count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(SR.GetString(SR.AmbiguousConnectivitySpec))); } ReadOnlyCollection <IPAddress> addresses = new ReadOnlyCollection <IPAddress>(addresslist); this.meshId = meshId; this.nodeAddress = new PeerNodeAddress(nodeAddress.EndpointAddress, addresses); RegisterInfo info = new RegisterInfo(clientId, meshId, this.nodeAddress); IPeerResolverClient proxy = GetProxy(); try { proxy.OperationTimeout = timeout; RegisterResponseInfo response = proxy.Register(info); this.registrationId = response.RegistrationId; timer.Set(response.RegistrationLifetime); this.defaultLifeTime = response.RegistrationLifetime; proxy.Close(); } finally { proxy.Abort(); } } return(registrationId); }
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; } }
public void Attach(IPeerNeighbor host) { this.owner = host; ackTimer.Set(PeerTransportConstants.AckTimeout); }