Exemple #1
0
        /**
         * Schedule a task to refresh the link if the refresh mode requires it. In the case of an {@code onInterval} and
         * {@code onExpire} refresh modes, this method schedules a task to update the link after the refresh interval
         * elapses, but only if such a task has not already been scheduled (only one refresh task is active at a time).
         */
        protected void scheduleRefreshIfNeeded()
        {
            Long refreshTime = this.computeRefreshTime();

            if (refreshTime == null)
            {
                return;
            }

            // Determine if the refresh interval has elapsed since the last refresh task was scheduled.
            bool intervalElapsed = System.currentTimeMillis() > refreshTime;

            // If the refresh interval has already elapsed then the link needs to refresh immediately.
            if (intervalElapsed)
            {
                this.updateTime.set(System.currentTimeMillis());
            }

            // Schedule a refresh if the refresh interval has elapsed, or if no refresh task is already active.
            // Checking the refresh interval ensures that even if the task fails to run for some reason, a new
            // task will be scheduled after the interval expires.
            if (intervalElapsed || this.refreshTask == null || this.refreshTask.isDone())
            {
                long refreshDelay = refreshTime - System.currentTimeMillis();
                this.refreshTask = this.scheduleDelayedTask(new RefreshTask(), refreshDelay, TimeUnit.MILLISECONDS);
            }
        }
Exemple #2
0
            public override void Start()
            {
                Scheduler = Executors.newSingleThreadScheduledExecutor(daemon("timeout-clusterClient", Monitors.newMonitor(typeof(NamedThreadFactory.Monitor))));

                TickFuture = Scheduler.scheduleWithFixedDelay(() =>
                {
                    long now = DateTimeHelper.CurrentUnixTimeMillis();

                    Server.Timeouts.tick(now);
                }, 0, 10, TimeUnit.MILLISECONDS);
            }
Exemple #3
0
 protected internal override void After()
 {
     lock (this)
     {
         if (null != _thunk && !_thunk.Done)
         {
             _thunk.cancel(true);
         }
         _thunk = null;
         base.After();
     }
 }
Exemple #4
0
        private void ScheduleHistoryCleaner()
        {
            bool startCleanerService = conf.GetBoolean(JHAdminConfig.MrHistoryCleanerEnable,
                                                       true);

            if (startCleanerService)
            {
                cleanerInterval = conf.GetLong(JHAdminConfig.MrHistoryCleanerIntervalMs, JHAdminConfig
                                               .DefaultMrHistoryCleanerIntervalMs);
                futureHistoryCleaner = scheduledExecutor.ScheduleAtFixedRate(new JobHistory.HistoryCleaner
                                                                                 (this), GetInitDelaySecs() * 1000l, cleanerInterval, TimeUnit.Milliseconds);
            }
        }
Exemple #5
0
        /**
         * Specifies the time at which the linked resource expires. If the link's update mode is onExpire, the link will
         * mark itself updated at this time.
         *
         * @param time Time, in milliseconds since the Epoch, at which the link expires. Zero indicates no expiration.
         */
        public void setExpirationTime(long time)
        {
            // If the refresh mode is onExpire, schedule a task to update the link at the expiration time. Otherwise
            // we don't care about the expiration.
            if (KMLConstants.ON_EXPIRE.Equals(this.getRefreshMode()))
            {
                // If there is already a task running, cancel it
                if (this.refreshTask != null)
                {
                    this.refreshTask.cancel(false);
                }

                if (time != 0)
                {
                    long refreshDelay = time - System.currentTimeMillis();
                    this.refreshTask = this.scheduleDelayedTask(new RefreshTask(), refreshDelay, TimeUnit.MILLISECONDS);
                }
            }
        }
Exemple #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected synchronized void before() throws Throwable
        protected internal override void Before()
        {
            lock (this)
            {
                if (null == _thunk)
                {
                    base.Before();
                    _thunk = _executor.schedule((Callable <Void>)() =>
                    {
                        Dump();
                        return(null);
                    }, _duration, _timeUnit);
                }
                else
                {
                    throw new System.InvalidOperationException("process dumping thunk already started");
                }
            }
        }
Exemple #7
0
 private void ScheduleWithDelay(int suggestedDelay)
 {
     Log.V(Log.TagSync, "%s: scheduleWithDelay called with delay: %d ms", this, suggestedDelay
           );
     if (scheduled && (suggestedDelay < scheduledDelay))
     {
         Log.V(Log.TagSync, "%s: already scheduled and: %d < %d --> unscheduling", this, suggestedDelay
               , scheduledDelay);
         Unschedule();
     }
     if (!scheduled)
     {
         Log.V(Log.TagSync, "not already scheduled");
         scheduled      = true;
         scheduledDelay = suggestedDelay;
         Log.V(Log.TagSync, "workExecutor.schedule() with delay: %d ms", suggestedDelay);
         flushFuture = workExecutor.Schedule(processNowRunnable, suggestedDelay, TimeUnit.
                                             Milliseconds);
     }
 }
Exemple #8
0
 public virtual void RefreshJobRetentionSettings()
 {
     if (GetServiceState() == Service.STATE.Started)
     {
         conf = CreateConf();
         long maxHistoryAge = conf.GetLong(JHAdminConfig.MrHistoryMaxAgeMs, JHAdminConfig.
                                           DefaultMrHistoryMaxAge);
         hsManager.SetMaxHistoryAge(maxHistoryAge);
         if (futureHistoryCleaner != null)
         {
             futureHistoryCleaner.Cancel(false);
         }
         futureHistoryCleaner = null;
         ScheduleHistoryCleaner();
     }
     else
     {
         Log.Warn("Failed to execute refreshJobRetentionSettings : Job History service is not started"
                  );
     }
 }
 private void ScheduleWithDelay(int suggestedDelay)
 {
     Log.D(Database.Tag, "scheduleWithDelay called with delay: " + suggestedDelay + " ms"
           );
     if (scheduled && (suggestedDelay < scheduledDelay))
     {
         Log.D(Database.Tag, "already scheduled and : " + suggestedDelay + " < " + scheduledDelay
               + " --> unscheduling");
         Unschedule();
     }
     if (!scheduled)
     {
         Log.D(Database.Tag, "not already scheduled");
         scheduled      = true;
         scheduledDelay = suggestedDelay;
         Log.D(Database.Tag, "workExecutor.schedule() with delay: " + suggestedDelay + " ms"
               );
         flushFuture = workExecutor.Schedule(processNowRunnable, suggestedDelay, TimeUnit.
                                             Milliseconds);
     }
 }
Exemple #10
0
        internal virtual Resource StartPrinting()
        {
            ScheduledExecutorService timer = Executors.newSingleThreadScheduledExecutor();
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.concurrent.ScheduledFuture<?> timerFuture = timer.scheduleAtFixedRate(this::printOnNextUpdate, 0, interactive ? 100 : 5_000, java.util.concurrent.TimeUnit.MILLISECONDS);
            ScheduledFuture <object> timerFuture = timer.scheduleAtFixedRate(this.printOnNextUpdate, 0, _interactive ? 100 : 5_000, TimeUnit.MILLISECONDS);

            return(() =>
            {
                timerFuture.cancel(false);
                timer.shutdown();
                try
                {
                    timer.awaitTermination(10, TimeUnit.SECONDS);
                }
                catch (InterruptedException)
                {
                }
                Done();
                PrintProgress();
            });
        }
 public override void willTransferPath(Path path)
 {
     _controller._meter.reset();
     _progressTimer = getTimerPool().scheduleAtFixedRate(new ProgressTimerRunnable(_controller),
                                                         Delay, Period, TimeUnit.MILLISECONDS);
 }