Return the next event that is safe for delivery or null
if there are no safe objects to deliver.

Null response could mean no events, or could mean all events
are scheduled for the future.

@param systemCurrentTimeMillis The current time.
772632
@Override
    public T next(long systemCurrentTimeMillis) {
        // drain all the waiting messages from the source (up to 10k)
        while (delayed.size() < 10000) {
            T event = source.next(systemCurrentTimeMillis);
            if (event == null) {
                break;
            }
            transformAndQueue(event, systemCurrentTimeMillis);
        }

        return delayed.nextReady(systemCurrentTimeMillis);
    }
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);
    }
274306
public Object next()
	{
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
    {
      SibTr.entry(tc, "next");
    } 
    
    Object result;
		if (msgIterator.hasNext())
		{
      Long valueStamp = (Long) msgIterator.next();
      
			result = new TransmitMessageRequest(valueStamp.longValue(), aoStream.itemStream, aoStream, messageProcessor, aoh.getDestinationHandler());
		}
		else
		{
			result = null;
		}
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
    {
      SibTr.exit(tc, "next", result);
    } 
    return result;
	}
1366717
public ICalendar readNext() throws IOException {
		warnings.clear();
		context = new ParseContext();
		ICalendar ical = _readNext();
		if (ical == null) {
			return null;
		}

		ical.setVersion(context.getVersion());
		handleTimezones(ical);
		return ical;
	}
570020
private boolean getNextEviction() {
		long nowTime = System.currentTimeMillis();
		final long sleepEndTime = nowTime + evictionInverval;

		while (nowTime < sleepEndTime) {
			final long toSleep = Math.max(100, sleepEndTime - nowTime);
			synchronized (this) {
				if (terminate)
					return false;
				try {
					wait(toSleep);
				} catch (InterruptedException e) {
					// ignore
				}
			}
			nowTime = System.currentTimeMillis();
		}
		return true;
	}
348131
public final ZEvent nextEvent(boolean wait)
    {
        if (!started) {
            System.out.println("ZMonitor: Start before getting events.");
            return null;
        }
        ZMsg msg = agent.recv(wait);
        if (msg == null) {
            return null;
        }
        return new ZEvent(msg);
    }
1201814
public TimelineEvent getEvent(String index) {
        return getEvent(index != null ? Integer.valueOf(index) : -1);
    }
1248505
public synchronized EventData getNextEvent(int event_type) throws DevFailed {
        EventData ev_data = null;
        for (EventData event : events)
            if (event.event_type == event_type)
                ev_data = event;
        if (ev_data == null)
            Except.throw_exception("BUFFER_EMPTY",
                    "No " + TangoConst.eventNames[event_type] + " in event queue.",
                    "EventQueue.getNextEvent()");
        events.remove(ev_data);
        return ev_data;
    }
928458
public long nextBackOffMillis() throws IOException {
    // Make sure we have not gone over the maximum elapsed time.
    if (getElapsedTimeMillis() > maxElapsedTimeMillis) {
      return STOP;
    }
    int randomizedInterval =
        getRandomValueFromInterval(randomizationFactor, Math.random(), currentIntervalMillis);
    incrementCurrentInterval();
    return randomizedInterval;
  }
752927
@Override
	public T next() {
		if (hasNext()) {
			T current = next;
			next = null;
			return current;
		} else {
			throw new NoSuchElementException();
		}
	}
520576
protected HttpServletResponse getCurrentResponse() {
        final HttpServletResponse response = httpService.getCurrentResponse();
        if (response == null) {
            throw new IllegalStateException("No HttpServletResponse bound to current thread");
        }
        return response;
    }
470280
public static <T extends SubSystem> T
  getCurrentSystem(Class<T> systemClass)
  {
    SystemManager manager = getCurrent();

    if (manager != null)
      return manager.getSystem(systemClass);
    else
      return null;
  }
541035
public synchronized long nextId() throws InvalidSystemClock {
        long timestamp = timeGen();
        long curSequence = 0L;

        final long prevTimestamp = lastTimestamp.get();

        if (timestamp < prevTimestamp) {
            exceptionsCounter.inc();
            LOGGER.error(
                    "clock is moving backwards. Rejecting requests until {}",
                    prevTimestamp);
            throw new InvalidSystemClock(
                    String.format(
                            "Clock moved backwards. Refusing to generate id for %d milliseconds",
                            (prevTimestamp - timestamp)));
        }

        if (prevTimestamp == timestamp) {
            curSequence = sequence.incrementAndGet() & SEQUENCE_MASK;
            if (curSequence == 0) {
                timestamp = tilNextMillis(prevTimestamp);
            }
        } else {
            curSequence = 0L;
            sequence.set(0L);
        }

        lastTimestamp.set(timestamp);
        final long id = ((timestamp - TWEPOCH) << TIMESTAMP_LEFT_SHIFT)
                | (datacenterId << DATACENTER_ID_SHIFT)
                | (workerId << WORKER_ID_SHIFT) | curSequence;

        LOGGER.trace(
                "prevTimestamp = {}, timestamp = {}, sequence = {}, id = {}",
                prevTimestamp, timestamp, sequence, id);

        return id;
    }
1219728
public static long waitTillNextMillisec(long currentMillisec) {
        long nextMillisec = System.currentTimeMillis();
        for (; nextMillisec <= currentMillisec; nextMillisec = System.currentTimeMillis()) {
            Thread.yield();
        }
        return nextMillisec;
    }
212415
public T get() {
        EventImpl event = (EventImpl) CurrentEvent.get();
        if (null == event) {
            return null;
        }
        return event.get(this);
    }
823616
public Object next()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "next");
    
    Long ticks;  
    RemoteMessageRequest remoteMessageRequest;
    if (msgIterator.hasNext())
    {
      ticks =  (Long) msgIterator.next();
      
      remoteMessageRequest = new RemoteMessageRequest(ticks.longValue(), aiStream);
    }
    else
    {
    	remoteMessageRequest = null;
    }
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "next", remoteMessageRequest);
      
    return remoteMessageRequest;      
  }
196502
public final GregorianCalendar getNextRunTime(GregorianCalendar schedule_start, int run_count)
    {
        Schedule schedule = getSchedule(run_count);
        return schedule == null ? null : schedule.getNextRunTime(schedule_start);
    }