|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecthu.mta.sztaki.lpds.cloud.simulator.Timed
public abstract class Timed
This is the base class for the simulation, every class that should receive timing events should extend this and implement the function named "tick". Tick is also used as the smallest discrete increase in time and it is user defined. IMPORTANT: How long an actual tick takes is left for the simulator's user. The simulator expects every time dependent operation and constant to be based on ticks used here. E.g., if you define the outgoing network bandwidth of a networknode then you should set it in bytes/tick. Thus if your tick=ms you must set it in bytes/ms.
Field Summary | |
---|---|
private boolean |
activeSubscription
Determines if the actual timed object is going to receive recurring events (through the tick() function). |
private boolean |
backPreference
Should two timed events occur on the same time instance this marker allows Timed to determine which ones should be notified first. |
private static long |
fireCounter
The actual time in the system. |
private long |
frequency
The number of ticks that should pass between two tick() calls. |
private long |
nextEvent
Specifies the next time (in ticks) when the recurring event should be fired. |
private static PriorityQueue<Timed> |
timedlist
The main container for all recurring events in the system |
private static Timed |
underProcessing
the event that is currently processed by the event loop. |
Constructor Summary | |
---|---|
Timed()
|
Method Summary | |
---|---|
static long |
calcTimeJump(long jump)
A simple approach to calculate time advances in the system |
int |
compareTo(Timed o)
a comparator for timed objects based on next events and back preference (those objects will be specified smaller that have an earlier next event - if nextevents are the same then backpreference decides betwen events) |
static void |
fire()
This function allows the manual operation of the event handling mechanism. |
static long |
getFireCount()
Determines the simulated time that has already passed since the beginning of the simulation (0). |
long |
getFrequency()
Determines the time distance (in ticks) between two tick() calls. |
long |
getNextEvent()
Allows the query of the next event at which the tick() function will be called for this object |
static long |
getNextFire()
Determines the earliest time instance when there is any event in the system to be performed. |
boolean |
isSubscribed()
Allows to determine if a particular timed object is receiving notifications from the system |
static long |
jumpTime(long desiredJump)
Increases the time with a specific amount of ticks. |
long |
nextEventDistance()
Determines the next event at which point this object will receive a tick() call. |
private void |
realSubscribe(long freq)
The actual subscription function that is behind updateFreq or subcribe |
static void |
resetTimed()
Cancels all timed events and sets back the time to 0. |
protected void |
setBackPreference(boolean backPreference)
Enables to set the back preference of a particular timed object. |
static void |
simulateUntil(long time)
Automatically advances the time in the simulation until the specific time instance. |
static void |
simulateUntilLastEvent()
Automatically advances the time in the simulation until there are no events remaining in the event queue. |
static void |
skipEventsTill(long desiredTime)
Jumps the time until the time given by the user. |
protected boolean |
subscribe(long freq)
Allows Timed objects to subscribe for recurring events with a particular frequency. |
abstract void |
tick(long fires)
This function will be called on all timed objects which asked for a recurring event notification at a given time instance. |
String |
toString()
Prints out basic information about this timed object. |
protected boolean |
unsubscribe()
Cancels the future recurrance of this event. |
private void |
updateEvent(long freq)
A core function that actually manages the frequency and nextevent fields. |
protected long |
updateFrequency(long freq)
Allows the alteration of the event frequency independently from subscription. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final PriorityQueue<Timed> timedlist
private static Timed underProcessing
private static long fireCounter
private boolean activeSubscription
private long nextEvent
private long frequency
private boolean backPreference
Constructor Detail |
---|
public Timed()
Method Detail |
---|
public final boolean isSubscribed()
protected final boolean subscribe(long freq)
freq
- the event frequency with which the tick() function should be
called on the particular implementation of timed.
private void realSubscribe(long freq)
freq
- the event frequency with which the tick() function should be
called on the particular implementation of timed.protected final boolean unsubscribe()
protected final long updateFrequency(long freq)
freq
- the event frequency with which the tick() function should be
called on the particular implementation of timed.
private void updateEvent(long freq)
freq
- the event frequency with which the tick() function should be
called on the particular implementation of timed.
IllegalStateException
- if the frequency specified is negative, or if the next event
would be in the indefinite futurepublic long getNextEvent()
public long getFrequency()
public long nextEventDistance()
public int compareTo(Timed o)
compareTo
in interface Comparable<Timed>
protected void setBackPreference(boolean backPreference)
backPreference
- public static final void fire()
public static long calcTimeJump(long jump)
jump
- the time (in ticks) to be advanced with
public static final long jumpTime(long desiredJump)
desiredJump
- the amount of time to be jumped ahead.
public static final void skipEventsTill(long desiredTime)
desiredTime
- the time at which the simulation should continue after this
call. If the time given here already happened then this
function will have no effect.public static final long getFireCount()
public static final long getNextFire()
public static final void simulateUntilLastEvent()
public static final void simulateUntil(long time)
time
- the time instance that should not happen but the time should
advance to this point.public static final void resetTimed()
public String toString()
toString
in class Object
public abstract void tick(long fires)
fires
- The particular time instance when the function was called. The
time instance is passed so the tick functions will not need to
call getFireCount() if they need to operate on the actual
time.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |