public class EventList extends java.lang.Object implements BasicEventList
Replacement for original static Schedule implementation of event
list. Now multiple instances of EventList may exist so that the
same virtual machine can be running multiple independent simulations
simultaneously.
The motivation for switching from the single event list (static) is twofold: (1) Web services typically run in a single virtual machine, and a simulation web service needs to be able to run multiple simulations; (2) The simulation launcher application also could be capable of running multiple simulations in the same virtual machine. This approach also helps protect from rogue models that do bad things to the event list, affecting other running models.
| Modifier and Type | Field and Description |
|---|---|
private SimEvent |
currentSimEvent
The event currently being handled.
|
protected boolean |
DEFAULT_FAST_INTERRUPTS
The default setting for fastInterrupts (TRUE).
|
private boolean |
dumpEventSources
Causes the owner of the event to be included in printouts of the event
list.
|
protected java.util.Map<SimEventScheduler,java.util.SortedSet<SimEvent>> |
entityEventMap
A Map a SimEntity to a SortedSet of its pending SimEvents.
|
protected int |
entryCounter
A count of the number of threads in startSimulation, reset(), and
coldReset().
|
protected java.lang.Object |
entryCounterMutex
An Object used to synchronize access to entryCounter.
|
private java.util.HashMap<java.lang.String,int[]> |
eventCounts
Holds the number of times each type of event has been processed.
|
protected java.util.SortedSet<SimEvent> |
eventList
Holds the pending events.
|
private boolean |
fastInterrupts
If true, then pending SimEvents will be stored in a secondary hash table
to make them easier to find when interrupting.
|
private java.text.DecimalFormat |
form
Holds the default format for outputting times.
|
protected java.util.Map<java.lang.Integer,java.util.SortedSet<SimEvent>> |
hashEventMap
A Map from a SimEvent.getEventHash() (an Integer) to a SortedSet of
pending events.
|
private int |
id
The identifying number of this
EventList instance. |
private java.util.HashSet<java.lang.String> |
ignoreOnDump
List of events that are not dumped in Event List
|
static java.util.logging.Logger |
LOGGER |
private int |
numberStopEvents
The number of times to process the stop event prior to stopping the
simulation.
|
private java.io.PrintStream |
outputStream
PrintStream that dumps will be directed to.
|
private boolean |
pauseAfterEachEvent
If true, will process one event and wait for another call to
startSimulation() |
private double |
precision |
private boolean |
printEventSources |
private boolean |
reallyVerbose
Causes additional debug/trace information to be printed.
|
private java.util.SortedSet<ReRunnable> |
reRun
Holds a list of entities with Run events.
|
private boolean |
running
True if the simulation is currently running.
|
protected double |
simTime
The current simulation time.
|
private boolean |
singleStep
If true the simulation will stop prior to each event and wait for user
input.
|
private boolean |
stopAtTime
If true, stop the simulation at endingTime.
|
private java.lang.String |
stopEventName
The name of the event to stop on after it has been processed numberEvents
times.
|
private SimEntity |
stopInstance
Instance of
Stop if stopAtTime is set. |
private boolean |
stopOnEvent
If true, stop the simulation after the stop event has been processed
numberEvents times.
|
protected boolean |
stoppingSimulation
If true, the event list will be cleared at the start of the next
iteration of the simulation loop in startSimulation().
|
private double |
stopTime
The time to stop the simulation if stopOnTime is true.
|
private boolean |
verbose
If true causes the event list to be printed prior to processing each
event.
|
| Constructor and Description |
|---|
EventList(int id)
Instantiate an
EventList with given id. |
| Modifier and Type | Method and Description |
|---|---|
void |
addIgnoreOnDump(java.lang.String eventName)
Events of this name will not be printed in verbose mode.
|
void |
addRerun(ReRunnable simEntity)
Add the SimEntity to the reRun list.
|
protected boolean |
addToEntityEventMap(SimEvent event)
Adds the given SimEvent to the entity event Map.
|
protected boolean |
addToHashEventMap(SimEvent event)
Adds the given SimEvent to the event hash event Map.
|
protected void |
checkStopEvent()
Stops simulation if the number of stop events have occurred.
|
protected void |
cleanUpHashEventMap(int hash)
Removes the entry for the given hash code if there are no more events.
|
protected void |
clearDeadEvents()
Removes all canceled events from the front of the Event List.
|
protected void |
clearEventList()
Empties event list.
|
void |
clearRerun()
Empty the reRun list
|
void |
coldReset()
Resets instance to pristine condition, as if it were freshly
instantiated.
|
void |
dump()
Dumps current event list to the stream set by
setOutputStream(). |
void |
dump(java.lang.String reason)
Dumps current event list to the stream set by
setOutputStream(). |
SimEvent |
getCurrentSimEvent() |
protected java.util.SortedSet<SimEvent> |
getEventList() |
java.lang.String |
getEventListAsString(java.lang.String reason)
For debugging purposes - returns a String depicting the current event and
state of the event list.
|
int |
getID() |
java.util.Set<java.lang.String> |
getIgnoredEvents()
For debugging purposes - returns a copy of the ignored events
|
int |
getNumberStopEvents() |
java.io.PrintStream |
getOutputStream() |
int |
getPendingEventCount() |
java.util.Set<ReRunnable> |
getRerun()
For debugging purposes - gets a copy of the current reRun list.
|
double |
getSimTime() |
java.lang.String |
getStopEventName() |
double |
getStopTime() |
void |
interrupt(SimEventScheduler simEntity,
java.lang.String eventName)
Cancels an event of the given name originally scheduled from the given
SimEntity.
|
void |
interrupt(SimEventScheduler simEntity,
java.lang.String eventName,
java.lang.Object... parameters)
Cancel next event of given name matching the parameter list owned by the
given SimEntity
|
void |
interruptAll(SimEventScheduler simEntity)
Cancel the all events scheduled by the given scheduler
|
void |
interruptAll(SimEventScheduler simEntity,
java.lang.String eventName)
Cancel all events with the given name which were scheduled by the given
SimEventScheduler regardless of signature.
|
void |
interruptAll(SimEventScheduler simEntity,
java.lang.String eventName,
java.lang.Object... parameters)
Cancel all events with the given name which were scheduled by the given
SimEventScheduler and whos parameters exactly match the given array.
|
void |
interruptAllWithArg(java.lang.Object parameter)
Interrupt all events having this parameter in its argument list,
regardless of event name and who scheduled it.
|
void |
interruptAllWithArg(SimEventScheduler simEntity,
java.lang.Object parameter)
Interrupt all events scheduled by this simEntity containing at least one
of the given parameter in its arguments.
|
void |
interruptAllWithArg(SimEventScheduler simEntity,
java.lang.String eventName,
java.lang.Object parameter)
Interrupt all events scheduled by this simEntity having the given
eventName and containing at least one of the given parameter in its
arguments.
|
void |
interruptAllWithArg(java.lang.String eventName,
java.lang.Object parameter)
Interrupt all events of the given eventName and having an instance of the
parameter in its arguments regardless of who scheduled it.
|
boolean |
isDumpEventSources() |
boolean |
isFastInterrupts()
If true, then pending SimEvents will be stored in a secondary hash table
to make them easier to find when interrupting.
|
boolean |
isFinished() |
boolean |
isPauseAfterEachEvent() |
boolean |
isPrintEventSources() |
boolean |
isReallyVerbose() |
boolean |
isRunning() |
boolean |
isSingleStep() |
boolean |
isStopAtTime() |
boolean |
isStopOnEvent() |
boolean |
isVerbose() |
void |
pause()
Cause pending event processing to stop after completing processing of the
current event.
|
protected boolean |
removeFromEntityEventMap(SimEvent event)
Removes the given SimEvent from the entity event Map.
|
protected boolean |
removeFromHashEventMap(SimEvent event)
Removes the given SimEvent from the hash event Map.
|
void |
removeIgnoreOnDump(java.lang.String eventName)
Events of this name now will be printed in verbose mode.
|
protected void |
removeListeners(java.lang.Object se)
Removes all SimEventListeners and PropertyChangelisteners from the given
SimEntity |
void |
removeRerun(ReRunnable simEntity)
Remove the given SimEntity from the reRun list
|
void |
reset()
Performs the following:
Empties the event list
Sets simulation time to 0.0
Invokes
reset() on each persistent
SimEntity in reRun
Removes all listeners for every transient SimEntity in
reRun. |
void |
scheduleEvent(SimEvent event)
Place an event on the event list.
|
void |
setDumpEventSources(boolean b)
If true, then the SimEntity toString() is dumped with verbose mode for
each event.
|
void |
setFastInterrupts(boolean value)
If true, then pending SimEvents will be stored in a secondary hash table
to make them easier to find when interrupting (defaults to true).
|
void |
setFormat(java.lang.String format) |
void |
setOutputStream(java.io.PrintStream outputStream) |
void |
setPauseAfterEachEvent(boolean b)
If true, then simulation will pause after each event and resume only on
another call to
startSimulation() |
void |
setPrintEventSources(boolean b) |
void |
setReallyVerbose(boolean b)
For debugging, gives more detailed output
|
void |
setSingleStep(boolean b) |
void |
setUserDefinedStop()
Sets all stop modes to false.
|
void |
setVerbose(boolean b)
If true, then contents of the event list are printed after each event is
processed.
|
void |
startSimulation()
Starts event list algorithm.
|
void |
step()
Processed events one at a time based on user input from the console.
|
void |
stopAtTime(double time)
Sets the stopAtTime mode to true, setting others to false.
|
void |
stopOnEvent(int numberEvents,
java.lang.String eventName,
java.lang.Class<?>... signature)
Cause event processing to stop when the given number of events with this
signature have occurred.
|
void |
stopSimulation()
Stop processing pending events.
|
protected void |
updateEventCounts(SimEvent event)
Adds one to the number of this event that have occurred.
|
public static final java.util.logging.Logger LOGGER
protected boolean DEFAULT_FAST_INTERRUPTS
protected final java.util.SortedSet<SimEvent> eventList
protected double simTime
private SimEvent currentSimEvent
private final java.util.HashMap<java.lang.String,int[]> eventCounts
private boolean verbose
private boolean reallyVerbose
private boolean singleStep
private boolean dumpEventSources
private final java.util.SortedSet<ReRunnable> reRun
private java.lang.String stopEventName
private int numberStopEvents
private boolean stopOnEvent
private boolean stopAtTime
private double stopTime
private boolean running
private SimEntity stopInstance
Stop if stopAtTime is set.private final java.util.HashSet<java.lang.String> ignoreOnDump
private final int id
EventList instance. It is the
responsibility of Schedule to ensure uniqueness across
EventList instances.private java.io.PrintStream outputStream
private java.text.DecimalFormat form
private boolean printEventSources
private final double precision
private boolean pauseAfterEachEvent
startSimulation()private boolean fastInterrupts
protected java.util.Map<SimEventScheduler,java.util.SortedSet<SimEvent>> entityEventMap
protected java.util.Map<java.lang.Integer,java.util.SortedSet<SimEvent>> hashEventMap
protected int entryCounter
protected final java.lang.Object entryCounterMutex
protected boolean stoppingSimulation
public EventList(int id)
EventList with given id.id - The id number for this EventGraph instancepublic int getPendingEventCount()
public int getID()
getID in interface BasicEventListpublic double getSimTime()
getSimTime in interface BasicEventListpublic void setVerbose(boolean b)
BasicEventListsetVerbose in interface BasicEventListb - whether verbose mode is onpublic boolean isVerbose()
isVerbose in interface BasicEventListpublic void setReallyVerbose(boolean b)
BasicEventListsetReallyVerbose in interface BasicEventListb - Whether reallyVerbose is onpublic boolean isReallyVerbose()
isReallyVerbose in interface BasicEventListpublic void setPrintEventSources(boolean b)
setPrintEventSources in interface BasicEventListb - Whether the event source is printed on a dump()public boolean isPrintEventSources()
isPrintEventSources in interface BasicEventListpublic void setSingleStep(boolean b)
setSingleStep in interface BasicEventListb - Whether single step mode is onpublic boolean isSingleStep()
isSingleStep in interface BasicEventListpublic void setDumpEventSources(boolean b)
BasicEventListsetDumpEventSources in interface BasicEventListb - Whether this mode is onpublic boolean isDumpEventSources()
isDumpEventSources in interface BasicEventListpublic boolean isStopOnEvent()
isStopOnEvent in interface BasicEventListpublic void setFormat(java.lang.String format)
setFormat in interface BasicEventListformat - String for DecimalFormat of time stringspublic int getNumberStopEvents()
getNumberStopEvents in interface BasicEventListpublic boolean isStopAtTime()
isStopAtTime in interface BasicEventListpublic double getStopTime()
getStopTime in interface BasicEventListstopAtTime is setpublic boolean isRunning()
isRunning in interface BasicEventListpublic java.lang.String getStopEventName()
getStopEventName in interface BasicEventListpublic boolean isFinished()
isFinished in interface BasicEventListpublic SimEvent getCurrentSimEvent()
getCurrentSimEvent in interface BasicEventListpublic void setPauseAfterEachEvent(boolean b)
BasicEventListstartSimulation()setPauseAfterEachEvent in interface BasicEventListb - Whether this mode is onpublic boolean isPauseAfterEachEvent()
isPauseAfterEachEvent in interface BasicEventListpublic void reset()
reset() on each persistent
SimEntity in reRunSimEntity in
reRun.
reset in interface BasicEventListprotected void removeListeners(java.lang.Object se)
SimEntityse - The SimEntity for which listeners are to be
removedprotected void clearEventList()
protected void clearDeadEvents()
public void stopAtTime(double time)
stopAtTime in interface BasicEventListtime - Time to stop simulationpublic void stopOnEvent(int numberEvents,
java.lang.String eventName,
java.lang.Class<?>... signature)
BasicEventListCalling this method should cause any other stop method previously called to be ineffective. That is, the last stop_xxx method invoked should be the definitive one.
stopOnEvent in interface BasicEventListnumberEvents - Number of events to occureventName - Name of stop eventsignature - Signature of stop eventpublic void setUserDefinedStop()
setUserDefinedStop in interface BasicEventListpublic void scheduleEvent(SimEvent event) throws InvalidSchedulingException
BasicEventListscheduleEvent in interface BasicEventListevent - Event to be scheduledInvalidSchedulingException - If scheduled time is less than current
simTime.public void startSimulation()
BasicEventListhandleSimEvent method. Then have the owner
of the event notify its listeners of the event.startSimulation in interface BasicEventListpublic void step()
step in interface BasicEventListpublic void dump(java.lang.String reason)
BasicEventListsetOutputStream().dump in interface BasicEventListreason - Short message to add to dumppublic void dump()
BasicEventListsetOutputStream().dump in interface BasicEventListprotected void updateEventCounts(SimEvent event)
stopOnEvent This method is not synchronized since it is only
called from startSimulation(), which is protected from being entered
multiple times.event - event to update countsprotected void checkStopEvent()
public void pause()
BasicEventList
It is legal to subsequently call step or startSimulation.
isRunning will return false after this is called.
pause in interface BasicEventListpublic void stopSimulation()
BasicEventList
Unlike pause resumption of the simulation is not supported. After
this call there is no guarantee that previously pending events or any
other external references will remain accessable. It is not legal to
subsequently call startSimulation or step
stopSimulation in interface BasicEventListpublic void interrupt(SimEventScheduler simEntity, java.lang.String eventName)
interrupt in interface BasicEventListsimEntity - Given SimEntity that originally scheduled the eventeventName - Name of the eventpublic void interrupt(SimEventScheduler simEntity, java.lang.String eventName, java.lang.Object... parameters)
BasicEventListinterrupt in interface BasicEventListsimEntity - SimEventScheduler to have event cancelledeventName - Name of event to cancelparameters - edge parameters of cancelled eventpublic void interruptAll(SimEventScheduler simEntity)
BasicEventListinterruptAll in interface BasicEventListsimEntity - SimEventScheduler whose events will be interrupted.public void interruptAll(SimEventScheduler simEntity, java.lang.String eventName)
BasicEventListinterruptAll in interface BasicEventListsimEntity - SimEntity to have event cancelledeventName - Name of eventpublic void interruptAll(SimEventScheduler simEntity, java.lang.String eventName, java.lang.Object... parameters)
BasicEventListinterruptAll in interface BasicEventListsimEntity - SimEntity to have event cancelledeventName - Name of event to cancelparameters - edge parameters that must matchpublic void addRerun(ReRunnable simEntity)
BasicEventListBasicEventList.reset
the SimEntity's reset() method is invoked and its Run event
(if it has one) is scheduled at time 0.0. This happens only if the
SimEntity is persistant.addRerun in interface BasicEventListsimEntity - SimEntity to be added as a reRunpublic void removeRerun(ReRunnable simEntity)
BasicEventListremoveRerun in interface BasicEventListsimEntity - SimEntity to be removed from reRun listpublic void clearRerun()
BasicEventListclearRerun in interface BasicEventListpublic java.util.Set<ReRunnable> getRerun()
BasicEventListgetRerun in interface BasicEventListpublic void addIgnoreOnDump(java.lang.String eventName)
BasicEventListaddIgnoreOnDump in interface BasicEventListeventName - Name of event to be ignoredpublic void removeIgnoreOnDump(java.lang.String eventName)
BasicEventListremoveIgnoreOnDump in interface BasicEventListeventName - Event Namepublic java.util.Set<java.lang.String> getIgnoredEvents()
BasicEventListgetIgnoredEvents in interface BasicEventListpublic void coldReset()
BasicEventListfalse).coldReset in interface BasicEventListpublic java.lang.String getEventListAsString(java.lang.String reason)
BasicEventListgetEventListAsString in interface BasicEventListreason - User message to be appended to event listprotected java.util.SortedSet<SimEvent> getEventList()
public boolean isFastInterrupts()
public void setFastInterrupts(boolean value)
setFastInterrupts in interface BasicEventListvalue - If true, then pending SimEvents will be stored in a
secondary hash table to make them easier to find when interrupting
(defaults to true).protected boolean addToEntityEventMap(SimEvent event)
event - Given SimEventprotected boolean removeFromEntityEventMap(SimEvent event)
event - Given SimEventprotected boolean addToHashEventMap(SimEvent event)
event - Given SimEventprotected boolean removeFromHashEventMap(SimEvent event)
event - Given SimEventprotected void cleanUpHashEventMap(int hash)
hash - given hash codepublic java.io.PrintStream getOutputStream()
getOutputStream in interface BasicEventListpublic void setOutputStream(java.io.PrintStream outputStream)
setOutputStream in interface BasicEventListpublic void interruptAllWithArg(SimEventScheduler simEntity, java.lang.String eventName, java.lang.Object parameter)
BasicEventListinterruptAllWithArg in interface BasicEventListsimEntity - Scheduling SimEntityeventName - Name of events to be canceledparameter - argument to be matchedpublic void interruptAllWithArg(SimEventScheduler simEntity, java.lang.Object parameter)
BasicEventListinterruptAllWithArg in interface BasicEventListsimEntity - Scheduling SimEntityparameter - argument to be matchedpublic void interruptAllWithArg(java.lang.String eventName,
java.lang.Object parameter)
BasicEventListinterruptAllWithArg in interface BasicEventListeventName - Name of events to be canceledparameter - argument to be matchedpublic void interruptAllWithArg(java.lang.Object parameter)
BasicEventListinterruptAllWithArg in interface BasicEventListparameter - argument to be matched