Checks the duration between the last commit to this index and the current
time and flushes the index (if there are changes at all) if the duration
(idle time) is more than {@link SearchIndex#getVolatileIdleTime()}
seconds.
492832
private synchronized void checkFlush()
   {
      // avoid frequent flushes during reindexing;
      long idleTime = online.get() ? System.currentTimeMillis() - lastFlushTime : 0;
      long volatileTime = System.currentTimeMillis() - lastFileSystemFlushTime;
      // do not flush if volatileIdleTime is zero or negative
      if ((handler.getVolatileIdleTime() > 0 && idleTime > handler.getVolatileIdleTime() * 1000)
         || (handler.getMaxVolatileTime() > 0 && volatileTime > handler.getMaxVolatileTime() * 1000))
      {
         try
         {
            if (redoLog.hasEntries())
            {
               LOG.debug("Flushing index after being idle for " + idleTime + " ms.");
               synchronized (updateMonitor)
               {
                  //updateInProgress = true;
                  indexUpdateMonitor.setUpdateInProgress(true, true);
               }
               try
               {
                  flush();
               }
               finally
               {
                  synchronized (updateMonitor)
                  {
                     //updateInProgress = false;
                     indexUpdateMonitor.setUpdateInProgress(false, true);
                     updateMonitor.notifyAll();
                     releaseMultiReader();
                  }
               }
            }
         }
         catch (IOException e)
         {
            LOG.error("Unable to commit volatile index", e);
         }
      }
   }
1141617
def flush_and_refresh(self, index):
        
        self.client.indices.flush(wait_if_ongoing=True, index=index)
        self.client.indices.refresh(index=index)
        self.client.cluster.health(
            wait_for_status='yellow', request_timeout=30)
        return True
144365
public Duration getNextRetryInterval(String clientId, Exception lastException, Duration remainingTime) {
        int baseWaitTime = 0;
        synchronized (this.serverBusySync) {
            if (lastException != null
                    && (lastException instanceof ServerBusyException || (lastException.getCause() != null && lastException.getCause() instanceof ServerBusyException))) {
                baseWaitTime += ClientConstants.SERVER_BUSY_BASE_SLEEP_TIME_IN_SECS;
            }
        }

        return this.onGetNextRetryInterval(clientId, lastException, remainingTime, baseWaitTime);
    }
496032
@Override
    public boolean flush()
    {
        //  If there are no un-flushed items, do nothing.
        if (w == f) {
            return true;
        }

        //  Try to set 'c' to 'f'.
        if (!c.compareAndSet(w, f)) {
            //  Compare-and-swap was unsuccessful because 'c' is NULL.
            //  This means that the reader is asleep. Therefore we don't
            //  care about thread-safeness and update c in non-atomic
            //  manner. We'll return false to let the caller know
            //  that reader is sleeping.
            c.set(f);
            w = f;
            return false;
        }

        //  Reader is alive. Nothing special to do now. Just move
        //  the 'first un-flushed item' pointer to 'f'.
        w = f;
        return true;
    }
1110281
boolean flush() {
    if (!dirty)
      return true;

    acquireExclusiveLock();
    try {

      final long timer = OProfiler.getInstance().startChrono();

      // FORCE THE WRITE OF THE BUFFER
      for (int i = 0; i < FORCE_RETRY; ++i) {
        try {
          buffer.force();
          dirty = false;
          break;
        } catch (Exception e) {
          OLogManager.instance().debug(this,
              "Cannot write memory buffer to disk. Retrying (" + (i + 1) + "/" + FORCE_RETRY + ")...");
          OMemoryWatchDog.freeMemory(FORCE_DELAY);
        }
      }

      if (dirty)
        OLogManager.instance().debug(this, "Cannot commit memory buffer to disk after %d retries", FORCE_RETRY);
      else
        OProfiler.getInstance().updateCounter("system.file.mmap.pagesCommitted", 1);

      OProfiler.getInstance().stopChrono("system.file.mmap.commitPages", timer);

      return !dirty;

    } finally {
      releaseExclusiveLock();
    }
  }
1018912
@Override
    @Transactional(MillJpaRepoConfig.TRANSACTION_MANAGER_BEAN)
    public void purgeExpired() {
        log.info("flushing all written log entries over {} days old.", ageInDaysOfPurgeableWrittenLogEntries);

        Calendar c = Calendar.getInstance();
        c.add(Calendar.DATE, ageInDaysOfPurgeableWrittenLogEntries * -1);
        Date date = c.getTime();
        long deleted = this.repo.deleteByWrittenTrueAndTimestampLessThan(date.getTime());
        log.info("successfully deleted {} audit log entries that had been written and were timestamped before {}",
                 deleted, date);

    }
10407
private int bucketLowInterval(final int index) {
    if (index <= num_linear_buckets) {
      return index * interval;
    } else {
      return cutoff + (1 << (index - num_linear_buckets + exp_bucket_shift));
    }
  }
1303871
public int flush(final MetricSender sender) throws IOException, HttpException {
		Preconditions.checkNotNull(sender);
				
		// aggregate metrics that were enqueued before the current minute
		
		long currentMinute = (System.currentTimeMillis() / MS_IN_MIN) * MS_IN_MIN;
		
		LOGGER.debug("Flushing metrics < {}", currentMinute);
		LOGGER.debug("Metrics queue size {}", queue.size());
		
		MetricAggregator aggregator = new MetricAggregator(currentMinute, lastValues);
		
		while ((!queue.isEmpty()) && (queue.peek().getOccurredMillis() < currentMinute)) {
			aggregator.add(queue.remove());
		}

		// handle the auto reports
		
		if (lastFlush < currentMinute) {
			aggregator.autoReportZero(autoReportZeroMetrics);
			aggregator.autoReportLast(autoReportLastMetrics);
		}
		
		lastFlush = currentMinute;
		
		// get the aggregates
		
		List<MetricAggregate> aggregates = aggregator.getAggregates();

		// Save the values of gauge and average metrics for the next iteration
		// Gauge last value = aggregate last value
		// Average last value = aggregate last value / aggregate count
		
		if ((aggregates != null) && (!aggregates.isEmpty())) {
			for (MetricAggregate aggregate : aggregates) {
				if (aggregate.getIdentity().getType().equals(MetricMonitorType.GAUGE)) {
					lastValues.put(aggregate.getIdentity(), aggregate.getValue());
				} else if (aggregate.getIdentity().getType().equals(MetricMonitorType.AVERAGE)) {
					lastValues.put(aggregate.getIdentity(), aggregate.getValue() / aggregate.getCount());
				}
			}
		}
		
		// send the aggregates to Stackify
		
		int numSent = 0;
		
		if ((aggregates != null) && (!aggregates.isEmpty())) {
			LOGGER.debug("Sending aggregate metrics: {}", aggregates);
			sender.send(aggregates);
			numSent = aggregates.size();
		}
		
		return numSent;
	}
1112766
public void checkKeepOrRemove() {
    boolean _hasKeepAfterExpired = heapCache.isKeepAfterExpired();
    if (expiry != 0 || remove || _hasKeepAfterExpired) {
      mutationUpdateHeap();
      return;
    }
    if (_hasKeepAfterExpired) {
      expiredImmediatelyKeepData();
      return;
    }
    expiredImmediatelyAndRemove();
  }
621983
@JsonIgnore
    protected boolean isRefreshTokenExpired(final TicketState ticketState) {
        if (ticketState == null) {
            return true;
        }
        val expiringTime = ticketState.getCreationTime().plus(this.timeToKillInSeconds, ChronoUnit.SECONDS);
        return expiringTime.isBefore(ZonedDateTime.now(ZoneOffset.UTC));
    }
1037321
synchronized boolean setLastRecoveryTime(long now) {
    boolean expired = now - lastRecoveryTime > NameNode.LEASE_RECOVER_PERIOD;
    if (expired) {
      lastRecoveryTime = now;
    }
    return expired;
  }
1052694
@Override
    public boolean flushPuts(long waitTime, TimeUnit timeUnit) throws InterruptedException
    {
        long    msWaitRemaining = TimeUnit.MILLISECONDS.convert(waitTime, timeUnit);
        synchronized(putCount)
        {
            while ( putCount.get() > 0 )
            {
                if ( msWaitRemaining <= 0 )
                {
                    return false;
                }

                long        startMs = System.currentTimeMillis();

                putCount.wait(msWaitRemaining);

                long        elapsedMs = System.currentTimeMillis() - startMs;
                msWaitRemaining -= elapsedMs;
            }
        }
        return true;
    }
1208828
private long getLastTimeStamp(Path pathToCheck) {
    long lastTimeStamp = -1;
    long tmpTimeStamp = -1;
    try {
      for (FileStatus fileStat: fs.listStatus(pathToCheck)) {
        Path srcPath = fileStat.getPath();
        if (!fileStat.isDir()) {
          boolean checkFlag = true;
          if (release_pattern != null) {
            // just need to check the files that match the pattern
            Matcher m = release_pattern.matcher(srcPath.toString());
            if (!m.find()) {
              checkFlag = false;
            } 
          }
          if (checkFlag) {
            tmpTimeStamp = fileStat.getModificationTime();
          } else {
            continue;
          }
        } else {
          tmpTimeStamp = getLastTimeStamp(srcPath);
        }
        if (tmpTimeStamp > lastTimeStamp) {
          lastTimeStamp = tmpTimeStamp;
        }
      }
    } catch (IOException ioe) {
      LOG.error("IOException when checking timestamp ", ioe);
    }
    return lastTimeStamp;
  }
521021
public long getLastModified() {
        if(matchedEntry != null){
            return matchedEntry.getLastModified();
        } else if (matchedZipFile != null){
            return matchedZipFile.getLastModified();
        } else if (matchedFile != null){
            return matchedFile.lastModified();
        } else {
            return 0;
        }
    }
895676
public boolean isIdleExpire()
  {
    if (! _lifecycle.isActive())
      return true;
    
    long now = currentTimeActual();
    
    long idleExpire = _threadIdleExpireTime.get();
    
    int idleCount = _idleCount.get();

    // if idle queue is full and the expire is set, return and exit
    if (_idleMin < idleCount) {
      long nextIdleExpire = now + _idleTimeout;

      if (_idleMax < idleCount 
          && _idleMin < _idleMax) {
        /*
          && _threadIdleExpireTime.compareAndSet(idleExpire, nextIdleExpire)) {
          */
        _threadIdleExpireTime.compareAndSet(idleExpire, nextIdleExpire);
        
        return true;
      }
      else if (idleExpire < now
               && _threadIdleExpireTime.compareAndSet(idleExpire,
                                                      nextIdleExpire)) {
        return true;
      }
    }
    
    return false;
  }
234279
@Override
  public boolean isModified()
  {
    long now = CurrentTime.currentTime();
    long lastCheckTime = _lastCheckTime.get();
    
    if (now <= lastCheckTime + _checkInterval) {
      return _isModified;
    }

    if (! _lastCheckTime.compareAndSet(lastCheckTime, now)) {
      return _isModified;
    }

    if (isModifiedImpl()) {
      _isModified = true;
      //_lastCheckTime.set(0);
    }
    else {
      _isModified = false;
    }

    return _isModified;
  }
919584
private void scheduleFlushTask()
   {
      // cancel task
      if (flushTask != null)
      {
         flushTask.cancel();
      }
      // clear canceled tasks
      FLUSH_TIMER.purge();
      // new flush task, cause canceled can't be re-used
      flushTask = new TimerTask()
      {
         @Override
         public void run()
         {
            // check if volatile index should be flushed
            checkFlush();
         }
      };
      FLUSH_TIMER.schedule(flushTask, 0, 1000);
      lastFlushTime = System.currentTimeMillis();
      lastFileSystemFlushTime = System.currentTimeMillis();
   }