public abstract class Calendar
extends java.lang.Object
Calendar
. The classes store references to callback methods (
CalendarCallback
) and associated points in time (PointInTime
)
when the callbacks are to be executed.
In addition to the event time, a priority of the event can be provided. These priorities come into effect if events are scheduled to be executed at the same time. In that case, they are processed in the order of decreasing priority, i.e., the event with the highest priority is processed first.
When posting an event, the calendar returns an instance of EventToken
, which can be used to query the state of the event and to cancel the event.
With the method processNextEvent()
the events can be executed in the
scheduled order. Calendars are used by models, see
Model
for more details.
Event priorities are integer numbers and may be negative. The default priority is 0. The processing order of events with the same time and the same priority is not defined and may vary in-between calendar implementations.
Modifier and Type | Field and Description |
---|---|
protected static Calendar |
CALENDAR
reference to calendar
|
protected int |
concurrentEvents
counter to count the number of events with exact same time stamp
|
protected UnweightedSampleCollector<java.lang.Double> |
eventsWithSameTimeStat |
protected PointInTime |
systemTime
the current simulation time
|
Modifier | Constructor and Description |
---|---|
protected |
Calendar() |
Modifier and Type | Method and Description |
---|---|
abstract void |
cancelAllEvents()
Cancel all events which are currently posted.
|
static Calendar |
getInstance()
calendar access method
|
PointInTime |
getSystemTime()
Returns the current simulation time
|
static boolean |
hasInstance() |
abstract boolean |
isEventAvailable()
Return true if there are events in the calendar.
|
abstract PointInTime |
peekNextEventTime()
Returns the time stamp of the next event in the calendar without removing
it.
|
EventToken |
postEvent(CalendarCallback onExecute,
CalendarCallback onCancel,
PointInTime eventTime)
As
postEvent(CalendarCallback, CalendarCallback, PointInTime, int) ,
but sets the eventPriority to 0. |
abstract EventToken |
postEvent(CalendarCallback onExecute,
CalendarCallback onCancel,
PointInTime eventTime,
int eventPriority)
Creates a new entry in the calendar.
|
abstract void |
processNextEvent()
Gets the next event on the schedule and calls its onExecute method.
|
static void |
setInstance(Calendar calendar) |
void |
setSameTimeEventStatistic(UnweightedSampleCollector<java.lang.Double> collector)
If set, the number of events with the exact same time stamp are collected
in the given
UnweightedSampleCollector . |
protected static Calendar CALENDAR
protected PointInTime systemTime
protected UnweightedSampleCollector<java.lang.Double> eventsWithSameTimeStat
protected int concurrentEvents
public static Calendar getInstance()
public static void setInstance(Calendar calendar)
public static boolean hasInstance()
public abstract EventToken postEvent(CalendarCallback onExecute, CalendarCallback onCancel, PointInTime eventTime, int eventPriority)
onExecute
- Function to call when the event is processed. May be null.onCancel
- Function to call when the event is cancelled. May be null.eventTime
- Time at which to call the onExecute
function. Must
be later or equal than the current system time returned by
getSystemTime()
.eventPriority
- Key used for sorting to break ties for two entries with the same
eventTime
.public EventToken postEvent(CalendarCallback onExecute, CalendarCallback onCancel, PointInTime eventTime)
postEvent(CalendarCallback, CalendarCallback, PointInTime, int)
,
but sets the eventPriority
to 0.public abstract void cancelAllEvents()
public abstract boolean isEventAvailable()
public abstract PointInTime peekNextEventTime()
public PointInTime getSystemTime()
public abstract void processNextEvent()
public void setSameTimeEventStatistic(UnweightedSampleCollector<java.lang.Double> collector)
UnweightedSampleCollector
. The number of events with
same time stamp