Exemplo n.º 1
0
        public IDisposable RegisterTimer(Func <object, Task> asyncCallback, object state, TimeSpan dueTime, TimeSpan period)
        {
            var timer = GrainTimer.FromTaskCallback(asyncCallback, state, dueTime, period);

            AddTimer(timer);
            timer.Start();
            return(timer);
        }
Exemplo n.º 2
0
        public IGrainTimer RegisterTimer(Func <object, Task> asyncCallback, object state, TimeSpan dueTime, TimeSpan period)
        {
            var timer = GrainTimer.FromTaskCallback(asyncCallback, state, dueTime, period, activationData: this);

            AddTimer(timer);
            timer.Start();
            return(timer);
        }
Exemplo n.º 3
0
 internal void AddTimer(GrainTimer timer)
 {
     lock (this)
     {
         if (timers == null)
         {
             timers = new HashSet <GrainTimer>();
         }
         timers.Add(timer);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Internal version of <see cref="RegisterTimer(Func{object, Task}, object, TimeSpan, TimeSpan, string)"/> that returns the inner IGrainTimer
        /// </summary>
        internal IGrainTimer RegisterGrainTimer(Func <object, Task> asyncCallback, object state, TimeSpan dueTime, TimeSpan period, string name = null)
        {
            var ctxt = RuntimeContext.Current;

            name = name ?? ctxt.GrainId + "Timer";

            var timer = GrainTimer.FromTaskCallback(this.timerLogger, asyncCallback, state, dueTime, period, name);

            timer.Start();
            return(timer);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Register a timer to send regular callbacks to this grain.
        /// This timer will keep the current grain from being deactivated.
        /// </summary>
        /// <param name="asyncCallback"></param>
        /// <param name="state"></param>
        /// <param name="dueTime"></param>
        /// <param name="period"></param>
        /// <returns></returns>
        public IDisposable RegisterTimer(Func <object, Task> asyncCallback, object state, TimeSpan dueTime, TimeSpan period)
        {
            var ctxt = RuntimeContext.CurrentActivationContext;

            InsideRuntimeClient.Current.Scheduler.CheckSchedulingContextValidity(ctxt);
            String name = ctxt.Name + "Timer";

            var timer = GrainTimer.FromTaskCallback(asyncCallback, state, dueTime, period, name);

            timer.Start();
            return(timer);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Register a timer to send regular callbacks to this grain.
        /// This timer will keep the current grain from being deactivated.
        /// </summary>
        /// <param name="asyncCallback"></param>
        /// <param name="state"></param>
        /// <param name="dueTime"></param>
        /// <param name="period"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public IDisposable RegisterTimer(Func <object, Task> asyncCallback, object state, TimeSpan dueTime, TimeSpan period, string name = null)
        {
            var ctxt = RuntimeContext.CurrentGrainContext;

            this.RuntimeClient.Scheduler.CheckSchedulingContextValidity(ctxt);
            name = name ?? ctxt.GrainId + "Timer";

            var timer = GrainTimer.FromTaskCallback(this.RuntimeClient.Scheduler, this.timerLogger, asyncCallback, state, dueTime, period, name);

            timer.Start();
            return(timer);
        }
Exemplo n.º 7
0
 public Task Start()
 {
     var random = new SafeRandom();
     var randomOffset = random.NextTimeSpan(orleansConfig.Globals.ClientRegistrationRefresh);
     clientRefreshTimer = GrainTimer.FromTaskCallback(
             OnClientRefreshTimer, 
             null, 
             randomOffset, 
             orleansConfig.Globals.ClientRegistrationRefresh, 
             "ClientObserverRegistrar.ClientRefreshTimer");
     clientRefreshTimer.Start();
     return TaskDone.Done;
 }
 private void Start()
 {
     var random = new SafeRandom();
     var randomOffset = random.NextTimeSpan(orleansConfig.Globals.ClientRegistrationRefresh);
     clientRefreshTimer = GrainTimer.FromTaskCallback(
             OnClientRefreshTimer, 
             null, 
             randomOffset, 
             orleansConfig.Globals.ClientRegistrationRefresh, 
             "ClientObserverRegistrar.ClientRefreshTimer");
     clientRefreshTimer.Start();
     if (logger.IsVerbose) { logger.Verbose("Client registrar service started successfully."); }
 }
Exemplo n.º 9
0
        public Task Start()
        {
            var random       = new SafeRandom();
            var randomOffset = random.NextTimeSpan(orleansConfig.Globals.ClientRegistrationRefresh);

            clientRefreshTimer = GrainTimer.FromTaskCallback(
                OnClientRefreshTimer,
                null,
                randomOffset,
                orleansConfig.Globals.ClientRegistrationRefresh,
                "ClientObserverRegistrar.ClientRefreshTimer");
            clientRefreshTimer.Start();
            return(TaskDone.Done);
        }
Exemplo n.º 10
0
        public async Task Start()
        {
            logger.Info("Starting DeploymentLoadPublisher.");
            if (statisticsRefreshTime > TimeSpan.Zero)
            {
                var random = new SafeRandom();
                // Randomize PublishStatistics timer,
                // but also upon start publish my stats to everyone and take everyone's stats for me to start with something.
                var randomTimerOffset = random.NextTimeSpan(statisticsRefreshTime);
                var t = GrainTimer.FromTaskCallback(PublishStatistics, null, randomTimerOffset, statisticsRefreshTime);
                t.Start();
            }
            await RefreshStatistics();
            await PublishStatistics(null);

            logger.Info("Started DeploymentLoadPublisher.");
        }
Exemplo n.º 11
0
        private void Start()
        {
            var random       = new SafeRandom();
            var randomOffset = random.NextTimeSpan(orleansConfig.Globals.ClientRegistrationRefresh);

            clientRefreshTimer = GrainTimer.FromTaskCallback(
                OnClientRefreshTimer,
                null,
                randomOffset,
                orleansConfig.Globals.ClientRegistrationRefresh,
                "ClientObserverRegistrar.ClientRefreshTimer");
            clientRefreshTimer.Start();
            if (logger.IsVerbose)
            {
                logger.Verbose("Client registrar service started successfully.");
            }
        }
Exemplo n.º 12
0
 internal void OnTimerDisposed(GrainTimer orleansTimerInsideGrain)
 {
     lock (this) // need to lock since dispose can be called on finalizer thread, outside garin context (not single threaded).
     {
         timers.Remove(orleansTimerInsideGrain);
     }
 }
Exemplo n.º 13
0
 internal void AddTimer(GrainTimer timer)
 {
     lock(this)
     {
         if (timers == null)
         {
             timers = new HashSet<GrainTimer>();
         }
         timers.Add(timer);
     }
 }