Exemplo n.º 1
0
            public void Set(IOThreadTimer timer, long dueTime)
            {
                long num = dueTime - timer.dueTime;

                if (num < 0L)
                {
                    num = -num;
                }
                if (num > timer.maxSkew)
                {
                    lock (this.ThisLock)
                    {
                        IOThreadTimer.TimerGroup timerGroup = timer.timerGroup;
                        IOThreadTimer.TimerQueue timerQueue = timerGroup.TimerQueue;
                        if (timer.index > 0)
                        {
                            if (timerQueue.UpdateTimer(timer, dueTime))
                            {
                                this.UpdateWaitableTimer(timerGroup);
                            }
                        }
                        else if (timerQueue.InsertTimer(timer, dueTime))
                        {
                            this.UpdateWaitableTimer(timerGroup);
                            if (timerQueue.Count == 1)
                            {
                                this.EnsureWaitScheduled();
                            }
                        }
                    }
                }
            }
Exemplo n.º 2
0
 public bool Cancel(IOThreadTimer timer)
 {
     lock (this.ThisLock)
     {
         if (timer.index > 0)
         {
             IOThreadTimer.TimerGroup timerGroup = timer.timerGroup;
             IOThreadTimer.TimerQueue timerQueue = timerGroup.TimerQueue;
             timerQueue.DeleteTimer(timer);
             if (timerQueue.Count > 0)
             {
                 this.UpdateWaitableTimer(timerGroup);
             }
             else
             {
                 IOThreadTimer.TimerGroup otherTimerGroup = this.GetOtherTimerGroup(timerGroup);
                 if (otherTimerGroup.TimerQueue.Count == 0)
                 {
                     long now  = Ticks.Now;
                     long num2 = timerGroup.WaitableTimer.DueTime - now;
                     long num3 = otherTimerGroup.WaitableTimer.DueTime - now;
                     if ((num2 > 0x989680L) && (num3 > 0x989680L))
                     {
                         timerGroup.WaitableTimer.Set(Ticks.Add(now, 0x989680L));
                     }
                 }
             }
             return(true);
         }
         return(false);
     }
 }
        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;
            }
        }
Exemplo n.º 4
0
            public bool UpdateTimer(IOThreadTimer timer, long dueTime)
            {
                int num = timer.index;

                IOThreadTimer[] oThreadTimerArray = this.timers;
                int             num1 = this.count;
                int             num2 = num / 2;

                if (num2 == 0 || oThreadTimerArray[num2].dueTime <= dueTime)
                {
                    int num3 = num * 2;
                    if (num3 > num1 || oThreadTimerArray[num3].dueTime >= dueTime)
                    {
                        int num4 = num3 + 1;
                        if (num4 > num1 || oThreadTimerArray[num4].dueTime >= dueTime)
                        {
                            timer.dueTime = dueTime;
                            return(num == 1);
                        }
                    }
                }
                this.DeleteTimer(timer);
                this.InsertTimer(timer, dueTime);
                return(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;
     }
 }
Exemplo n.º 6
0
            private void DeleteMinTimerCore()
            {
                int num3;
                int count = this.count;

                if (count == 1)
                {
                    this.count     = 0;
                    this.timers[1] = null;
                    return;
                }
                IOThreadTimer[] timers = this.timers;
                IOThreadTimer   timer  = timers[count];

                this.count = --count;
                int index = 1;

Label_0034:
                num3 = index * 2;
                if (num3 <= count)
                {
                    int           num4;
                    IOThreadTimer timer2;
                    if (num3 < count)
                    {
                        IOThreadTimer timer3 = timers[num3];
                        int           num5   = num3 + 1;
                        IOThreadTimer timer4 = timers[num5];
                        if (timer4.dueTime < timer3.dueTime)
                        {
                            timer2 = timer4;
                            num4   = num5;
                        }
                        else
                        {
                            timer2 = timer3;
                            num4   = num3;
                        }
                    }
                    else
                    {
                        num4   = num3;
                        timer2 = timers[num4];
                    }
                    if (timer.dueTime > timer2.dueTime)
                    {
                        timers[index] = timer2;
                        timer2.index  = index;
                        index         = num4;
                        if (num3 < count)
                        {
                            goto Label_0034;
                        }
                    }
                }
                timers[index]     = timer;
                timer.index       = index;
                timers[count + 1] = null;
            }
 public AsyncQueueWaiter(TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     if (timeout != TimeSpan.MaxValue)
     {
         this.timer = new IOThreadTimer(timerCallback, this, false);
         this.timer.Set(timeout);
     }
 }
Exemplo n.º 8
0
            public void DeleteMinTimer()
            {
                IOThreadTimer minTimer = this.MinTimer;

                this.DeleteMinTimerCore();
                minTimer.index   = 0;
                minTimer.dueTime = 0L;
            }
 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);
 }
 public Msmq4PoisonHandler(MsmqReceiveHelper receiver)
 {
     this.receiver = receiver;
     this.timer = new IOThreadTimer(new Action<object>(OnTimer), null, false);
     this.disposed = false;
     this.mainQueueName = this.ReceiveParameters.AddressTranslator.UriToFormatName(this.ListenUri);
     this.poisonQueueName = this.ReceiveParameters.AddressTranslator.UriToFormatName(new Uri(this.ListenUri.AbsoluteUri + ";poison"));
     this.retryQueueName = this.ReceiveParameters.AddressTranslator.UriToFormatName(new Uri(this.ListenUri.AbsoluteUri + ";retry"));
 }
        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 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 MsmqReceiveContextLockManager(MsmqReceiveContextSettings receiveContextSettings, MsmqQueue queue)
 {
     this.queue = queue;
     this.receiveContextSettings = receiveContextSettings;
     this.messageExpiryMap = new Dictionary<long, MsmqReceiveContext>();
     this.transMessages = new Dictionary<Guid, List<MsmqReceiveContext>>();
     this.transactionCompletedHandler = new TransactionCompletedEventHandler(this.OnTransactionCompleted);
     this.messageExpiryTimer = new IOThreadTimer(new Action<object>(this.CleanupExpiredLocks), null, false);
     this.messageExpiryTimer.Set(this.messageTimeoutInterval);
 }
 public void CancelTimer()
 {
     lock (this.ThisLock)
     {
         this.timerCancelled = true;
         if (this.taskTimer != null)
         {
             this.taskTimer.Cancel();
             this.taskTimer = null;
         }
     }
 }
 public CloseCommunicationAsyncResult(TimeSpan timeout, AsyncCallback callback, object state, object mutex) : base(callback, state)
 {
     this.timeout = timeout;
     this.timeoutHelper = new TimeoutHelper(timeout);
     this.mutex = mutex;
     if (timeout < TimeSpan.Zero)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TimeoutException(System.ServiceModel.SR.GetString("SFxCloseTimedOut1", new object[] { timeout })));
     }
     this.timer = new IOThreadTimer(new Action<object>(CloseCommunicationAsyncResult.TimeoutCallback), this, true);
     this.timer.Set(timeout);
 }
Exemplo n.º 16
0
 public AsyncQueueReader(InputQueue <T> inputQueue, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     if (inputQueue.AsyncCallbackGenerator != null)
     {
         base.VirtualCallback = inputQueue.AsyncCallbackGenerator();
     }
     this.inputQueue = inputQueue;
     if (timeout != TimeSpan.MaxValue)
     {
         this.timer = new IOThreadTimer(InputQueue <T> .AsyncQueueReader.timerCallback, this, false);
         this.timer.Set(timeout);
     }
 }
        public MsmqReceiveContextLockManager(MsmqReceiveContextSettings receiveContextSettings, MsmqQueue queue)
        {
            Fx.Assert(queue is ILockingQueue, "Queue must be ILockingQueue");

            this.disposed = false;
            this.queue = queue;
            this.receiveContextSettings = receiveContextSettings;
            this.messageExpiryMap = new Dictionary<long, MsmqReceiveContext>();
            this.transMessages = new Dictionary<Guid, List<MsmqReceiveContext>>();
            transactionCompletedHandler = new TransactionCompletedEventHandler(OnTransactionCompleted);

            this.messageExpiryTimer = new IOThreadTimer(new Action<object>(CleanupExpiredLocks), null, false);
            this.messageExpiryTimer.Set(messageTimeoutInterval);
        }
 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;
 }
 private void InternalSet(TimeSpan interval, bool ifNotSet)
 {
     lock (this.ThisLock)
     {
         if (!this.aborted && (!ifNotSet || !this.set))
         {
             if (this.timer == null)
             {
                 this.timer = new IOThreadTimer(onTimerElapsed, this, true);
             }
             this.timer.Set(interval);
             this.set = true;
         }
     }
 }
Exemplo n.º 20
0
            private void UpdateWaitableTimer(IOThreadTimer.TimerGroup timerGroup)
            {
                IOThreadTimer.WaitableTimer waitableTimer = timerGroup.WaitableTimer;
                IOThreadTimer minTimer = timerGroup.TimerQueue.MinTimer;
                long          dueTime  = waitableTimer.DueTime - minTimer.dueTime;

                if (dueTime < (long)0)
                {
                    dueTime = -dueTime;
                }
                if (dueTime > minTimer.maxSkew)
                {
                    waitableTimer.Set(minTimer.dueTime);
                }
            }
Exemplo n.º 21
0
            private void UpdateWaitableTimer(IOThreadTimer.TimerGroup timerGroup)
            {
                IOThreadTimer.WaitableTimer waitableTimer = timerGroup.WaitableTimer;
                IOThreadTimer minTimer = timerGroup.TimerQueue.MinTimer;
                long          num      = waitableTimer.DueTime - minTimer.dueTime;

                if (num < 0L)
                {
                    num = -num;
                }
                if (num > minTimer.maxSkew)
                {
                    waitableTimer.Set(minTimer.dueTime);
                }
            }
Exemplo n.º 22
0
 private void ScheduleElapsedTimers(IOThreadTimer.TimerGroup timerGroup, long now)
 {
     IOThreadTimer.TimerQueue timerQueue = timerGroup.TimerQueue;
     while (timerQueue.Count > 0)
     {
         IOThreadTimer minTimer = timerQueue.MinTimer;
         long          num      = minTimer.dueTime - now;
         if (num > minTimer.maxSkew)
         {
             break;
         }
         timerQueue.DeleteMinTimer();
         ActionItem.Schedule(minTimer.callback, minTimer.callbackState);
     }
 }
 public override void CloseQueue()
 {
     lock (this.timerLock)
     {
         if (!this.disposed)
         {
             this.disposed = true;
             this.lockCollectionTimer.Cancel();
             this.lockCollectionTimer = null;
         }
     }
     this.CollectLocks(this.lockQueueForReceive);
     this.mainQueueForMove.CloseQueue();
     this.lockQueueForMove.CloseQueue();
     this.lockQueueForReceive.CloseQueue();
     base.CloseQueue();
 }
Exemplo n.º 24
0
        public IOThreadTimer(Action <object> callback, object callbackState, bool isTypicallyCanceledShortlyAfterBeingSet, int maxSkewInMilliseconds)
        {
            IOThreadTimer.TimerGroup volatileTimerGroup;
            this.callback      = callback;
            this.callbackState = callbackState;
            this.maxSkew       = Ticks.FromMilliseconds(maxSkewInMilliseconds);
            IOThreadTimer oThreadTimer = this;

            if (isTypicallyCanceledShortlyAfterBeingSet)
            {
                volatileTimerGroup = IOThreadTimer.TimerManager.Value.VolatileTimerGroup;
            }
            else
            {
                volatileTimerGroup = IOThreadTimer.TimerManager.Value.StableTimerGroup;
            }
            oThreadTimer.timerGroup = volatileTimerGroup;
        }
Exemplo n.º 25
0
            public void DeleteTimer(IOThreadTimer timer)
            {
                int index = timer.index;

                IOThreadTimer[] timers = this.timers;
                while (true)
                {
                    int num2 = index / 2;
                    if (num2 < 1)
                    {
                        break;
                    }
                    IOThreadTimer timer2 = timers[num2];
                    timers[index] = timer2;
                    timer2.index  = index;
                    index         = num2;
                }
                timer.index   = 0;
                timer.dueTime = 0L;
                timers[1]     = null;
                this.DeleteMinTimerCore();
            }
Exemplo n.º 26
0
            public void DeleteTimer(IOThreadTimer timer)
            {
                int num = timer.index;

                IOThreadTimer[] oThreadTimerArray = this.timers;
                while (true)
                {
                    int num1 = num / 2;
                    if (num1 < 1)
                    {
                        break;
                    }
                    IOThreadTimer oThreadTimer = oThreadTimerArray[num1];
                    oThreadTimerArray[num] = oThreadTimer;
                    oThreadTimer.index     = num;
                    num = num1;
                }
                timer.index          = 0;
                timer.dueTime        = (long)0;
                oThreadTimerArray[1] = null;
                this.DeleteMinTimerCore();
            }
 public ReliableInputSessionChannelOverDuplex(ReliableChannelListenerBase<IInputSessionChannel> listener, IServerReliableChannelBinder binder, FaultHelper faultHelper, UniqueId inputID) : base(listener, binder, faultHelper, inputID)
 {
     this.guard = new Guard(0x7fffffff);
     this.acknowledgementInterval = listener.AcknowledgementInterval;
     this.acknowledgementTimer = new IOThreadTimer(new Action<object>(this.OnAcknowledgementTimeoutElapsed), null, true);
     base.DeliveryStrategy.DequeueCallback = new Action(this.OnDeliveryStrategyItemDequeued);
     if (binder.HasSession)
     {
         try
         {
             base.StartReceiving(false);
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             base.ReliableSession.OnUnknownException(exception);
         }
     }
 }
 public TransmissionStrategy(ReliableMessagingVersion reliableMessagingVersion, TimeSpan initRtt, int maxWindowSize, bool requestAcks, UniqueId id)
 {
     if (initRtt < TimeSpan.Zero)
     {
         throw Fx.AssertAndThrow("Argument initRtt cannot be negative.");
     }
     if (maxWindowSize <= 0)
     {
         throw Fx.AssertAndThrow("Argument maxWindow size must be positive.");
     }
     this.id = id;
     this.maxWindowSize = this.lossWindowSize = maxWindowSize;
     this.meanRtt = Math.Min((long) initRtt.TotalMilliseconds, 0x55555555555555L) << 7;
     this.serrRtt = this.meanRtt >> 1;
     this.window = new SlidingWindow(maxWindowSize);
     this.slowStartThreshold = maxWindowSize;
     this.timeout = Math.Max((long) (0xc800L + this.meanRtt), (long) (this.meanRtt + (this.serrRtt << 2)));
     this.quotaRemaining = 0x7fffffff;
     this.retryTimer = new IOThreadTimer(new Action<object>(this.OnRetryElapsed), null, true);
     this.requestAcks = requestAcks;
     this.reliableMessagingVersion = reliableMessagingVersion;
 }
Exemplo n.º 29
0
            public bool Cancel(IOThreadTimer timer)
            {
                bool flag;

                lock (this.ThisLock)
                {
                    if (timer.index <= 0)
                    {
                        flag = false;
                    }
                    else
                    {
                        IOThreadTimer.TimerGroup timerGroup = timer.timerGroup;
                        IOThreadTimer.TimerQueue timerQueue = timerGroup.TimerQueue;
                        timerQueue.DeleteTimer(timer);
                        if (timerQueue.Count <= 0)
                        {
                            IOThreadTimer.TimerGroup otherTimerGroup = this.GetOtherTimerGroup(timerGroup);
                            if (otherTimerGroup.TimerQueue.Count == 0)
                            {
                                long now     = Ticks.Now;
                                long dueTime = timerGroup.WaitableTimer.DueTime - now;
                                long num     = otherTimerGroup.WaitableTimer.DueTime - now;
                                if (dueTime > (long)0x989680 && num > (long)0x989680)
                                {
                                    timerGroup.WaitableTimer.Set(Ticks.Add(now, (long)0x989680));
                                }
                            }
                        }
                        else
                        {
                            this.UpdateWaitableTimer(timerGroup);
                        }
                        flag = true;
                    }
                }
                return(flag);
            }
Exemplo n.º 30
0
            public bool InsertTimer(IOThreadTimer timer, long dueTime)
            {
                IOThreadTimer[] oThreadTimerArray = this.timers;
                int             num = this.count + 1;

                if (num == (int)oThreadTimerArray.Length)
                {
                    oThreadTimerArray = new IOThreadTimer[(int)oThreadTimerArray.Length * 2];
                    Array.Copy(this.timers, oThreadTimerArray, (int)this.timers.Length);
                    this.timers = oThreadTimerArray;
                }
                this.count = num;
                if (num > 1)
                {
                    while (true)
                    {
                        int num1 = num / 2;
                        if (num1 == 0)
                        {
                            break;
                        }
                        IOThreadTimer oThreadTimer = oThreadTimerArray[num1];
                        if (oThreadTimer.dueTime <= dueTime)
                        {
                            break;
                        }
                        oThreadTimerArray[num] = oThreadTimer;
                        oThreadTimer.index     = num;
                        num = num1;
                    }
                }
                oThreadTimerArray[num] = timer;
                timer.index            = num;
                timer.dueTime          = dueTime;
                return(num == 1);
            }
Exemplo n.º 31
0
        void WriteStreamedMessage(TimeSpan timeout)
        {
            this.outputStream = GetWrappedOutputStream();

            // Since HTTP streams don't support timeouts, we can't just use TimeoutStream here. 
            // Rather, we need to run a timer to bound the overall operation
            if (onStreamSendTimeout == null)
            {
                onStreamSendTimeout = new Action<object>(OnStreamSendTimeout);
            }
            IOThreadTimer sendTimer = new IOThreadTimer(onStreamSendTimeout, this, true);
            sendTimer.Set(timeout);

            try
            {
                MtomMessageEncoder mtomMessageEncoder = messageEncoder as MtomMessageEncoder;
                if (mtomMessageEncoder == null)
                {
                    messageEncoder.WriteMessage(this.message, this.outputStream);
                }
                else
                {
                    mtomMessageEncoder.WriteMessage(this.message, this.outputStream, this.mtomBoundary);
                }
            }
            finally
            {
                sendTimer.Cancel();
            }
        }
 void SetFlushTimer()
 {
     if (this.flushTimer == null)
     {
         int flushSkew = Ticks.ToMilliseconds(Math.Min(this.flushTimeout / 10, Ticks.FromMilliseconds(maxFlushSkew)));
         this.flushTimer = new IOThreadTimer(new Action<object>(OnFlushTimer), null, true, flushSkew);
     }
     this.flushTimer.Set(Ticks.ToTimeSpan(this.flushTimeout));
 }
Exemplo n.º 33
0
 public void CancelTimer()
 {
     if (this.timer != null)
     {
         this.timer.Cancel();
         this.timer = null;
     }
 }
Exemplo n.º 34
0
            public void SetTimer(Action<object> callback, object state, TimeSpan timeout)
            {
                if (this.timer != null)
                {
                    throw Fx.Exception.AsError(new InvalidOperationException(InternalSR.MustCancelOldTimer));
                }

                this.originalTimeout = timeout;
                this.timer = new IOThreadTimer(callback, state, false);

                this.timer.Set(timeout);
            }
Exemplo n.º 35
0
        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);
            }
        }
 void CancelRetryTimer()
 {
     if (this.timer != null)
     {
         this.timer.Cancel();
         this.timer = null;
     }
 }
 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;
     }
 }
        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;
        }
Exemplo n.º 39
0
            private void DeleteMinTimerCore()
            {
                int           num;
                int           num1;
                IOThreadTimer oThreadTimer;
                int           num2 = this.count;

                if (num2 != 1)
                {
                    IOThreadTimer[] oThreadTimerArray = this.timers;
                    IOThreadTimer   oThreadTimer1     = oThreadTimerArray[num2];
                    int             num3 = num2 - 1;
                    num2       = num3;
                    this.count = num3;
                    int num4 = 1;
                    do
                    {
                        num = num4 * 2;
                        if (num > num2)
                        {
                            break;
                        }
                        if (num >= num2)
                        {
                            num1         = num;
                            oThreadTimer = oThreadTimerArray[num1];
                        }
                        else
                        {
                            IOThreadTimer oThreadTimer2 = oThreadTimerArray[num];
                            int           num5          = num + 1;
                            IOThreadTimer oThreadTimer3 = oThreadTimerArray[num5];
                            if (oThreadTimer3.dueTime >= oThreadTimer2.dueTime)
                            {
                                oThreadTimer = oThreadTimer2;
                                num1         = num;
                            }
                            else
                            {
                                oThreadTimer = oThreadTimer3;
                                num1         = num5;
                            }
                        }
                        if (oThreadTimer1.dueTime <= oThreadTimer.dueTime)
                        {
                            break;
                        }
                        oThreadTimerArray[num4] = oThreadTimer;
                        oThreadTimer.index      = num4;
                        num4 = num1;
                    }while (num < num2);
                    oThreadTimerArray[num4]     = oThreadTimer1;
                    oThreadTimer1.index         = num4;
                    oThreadTimerArray[num2 + 1] = null;
                    return;
                }
                else
                {
                    this.count     = 0;
                    this.timers[1] = null;
                    return;
                }
            }
        public void WaitAndBackoff(Action<object> callback, object state)
        {
            if (this.backoffCallback != callback || this.backoffState != state)
            {
                if (this.backoffTimer != null)
                {
                    this.backoffTimer.Cancel();
                }
                this.backoffCallback = callback;
                this.backoffState = state;
                this.backoffTimer = new IOThreadTimer(callback, state, false, BackoffTimeoutHelper.maxSkewMilliseconds);
            }

            TimeSpan backoffTime = WaitTimeWithDrift();
            Backoff();
            this.backoffTimer.Set(backoffTime);
        }
Exemplo n.º 41
0
        // 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;
        }
Exemplo n.º 42
0
            void SetTimer(TimeSpan timeout)
            {
                Fx.Assert(this.sendTimer == null, "SetTimer should only be called once");

                this.sendTimer = new IOThreadTimer(onStreamSendTimeout, this.httpOutput, true);
                this.sendTimer.Set(timeout);
            }
            public UnloadInstancePolicyHelper(WorkflowServiceInstance instance, TimeSpan timeToPersist, TimeSpan timeToUnload)
            {
                Fx.Assert(instance != null, String.Empty);

                this.instance = instance;
                this.timeToPersist = timeToPersist;
                this.timeToUnload = timeToUnload;
                this.persistEnabled = this.instance.persistenceContext.CanPersist && this.timeToPersist < this.timeToUnload;
                this.unloadEnabled = this.instance.persistenceContext.CanPersist && this.timeToUnload < TimeSpan.MaxValue;

                if (this.persistEnabled)
                {
                    this.persistTimer = new IOThreadTimer(onTimerCallback, new Action(Persist), true);
                }
                if (this.unloadEnabled)
                {
                    this.unloadTimer = new IOThreadTimer(onTimerCallback, new Action(Unload), true);
                }
            }
            void SetTimer(IOThreadTimer timer, TimeSpan ts)
            {
                Fx.Assert(timer != null && ts >= TimeSpan.Zero, String.Empty);

                // It is ok to dirty read the state, the consistency will be ensured by persis/unload itself.
                if (this.instance.state == State.Suspended)
                {
                    // Unload/Persist immediately when suspended 
                    timer.Set(TimeSpan.Zero);
                }
                else
                {
                    timer.Set(ts);
                }
            }
 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(timeoutCallback, this, false);
     }
     List<InstancePersistenceEvent> list = this.handle.StartWaiting(this, this.timer, this.timeout);
     if (list == null)
     {
         if (this.timeout == TimeSpan.Zero)
         {
             this.handle.CancelWaiting(this);
             throw Fx.Exception.AsError(new TimeoutException(SRCore.WaitForEventsTimedOut(TimeSpan.Zero)));
         }
     }
     else
     {
         this.readyEvents = list;
         base.Complete(true);
     }
 }
 public void Dispose()
 {
     lock (this.internalStateLock)
     {
         if (!this.disposed)
         {
             this.disposed = true;
             this.messageExpiryTimer.Cancel();
             this.messageExpiryTimer = null;
         }
     }
 }