Top Description Inners Fields Constructors Methods
org.LatencyUtils

public Class TimeServices

extends Object
Class Inheritance
Imports
java.util.Comparator, java.util.concurrent.*

Provide an API for time-related service, such as getting the current time and waiting for a given period of time. By default, these services are provided by actual time services in the JDK (i.e. System.nanoTime(), System.currentTimeMillis(), Thread.sleep(), and java.util.concurrent.locks.LockSupport.parkNanos()). However, if the property LatencyUtils.useActualTime is set to "false", TimeServers will only move the notion of time in response to calls to the #setCurrentTime() method.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private static long
private static final Object
public static final boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static long
public static void
moveTimeForward(long timeDeltaNsec)

public static void
moveTimeForwardMsec(long timeDeltaMsec)

public static long
public static void
setCurrentTime(long newCurrentTime)

public static void
sleepMsecs(long sleepTimeMsec)

public static void
sleepNanos(long sleepTimeNsec)

public static void
waitUntilTime(long timeToWakeAt)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentTimeback to summary
private static long currentTime
timeUpdateMonitorback to summary
private static final Object timeUpdateMonitor
useActualTimeback to summary
public static final boolean useActualTime

Constructor Detail

TimeServicesback to summary
public TimeServices()

Method Detail

currentTimeMillisback to summary
public static long currentTimeMillis()
moveTimeForwardback to summary
public static void moveTimeForward(long timeDeltaNsec) throws InterruptedException
moveTimeForwardMsecback to summary
public static void moveTimeForwardMsec(long timeDeltaMsec) throws InterruptedException
nanoTimeback to summary
public static long nanoTime()
setCurrentTimeback to summary
public static void setCurrentTime(long newCurrentTime) throws InterruptedException
sleepMsecsback to summary
public static void sleepMsecs(long sleepTimeMsec)
sleepNanosback to summary
public static void sleepNanos(long sleepTimeNsec)
waitUntilTimeback to summary
public static void waitUntilTime(long timeToWakeAt) throws InterruptedException
org.LatencyUtils back to summary

public Class TimeServices.ScheduledExecutor

extends Object
Class Inheritance

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
private class
private static class

Field Summary

Modifier and TypeField and Description
private final ScheduledThreadPoolExecutor
private static TimeServices.ScheduledExecutor.CompareRunnableTaskEntryByStartTime
pack-priv final TimeServices.ScheduledExecutor.MyExecutorThread
pack-priv final PriorityBlockingQueue<TimeServices.ScheduledExecutor.RunnableTaskEntry>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actualExecutorback to summary
private final ScheduledThreadPoolExecutor actualExecutor
compareRunnableTaskEntryByStartTimeback to summary
private static TimeServices.ScheduledExecutor.CompareRunnableTaskEntryByStartTime compareRunnableTaskEntryByStartTime
internalExecutorThreadback to summary
pack-priv final TimeServices.ScheduledExecutor.MyExecutorThread internalExecutorThread
taskEntriesback to summary
pack-priv final PriorityBlockingQueue<TimeServices.ScheduledExecutor.RunnableTaskEntry> taskEntries

Constructor Detail

ScheduledExecutorback to summary
pack-priv ScheduledExecutor()

Method Detail

scheduleAtFixedRateback to summary
public void scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
shutdownback to summary
public void shutdown()
org.LatencyUtils back to summary

pack-priv Class TimeServices.ScheduledExecutor.CompareRunnableTaskEntryByStartTime

extends Object
implements Comparator<TimeServices.ScheduledExecutor.RunnableTaskEntry>
Class Inheritance
  • java.lang.Object
  • org.LatencyUtils.TimeServices.ScheduledExecutor.CompareRunnableTaskEntryByStartTime
All Implemented Interfaces
java.util.Comparator

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
compare(TimeServices.ScheduledExecutor.RunnableTaskEntry
the first object to be compared.
r1
,
TimeServices.ScheduledExecutor.RunnableTaskEntry
the second object to be compared.
r2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CompareRunnableTaskEntryByStartTimeback to summary
pack-priv CompareRunnableTaskEntryByStartTime()

Method Detail

compareback to summary
public int compare(TimeServices.ScheduledExecutor.RunnableTaskEntry r1, TimeServices.ScheduledExecutor.RunnableTaskEntry r2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
r1:TimeServices.ScheduledExecutor.RunnableTaskEntry

the first object to be compared.

r2:TimeServices.ScheduledExecutor.RunnableTaskEntry

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

org.LatencyUtils back to summary

private Class TimeServices.ScheduledExecutor.MyExecutorThread

extends Thread
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv volatile boolean
Inherited from java.lang.Thread:
MAX_PRIORITYMIN_PRIORITYNORM_PRIORITY

Constructor Summary

AccessConstructor and Description
private

Field Detail

doRunback to summary
pack-priv volatile boolean doRun

Constructor Detail

MyExecutorThreadback to summary
private MyExecutorThread()

Method Detail

runback to summary
public void run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Doc from java.lang.Thread.run.

This method is run by the thread when it executes. Subclasses of Thread may override this method.

This method is not intended to be invoked directly. If this thread is a platform thread created with a Runnable task then invoking this method will invoke the task's run method. If this thread is a virtual thread then invoking this method directly does nothing.

terminateback to summary
pack-priv void terminate()
org.LatencyUtils back to summary

private Class TimeServices.ScheduledExecutor.RunnableTaskEntry

extends Object
Class Inheritance
  • java.lang.Object
  • org.LatencyUtils.TimeServices.ScheduledExecutor.RunnableTaskEntry

Field Summary

Modifier and TypeField and Description
pack-priv Runnable
pack-priv long
pack-priv boolean
pack-priv long
pack-priv long
pack-priv long

Constructor Summary

AccessConstructor and Description
pack-priv
RunnableTaskEntry(Runnable command, long startTimeNsec, long periodNsec, boolean fixedRate)

Method Summary

Modifier and TypeMethod and Description
public Runnable
public long
public void
setNewStartTime(long timeNow)

pack-priv boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

commandback to summary
pack-priv Runnable command
executionCountback to summary
pack-priv long executionCount
fixedRateback to summary
pack-priv boolean fixedRate
initialStartTimeback to summary
pack-priv long initialStartTime
periodback to summary
pack-priv long period
startTimeback to summary
pack-priv long startTime

Constructor Detail

RunnableTaskEntryback to summary
pack-priv RunnableTaskEntry(Runnable command, long startTimeNsec, long periodNsec, boolean fixedRate)

Method Detail

getCommandback to summary
public Runnable getCommand()
getStartTimeback to summary
public long getStartTime()
setNewStartTimeback to summary
public void setNewStartTime(long timeNow)
shouldRescheduleback to summary
pack-priv boolean shouldReschedule()