YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.multiroom.feed.FeedClock Interface Reference

The time source of the feed: a monotonic nanosecond clock and a sleep that goes with it. More...

Collaboration diagram for de.yaacc.multiroom.feed.FeedClock:
Collaboration graph

Public Member Functions

long nanoTime ()
 A monotonic time in nanoseconds; only differences mean something.
 
void sleepNanos (long nanos) throws InterruptedException
 Waits until this clock has advanced by nanos; returns at once for zero or less.
 
void wake (Thread thread)
 Ends the sleep of thread early.
 

Public Attributes

FeedClock SYSTEM
 The real clock: System#nanoTime(), a sleep that ends early on an interrupt or a wake.
 

Detailed Description

The time source of the feed: a monotonic nanosecond clock and a sleep that goes with it.

The real one is SYSTEM; a test passes a clock that it moves by hand, so that pacing needs no real waiting.

Member Function Documentation

◆ sleepNanos()

void de.yaacc.multiroom.feed.FeedClock.sleepNanos ( long nanos) throws InterruptedException

Waits until this clock has advanced by nanos; returns at once for zero or less.

May return early (after a wake, or spuriously): the caller looks at the situation again and sleeps again if it must.

Exceptions
InterruptedExceptionwhen the thread is interrupted (the feeder does that to stop its writer)

◆ wake()

void de.yaacc.multiroom.feed.FeedClock.wake ( Thread thread)

Ends the sleep of thread early.

If it does not sleep now, its next sleep returns at once (the permit of LockSupport.unpark). The feeder uses it to tell the writer that audio has arrived.

Member Data Documentation

◆ SYSTEM

FeedClock de.yaacc.multiroom.feed.FeedClock.SYSTEM
Initial value:
= new FeedClock() {
@Override
public long nanoTime() {
return System.nanoTime();
}
@Override
public void sleepNanos(long nanos) throws InterruptedException {
if (Thread.interrupted()) {
throw new InterruptedException();
}
if (nanos > 0) {
LockSupport.parkNanos(nanos);
}
if (Thread.interrupted()) {
throw new InterruptedException();
}
}
@Override
public void wake(Thread thread) {
LockSupport.unpark(thread);
}
}
long nanoTime()
A monotonic time in nanoseconds; only differences mean something.
void sleepNanos(long nanos)
Waits until this clock has advanced by nanos; returns at once for zero or less.
void wake(Thread thread)
Ends the sleep of thread early.

The real clock: System#nanoTime(), a sleep that ends early on an interrupt or a wake.


The documentation for this interface was generated from the following file: