private static void CancelInternal(ITimerCallback callback, int id, PooledLinkedList <Entry> list)
        {
            if (ReferenceEquals(callback, null))
            {
                throw new ArgumentNullException("callback");
            }

            var current = list.First;

            while (current != null)
            {
                var entry = current.Value;

                if (entry.Callback == callback &&
                    entry.Id == id)
                {
                    var next = current.Next;
                    list.Remove(current);
                    current = next;
                }
                else
                {
                    current = current.Next;
                }
            }
        }
Example #2
0
 public Entry(float time, ITimerCallback callback, int id = NoId, object args = null)
 {
     Time              = time;
     Callback          = callback;
     Id                = id;
     Args              = args;
     Repeating         = false;
     RepeatingInterval = 0;
 }
Example #3
0
 public EPLTimerTask(ITimerCallback callback)
 {
     _timerCallback  = callback.TimerCallback;
     EnableStats     = false;
     LastDrift       = 0;
     MaxDrift        = 0;
     TotalDrift      = 0;
     InvocationCount = 0;
 }
Example #4
0
        /// <summary>
        /// Schedule a callback to be called at a specific <see cref="Time.time"/> and repeatedly every <paramref name="repeatInterval"/> there after.
        /// </summary>
        /// <param name="time">The <see cref="Time.time"/> at which the callback should be called.</param>
        /// <param name="repeatInterval">The interval in seconds to repeat the timer.</param>
        /// <param name="callback">The callback that will be notified.</param>
        /// <param name="id">An id so that you can reidentify the origin of the timer. Optional, but useful if you have more than one timer.</param>
        /// <param name="args">An optional args object that will be passed to the callback.</param>
        public static void Exact(float time, float repeatInterval, ITimerCallback callback, int id = NoId, object args = null)
        {
            var entry = new Entry(time, callback, id, args)
            {
                Repeating         = true,
                RepeatingInterval = repeatInterval
            };

            InsertIntoList(entry, EntriesScaled);
        }
        /// <summary>
        /// Schedule a callback to be called at a specific <see cref="Time.time"/>.
        /// </summary>
        /// <param name="time">The <see cref="Time.time"/> at which the callback should be called.</param>
        /// <param name="callback">The callback that will be notified.</param>
        /// <param name="id">An id so that you can reidentify the origin of the timer. Optional, but useful if you have more than one timer.</param>
        /// <param name="args">An optional args object that will be passed to the callback.</param>
        public static void Exact(float time, ITimerCallback callback, int id = NoId, object args = null)
        {
            if (ReferenceEquals(callback, null))
            {
                throw new ArgumentNullException("callback");
            }

            var entry = new Entry(time, callback, id, args);

            InsertIntoList(entry, EntriesScaled);
        }
Example #6
0
 /// <summary>
 /// Schedule a callback to be called after a specific amount of (scaled) seconds.
 /// </summary>
 /// <param name="seconds">The amount of seconds before the callback should be called.</param>
 /// <param name="callback">The callback that will be notified.</param>
 /// <param name="id">An id so that you can reidentify the origin of the timer. Optional, but useful if you have more than one timer.</param>
 /// <param name="args">An optional args object that will be passed to the callback.</param>
 /// <param name="repeating">Whether the timer should repeat untill cancelled.</param>
 public static void Seconds(float seconds, ITimerCallback callback, int id = NoId, object args = null, bool repeating = false)
 {
     if (repeating)
     {
         Exact(BetterTime.Time + seconds, seconds, callback, id, args);
     }
     else
     {
         Exact(BetterTime.Time + seconds, callback, id, args);
     }
 }
        /// <summary>
        /// Schedule a callback to be called at a specific <see cref="Time.unscaledTime"/> and repeatedly every <paramref name="repeatInterval"/> there after.
        /// </summary>
        /// <param name="time">The <see cref="Time.unscaledTime"/> at which the callback should be called.</param>
        /// <param name="repeatInterval">The interval in seconds to repeat the timer.</param>
        /// <param name="callback">The callback that will be notified.</param>
        /// <param name="id">An id so that you can reidentify the origin of the timer. Optional, but useful if you have more than one timer.</param>
        /// <param name="args">An optional args object that will be passed to the callback.</param>
        public static void ExactUnscaled(float time, float repeatInterval, ITimerCallback callback, int id = NoId, object args = null)
        {
            if (ReferenceEquals(callback, null))
            {
                throw new ArgumentNullException("callback");
            }

            var entry = new Entry(time, callback, id, args)
            {
                Repeating         = true,
                RepeatingInterval = repeatInterval
            };

            InsertIntoList(entry, EntriesUnscaled);
        }
Example #8
0
        private static void CancelInternal(ITimerCallback callback, PooledLinkedList <Entry> list)
        {
            var current = list.First;

            while (current != null)
            {
                var entry = current.Value;

                if (entry.Callback == callback)
                {
                    var next = current.Next;
                    list.Remove(current);
                    current = next;
                }
                else
                {
                    current = current.Next;
                }
            }
        }
Example #9
0
        /// <summary>
        /// Schedule a callback to be called at a specific <see cref="Time.time"/>.
        /// </summary>
        /// <param name="time">The <see cref="Time.time"/> at which the callback should be called.</param>
        /// <param name="callback">The callback that will be notified.</param>
        /// <param name="id">An id so that you can reidentify the origin of the timer. Optional, but useful if you have more than one timer.</param>
        /// <param name="args">An optional args object that will be passed to the callback.</param>
        public static void Exact(float time, ITimerCallback callback, int id = NoId, object args = null)
        {
            var entry = new Entry(time, callback, id, args);

            InsertIntoList(entry, EntriesScaled);
        }
Example #10
0
 /// <summary>
 /// Cancels a unscaled timer for the given callback with a specific id.
 /// </summary>
 /// <param name="callback">The callback of the timer to cancel.</param>
 /// <param name="id">The id of the timer to cancel.</param>
 public static void CancelUnscaled(ITimerCallback callback, int id)
 {
     CancelInternal(callback, id, EntriesUnscaled);
 }
Example #11
0
 /// <summary>
 /// Cancels all scaled timers for the given callback.
 /// </summary>
 /// <param name="callback">The callback of the timers to cancel.</param>
 public static void CancelScaled(ITimerCallback callback)
 {
     CancelInternal(callback, EntriesScaled);
 }
Example #12
0
 /// <summary>
 /// Schedule a callback to be called after a specific amount of (unscaled) minutes.
 /// </summary>
 /// <param name="minutes">The amount of minutes before the callback should be called.</param>
 /// <param name="callback">The callback that will be notified.</param>
 /// <param name="id">An id so that you can reidentify the origin of the timer. Optional, but useful if you have more than one timer.</param>
 /// <param name="args">An optional args object that will be passed to the callback.</param>
 /// <param name="repeating">Whether the timer should repeat untill cancelled.</param>
 public static void MinutesUnscaled(float minutes, ITimerCallback callback, int id = NoId, object args = null, bool repeating = false)
 {
     SecondsUnscaled(minutes * 60, callback, id, args, repeating);
 }
Example #13
0
        // ===========================================================
        // Constructors
        // ===========================================================

        public TimerHandler(float pTimerSeconds, ITimerCallback pTimerCallback)
        {
            Init(pTimerSeconds, false);
            this.mTimerCallback = pTimerCallback;
        }
Example #14
0
 public int CreateNewTimerEvent(float sT, float d, ITimerCallback cb)
 {
     tData.Add(currTimerCreated, new TimerData(sT, d, cb));
     currTimerCreated++;
     return(currTimerCreated - 1);
 }
Example #15
0
 public int CreateNewTimerEvent(float d, ITimerCallback cb)
 {
     tData.Add(currTimerCreated, new TimerData(Time.realtimeSinceStartup, d, cb));
     currTimerCreated++;
     return(currTimerCreated - 1);
 }
Example #16
0
 public TimerData(float sT, float d, ITimerCallback cb)
 {
     startTime = sT;
     duration  = d;
     callback  = cb;
 }
Example #17
0
 public TimerHandler(float pTimerSeconds, bool pAutoReset, ITimerCallback pTimerCallback)
 {
     Init(pTimerSeconds, pAutoReset /*, pTimerCallback*/);
 }
Example #18
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="aSessionId">
 /// The unique identifier of the session that the tab is in.
 /// </param>
 /// <param name="aTabKey">
 /// An identifier for this tab, unique within its session.
 /// </param>
 /// <param name="aListener">
 /// A listener that will be notified about changes to the state of the
 /// event queue. Used to implement the "server health" app.
 /// Important: The event-handler will be invoked while some app-state
 /// locks are held. To avoid deadlock, it's a good idea to use
 /// TabStatusQueue to transfer the events to another thread.
 /// </param>
 /// <param name="aClock">
 /// Provides access to the current UTC time. Production code should
 /// likely use ()=>DateTime.UtcNow, testing code will want more direct
 /// control over the perceived time.
 /// </param>
 /// <param name="aTimeoutPolicy">
 /// Policy on how long to keep long polls alive and how long to
 /// keep a tab alive with no outstanding long poll.
 /// </param>
 /// <param name="aTimerThread">
 /// Timer for scheduling maintenance work, such as checking for
 /// expired tabs and long polls.
 /// </param>
 /// <param name="aAppsStateThread">
 /// The soft thread for scheduling all asynchronous work. When we
 /// get invoked from the timer thread, we dispatch back to this
 /// thread before touching any of our mutable state.
 /// </param>
 /// <param name="aSession">
 /// Something that wants to know when a tab should expire due to
 /// inactivity.
 /// </param>
 /// <param name="aAppRecord">
 /// AppRecord associated with the tab.
 /// </param>
 public ServerTab(
     string aSessionId,
     string aTabKey,
     ITabStatusListener aListener,
     Func<DateTime> aClock,
     ServerTabTimeoutPolicy aTimeoutPolicy,
     ITimerThread aTimerThread,
     IStrand aAppsStateThread,
     ISession aSession,
     AppRecord aAppRecord)
 {
     SessionId = aSessionId;
     iListener = aListener;
     iAppsStateThread = aAppsStateThread;
     iSession = aSession;
     iTimerThread = aTimerThread;
     iClock = aClock;
     iTimeoutPolicy = aTimeoutPolicy;
     TabKey = aTabKey;
     AppRecord = aAppRecord;
     iEventQueue = new JsonEventQueue(12000);// aEventQueue;
     iLastRead = iClock();
     iTimerCallback = iTimerThread.RegisterCallback(
         ()=>iAppsStateThread.ScheduleExclusive(DoMaintenance));
     RescheduleMaintenance();
 }