se.lth.cs.realtime.event
Class RTEvent

java.lang.Object
  |
  +--java.util.EventObject
        |
        +--se.lth.cs.realtime.event.RTEvent
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
PeriodicEvent, RTThreadEvent

public abstract class RTEvent
extends java.util.EventObject

The base class of real-time, i.e. time-stamped, events. Every RTEvent comes from a source object referred to in the EventObject base class. Additional IDs, such as sequential numbers or the kind of event within a certain type, are expected to be defined in subclasses together with other user attributes. The time stamp is, however, fundamental to real-time systems as a mean to denote the freshness of the data. It is therefore an attribute here and the motivation for this class.

The source object, often run in another thread, is not supposed to keep any reference to the event after posting it, thus methods of this class should not need to be synchronized.

There is a ticker attribute referring to a time-base, which can be given to the constructor. This is for special computers or special applications; if you do not know that you need it, simply ignore it and the default System.currentTimeMillis() will be used as the actual ticker. However, obtaining the time via getMillis or getSeconds will make your code portable to such special applications.

See Also:
Serialized Form

Field Summary
protected  Timebase ticker
          The time-base relating number of ticks to real time.
protected  long timestamp
          The time stamp of this event, in number of (system dependent) ticks.
 
Fields inherited from class java.util.EventObject
source
 
Constructor Summary
RTEvent()
          Constructs an RTEvent object with the current thread as source and a timestamp from the current system time.
RTEvent(long ts)
          Constructs an RTEvent object with the current thread as source and with the specified time stamp.
RTEvent(java.lang.Object source)
          Constructs an RTEvent object with the specified source object and a timestamp from the current system time.
RTEvent(java.lang.Object source, long ts)
          Constructs an RTEvent object with the specified source object and time stamp.
RTEvent(java.lang.Object source, long ts, Timebase timebase)
          Constructs an RTEvent object with the specified source object and time-stamp with respect to the specified time-base.
 
Method Summary
 long getMillis()
          Returns the event's time stamp in number of milli-seconds.
 long getNanos()
          Return the sub-milli part of the time-stamp, if any.
 double getSeconds()
          Returns the creation-time (or supplied time-stamp= of this event.
 long getTicks()
          Returns the event's time stamp.
 Timebase getTimebase()
          Obtains the time-base relating (possibly locally counted) ticks or seconds to real time.
protected  java.lang.String paramString()
          Return a string representation of the attributes/state of this object.
 java.lang.String toString()
          Gives a string representation of the event object.
 
Methods inherited from class java.util.EventObject
getSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

timestamp

protected long timestamp
The time stamp of this event, in number of (system dependent) ticks.

ticker

protected Timebase ticker
The time-base relating number of ticks to real time.
Constructor Detail

RTEvent

public RTEvent()
Constructs an RTEvent object with the current thread as source and a timestamp from the current system time.

RTEvent

public RTEvent(java.lang.Object source)
Constructs an RTEvent object with the specified source object and a timestamp from the current system time.
Parameters:
source - The object where the event originated.

RTEvent

public RTEvent(long ts)
Constructs an RTEvent object with the current thread as source and with the specified time stamp.
Parameters:
ts - The time from which the event originates.

RTEvent

public RTEvent(java.lang.Object source,
               long ts)
Constructs an RTEvent object with the specified source object and time stamp.
Parameters:
source - The object where the event originated.
ts - The time from which the event originates.

RTEvent

public RTEvent(java.lang.Object source,
               long ts,
               Timebase timebase)
Constructs an RTEvent object with the specified source object and time-stamp with respect to the specified time-base.
Parameters:
source - The object where the event originated.
ts - The time from which the event originates.
Method Detail

getTicks

public long getTicks()
Returns the event's time stamp. Use the other get-time methods to make the management of time portable, e.g. getSeconds().
Returns:
the time in number of (system dependent) ticks.

getSeconds

public double getSeconds()
Returns the creation-time (or supplied time-stamp= of this event.
Returns:
the time-stamp expressed in seconds.

getMillis

public long getMillis()
Returns the event's time stamp in number of milli-seconds. The returned value is compliant with System.currentTimeMillis().
Returns:
the time-stamp expressed in milli-seconds.

getNanos

public long getNanos()
Return the sub-milli part of the time-stamp, if any. If permitted by numerical accuracy, using getSeconds usually is a better alternative when working with times that contain fractions of milli-seconds.
Returns:
any nano-second part of time-stamp.

getTimebase

public Timebase getTimebase()
Obtains the time-base relating (possibly locally counted) ticks or seconds to real time.
Returns:
the time-base, or null if System.currentTimeMillis is used.

toString

public java.lang.String toString()
Gives a string representation of the event object.

The string is of the form:

ClassName[paramString]

where ClassName is the name of the event class, paramString is the string returned by paramString.

Overrides:
toString in class java.util.EventObject

paramString

protected java.lang.String paramString()
Return a string representation of the attributes/state of this object. Useful for debugging puposes via toString. Subclasses may simply use super.paramString and add its additional attributes.