javax.realtime
Class RationalTime

java.lang.Object
  |
  +--javax.realtime.HighResolutionTime
        |
        +--javax.realtime.RelativeTime
              |
              +--javax.realtime.RationalTime

public class RationalTime
extends RelativeTime

An object that represents a time interval millis/1E3+nanos/1E9 seconds long that is divided into subintervals by some frequency. This is generally used in periodic events, threads, and feasibility analysis to specify periods where there is a basic period that must be adhered to strictly (the interval), but within that interval the periodic events are supposed to happen frequency times, as uniformly spaced as possible, but clock and scheduling jitter is moderately acceptable. Caution: This class is explicitly unsafe in multithreaded situations when it is being changed. No synchronization is done. It is assumed that users of this class who are mutating instances will be doing their own synchronization at a higher level. All Implemented Interfaces: java.lang.Comparable


Constructor Summary
RationalTime(int frequency)
          Construct a new Object of RationalTime Equivalent to new RationalTime(1000, 0, frequency) -- essentially a cycles -per-second value
RationalTime(int frequency, long millis, int nanos)
          Construct a new Object of RationalTime.
RationalTime(int frequency, RelativeTime interval)
          Construct a new Object of RationalTime from the given RelativeTime
 
Method Summary
 AbsoluteTime absolute(Clock clock)
           
 AbsoluteTime absolute(Clock clock, AbsoluteTime destination)
          Convert this time to an absolute time.
 void addInterarrivalTo(AbsoluteTime destination)
          Add this time to an AbsoluteTime.
 int getFrequency()
           
 RelativeTime getInterarrivalTime()
          Gets the time duration between two consecutive ticks using frequency
 RelativeTime getInterarrivalTime(RelativeTime dest)
          Gets the time duration between two consecutive ticks using frequency
 RelativeTime relative(Clock clock)
           
 RelativeTime relative(Clock clock, RelativeTime destination)
           
 void set(long millis, int nanos)
          Change the indicated interval of this to the sum of the values of the arguments
 void setFrequency(int frequency)
          set the frequency of this
 
Methods inherited from class javax.realtime.RelativeTime
add, add, add, add, subtract, subtract, toString
 
Methods inherited from class javax.realtime.HighResolutionTime
compareTo, compareTo, equals, equals, getMilliseconds, getNanoseconds, hashCode, set, set, waitForObject
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RationalTime

public RationalTime(int frequency)
Construct a new Object of RationalTime Equivalent to new RationalTime(1000, 0, frequency) -- essentially a cycles -per-second value

RationalTime

public RationalTime(int frequency,
                    long millis,
                    int nanos)
             throws java.lang.IllegalArgumentException
Construct a new Object of RationalTime. All arguments must be >= 0.
Parameters:
frequency - The frequency value of this
millis - The milliseonds value of this
nanos - The nanoseconds value of this

RationalTime

public RationalTime(int frequency,
                    RelativeTime interval)
             throws java.lang.IllegalArgumentException
Construct a new Object of RationalTime from the given RelativeTime
Parameters:
frequency - The frequency value of this
interval - The relativeTime object used as the source for the copy
Method Detail

absolute

public AbsoluteTime absolute(Clock clock,
                             AbsoluteTime destination)
Convert this time to an absolute time. For a RelativeTime, this invovled adding the clocks notion of now to this interval and constructing a new AbsoluteTime based on the sum
Overrides:
absolute in class RelativeTime
Parameters:
clock - if null, Clock.getRealTimeClock() is used
destination -  

absolute

public AbsoluteTime absolute(Clock clock)
Overrides:
absolute in class RelativeTime

addInterarrivalTo

public void addInterarrivalTo(AbsoluteTime destination)
Add this time to an AbsoluteTime. It is almost the same dest.add(this, dest) except that it accounts for(ie. divides by) the frequency.
Overrides:
addInterarrivalTo in class RelativeTime
Parameters:
dest -  

getFrequency

public int getFrequency()

getInterarrivalTime

public RelativeTime getInterarrivalTime(RelativeTime dest)
Gets the time duration between two consecutive ticks using frequency
Overrides:
getInterarrivalTime in class RelativeTime
Parameters:
dest - Result is stored in dest and returned, if null new object is returned.

getInterarrivalTime

public RelativeTime getInterarrivalTime()
Gets the time duration between two consecutive ticks using frequency

set

public void set(long millis,
                int nanos)
         throws java.lang.IllegalArgumentException
Change the indicated interval of this to the sum of the values of the arguments
Overrides:
set in class HighResolutionTime
Parameters:
millis - Millisecond part
nanos - Nanosecond part

setFrequency

public void setFrequency(int frequency)
                  throws java.lang.ArithmeticException
set the frequency of this
Parameters:
f - the frequency to be set for this

relative

public RelativeTime relative(Clock clock)
Overrides:
relative in class RelativeTime

relative

public RelativeTime relative(Clock clock,
                             RelativeTime destination)
Overrides:
relative in class RelativeTime