|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--cz.zcu.fav.kiv.jsim.JSimSimulation
The JSimSimulation class instances represent theoretical simulation models, containing processes, queues, and other elements. Every process and queue must have a simulation specified as a constructor parameter, otherwise the creation will not be successful. To the user, the JSimSimulation class provides the step() method -- execution of one simulation step. Alternatively, the runGUI() method can be used, causing the simulation to run in graphic mode.
Field Summary | |
protected JSimCalendar |
calendar
The simulation's calendar of events. |
private boolean |
firstStepExecuted
Flag saying that the first step of simulation has been executed. |
private java.lang.Object |
graphicLock
Lock used when switching between the simulation and its main GUI window. |
private JSimChange |
guiUpdate
Observable object notifying the GUI about possible changes. |
private static boolean |
guiUsed
Flag saying that graphic mode has been used. |
private double |
lastGUIUpdate
Last GUI update time. |
private JSimMainWindow |
mainWindow
The simulation's main window. |
private int |
mode
The simulation's mode -- text, GUI batch, GUI interactive. |
static int |
MODE_GUI_BATCH
|
static int |
MODE_GUI_INTERACTIVE
|
static int |
MODE_TXT
|
private java.lang.String |
myName
The simulation's name. |
private int |
myNumber
The simulation's number. |
static long |
NEW_PROCESS_FORBIDDEN
|
static long |
NEW_QUEUE_FORBIDDEN
|
static long |
NEW_SEMAPHORE_FORBIDDEN
|
private long |
newProcessNumber
Number for a newly created process. |
private long |
newQueueNumber
Number for a newly created queue. |
private long |
newSemaphoreNumber
Number for a newly created semaphore. |
private double |
nextGUIUpdateDelta
GUI update delta. |
private static int |
noOfSimulations
Number of simulations created in this JVM instance. |
private java.util.SortedSet |
notStartedProcesses
A set containing processes created during last step and not started yet. |
private long |
numberOfProcesses
Number of processes currently present within the simulation. |
private long |
numberOfQueues
Number of queues currently present within the simulation. |
private long |
numberOfSemaphores
Number of semaphores currently present within the simulation. |
static int |
PRN_ERROR
|
static int |
PRN_MESSAGE
|
private java.util.SortedSet |
processes
All processes of the simulation. |
private java.util.SortedSet |
processesForGUI
All processes that have ever existed in the simulation. |
private java.util.SortedSet |
queues
All queues of the simulation. |
private JSimProcess |
runningProcess
The currently running process. |
private java.util.SortedSet |
semaphores
All semaphores of the simulation. |
static int |
SIMULATION_IN_PROGRESS
|
static int |
SIMULATION_NOT_STARTED
|
static int |
SIMULATION_TERMINATED
|
private int |
simulationState
The simulation's state -- not started, in progress, terminated. |
private java.lang.Object |
stepLock
Lock used to synchronize (possible) concurrent calls to step(). |
private boolean |
talking
Flag saying that talking (=logging) is switched on. |
private java.io.PrintStream |
talkStream
Stream that the simulation talks to. |
protected double |
time
The simulation's current time. |
private java.lang.Object |
waitForWindowClosureLock
Lock used when the simulation waits in waitForWindowClosure(). |
private boolean |
waitingForWindowClosure
Flag saying that the simulation is just now waiting in waitForWindowClosure(). |
private boolean |
windowOpen
Flag saying that the main window is open. |
Constructor Summary | |
JSimSimulation(java.lang.String name)
Creates a new simulation with no processes, no queues and no graphic window. |
|
JSimSimulation(java.lang.String name,
int mode)
Creates a new simulation with no processes, no queues and no graphic window. |
|
JSimSimulation(java.lang.String name,
int mode,
double guiUpdateDelta)
Creates a new simulation with no processes, no queues and no graphic window. |
Method Summary | |
protected void |
addEntryToCalendar(double absoluteTime,
JSimProcess process)
Adds a new event to the calendar, with the specified absolute time and the specified process. |
protected void |
addProcess(JSimProcess process)
Adds a new process to the simulation. |
protected void |
addQueue(JSimHead queue)
Adds a new queue to the simulation. |
void |
addSemaphore(JSimSemaphore semaphore)
Adds a new semaphore to the simulation. |
private void |
deleteAllProcesses()
Deletes all processes from the simulation. |
protected int |
deleteEntriesInCalendar(JSimProcess process,
boolean all)
Deletes one or more entries in the calendar, concerning a process. |
protected void |
deleteProcess(JSimProcess process)
Deletes a process from the simulation. |
void |
error(java.lang.String s)
Prints out a text error message, either to the error output or to the simulation window. |
double |
getCurrentTime()
Returns the simulation's current time. |
long |
getFreeProcessNumber()
Returns a unique number that can be assigned to a newly created process. |
long |
getFreeQueueNumber()
Returns a unique number that can be assigned to a newly created queue. |
long |
getFreeSemaphoreNumber()
Returns a unique number that can be assigned to a newly created semaphore. |
java.lang.Object |
getGraphicLock()
Returns the lock object used for synchronization between the simulation and its GUI window. |
JSimChange |
getChange()
Returns an observable object notifying the GUI about possible changes. |
java.lang.String |
getName()
Returns the simulation's name. |
int |
getNumber()
Returns the simulation's unique number. |
long |
getNumberOfProcesses()
Returns the number of processes present within the simulation. |
long |
getNumberOfQueues()
Returns the number of queues present within the simulation. |
long |
getNumberOfSemaphores()
Returns the number of semaphores present within the simulation. |
java.util.SortedSet |
getObjectsToBeDisplayed(int elementType)
Returns a set containing information about simulation elements that are to be displayed in the GUI. |
JSimProcess |
getRunningProcess()
Returns the currently running process. |
int |
getSimulationMode()
Returns the simulation's mode. |
int |
getSimulationState()
Returns the simulation's state. |
java.lang.Object |
getStepLock()
Returns the lock object that protects the step() method from being invoked in parallel. |
boolean |
getTalking()
Returns true if talking is on, otherwise returns false. |
java.io.PrintStream |
getTalkStream()
Returns the talk stream where talking is directed to. |
boolean |
getWaitingForWindowClosure()
Returns true if the simulation is waiting in waitForWindowClosure(). |
java.lang.Object |
getWindowClosureLock()
Returns the lock object used for synchronization between the simulation and its GUI window, while waiting in waitForWindowClosure(). |
java.io.PrintStream |
changeTalkStream(java.io.PrintStream newStream)
Changes the talk stream where talking is directed to. |
boolean |
isRunningGUI()
Returns true if the simulation is running in a GUI window. |
void |
message(java.lang.String s)
Prints out a text message, either to the standard output or to the simulation window. |
void |
messageNoNL(java.lang.String s)
Prints out a text message, either to the standard output or to the simulation window, but does not terminate the line. |
void |
printString(java.lang.String s,
int code,
boolean newLine)
Prints a standard message or an error message. |
private boolean |
runBatchGUI()
Opens a graphic window for GUI batch mode and keeps it open. |
boolean |
runGUI()
Opens a graphic window and lets the user control the simulation's execution using this window. |
void |
setTalking(boolean yesOrNo)
Switches talking on/off. |
void |
shutdown()
Shutdowns the simulation by interrupting all living processes. |
private boolean |
startNewProcesses()
Starts all new processes. |
boolean |
step()
Executes one simulation step. |
protected void |
switchToNobody()
Switches the execution to the main thread. |
void |
talk(boolean x)
Prints a boolean value to the stream used for talking, if talking is set on. |
void |
talk(double x)
Prints a double value to the stream used for talking, if talking is set on. |
void |
talk(float x)
Prints a float value to the stream used for talking, if talking is set on. |
void |
talk(char x)
Prints a char value to the stream used for talking, if talking is set on. |
void |
talk(char[] x)
Prints an array of chars to the stream used for talking, if talking is set on. |
void |
talk(int x)
Prints an int value to the stream used for talking, if talking is set on. |
void |
talk(long x)
Prints a long value to the stream used for talking, if talking is set on. |
void |
talk(java.lang.Object x)
Prints an object to the stream used for talking, if talking is set on. |
void |
talk(java.lang.String x)
Prints a string to the stream used for talking, if talking is set on. |
void |
waitForWindowClosure()
Suspends the calling thread until the `Quit' button of the main window is pressed. |
void |
windowIsClosing(JSimMainWindow caller)
The simulation is informed about the main window's closure. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int MODE_TXT
public static final int MODE_GUI_BATCH
public static final int MODE_GUI_INTERACTIVE
public static final int SIMULATION_NOT_STARTED
public static final int SIMULATION_IN_PROGRESS
public static final int SIMULATION_TERMINATED
public static final int PRN_MESSAGE
public static final int PRN_ERROR
public static final long NEW_PROCESS_FORBIDDEN
public static final long NEW_QUEUE_FORBIDDEN
public static final long NEW_SEMAPHORE_FORBIDDEN
private final int myNumber
private final java.lang.String myName
private final int mode
private long numberOfProcesses
private long numberOfQueues
private long numberOfSemaphores
private JSimProcess runningProcess
private long newProcessNumber
private long newQueueNumber
private long newSemaphoreNumber
protected JSimCalendar calendar
protected double time
private int simulationState
private java.util.SortedSet processes
private java.util.SortedSet processesForGUI
private java.util.SortedSet queues
private java.util.SortedSet semaphores
private java.util.SortedSet notStartedProcesses
private final java.lang.Object graphicLock
private final java.lang.Object stepLock
private final java.lang.Object waitForWindowClosureLock
private boolean talking
private java.io.PrintStream talkStream
private JSimMainWindow mainWindow
private boolean windowOpen
private boolean waitingForWindowClosure
private boolean firstStepExecuted
private JSimChange guiUpdate
private double nextGUIUpdateDelta
private double lastGUIUpdate
private static boolean guiUsed
private static int noOfSimulations
Constructor Detail |
public JSimSimulation(java.lang.String name) throws JSimInvalidParametersException
name
- Name of the simulation.
JSimInvalidParametersException
- This exception is thrown out if the specified name is
is null.public JSimSimulation(java.lang.String name, int mode) throws JSimInvalidParametersException
name
- Name of the simulation.mode
- Simulation mode. Possible values are MODE_TXT, MODE_GUI_BATCH,
and MODE_GUI_INTERACTIVE.
JSimInvalidParametersException
- This exception is thrown out if the specified name is
is null or an invalid simulation mode is given to the
constructor.public JSimSimulation(java.lang.String name, int mode, double guiUpdateDelta) throws JSimInvalidParametersException
name
- Name of the simulation.mode
- Simulation mode. Possible values are MODE_TXT, MODE_GUI_BATCH,
and MODE_GUI_INTERACTIVE.
JSimInvalidParametersException
- This exception is thrown out if the specified name is
is null, an invalid simulation mode is given to the
constructor, or if the update interval is less than zero.Method Detail |
protected final void addProcess(JSimProcess process) throws JSimInvalidParametersException
process
- The process that has to be added to the simulation.
JSimInvalidParametersException
- This exception is thrown out if the specified process
is null.protected final void addQueue(JSimHead queue) throws JSimInvalidParametersException
queue
- The queue that has to be added to the simulation.
JSimInvalidParametersException
- This exception is thrown out if the specified queue
is null.public final void addSemaphore(JSimSemaphore semaphore) throws JSimInvalidParametersException
semaphore
- The semaphore that has to be added to the simulation.
JSimInvalidParametersException
- This exception is thrown out if the specified semaphore
is null.private final boolean startNewProcesses()
protected final void deleteProcess(JSimProcess process)
process
- The process to be deleted from the simulation.private final void deleteAllProcesses()
public final boolean step() throws JSimMethodNotSupportedException
JSimKernelPanicException
- This exception is thrown out when the state
of the simulation cannot be determined or when an inconsistency
of J-Sim internal structures (such as the calendar) is revealed.
JSimMethodNotSupportedException
- This exception is thrown out when the simulation
is running in GUI interactive mode and step() is called
from elsewhere than GUI.public void shutdown()
public int getNumber()
public java.lang.String getName()
public final long getNumberOfProcesses()
public final long getNumberOfQueues()
public final long getNumberOfSemaphores()
public final JSimProcess getRunningProcess()
public final long getFreeProcessNumber()
public final long getFreeQueueNumber()
public final long getFreeSemaphoreNumber()
protected final void switchToNobody()
public final double getCurrentTime()
public final int getSimulationState()
public final int getSimulationMode()
public final java.lang.Object getGraphicLock()
public final java.lang.Object getStepLock()
public final java.lang.Object getWindowClosureLock()
public final JSimChange getChange()
public java.util.SortedSet getObjectsToBeDisplayed(int elementType) throws JSimInvalidParametersException
elementType
- Specifies the type of elements whose information should be returned. Available
constants are JSimMainWindow.LIST_TYPE_*.
JSimInvalidParametersException
- This exception is thrown out if the elementType parameter
does not specify a valid type of simulation elements.protected void addEntryToCalendar(double absoluteTime, JSimProcess process) throws JSimInvalidParametersException
absoluteTime
- Absolute simulation time of the event being added to the calendar.process
- Process that will be activated at the specified time.
JSimInvalidParametersException
- This exception is thrown out if the time
or the process specified are invalid and were rejected
by the calendar.protected int deleteEntriesInCalendar(JSimProcess process, boolean all) throws JSimInvalidParametersException
process
- Process whose events are to be deleted.all
- Flag saying whether just one (false) or all (true) events of the process should be deleted.
JSimInvalidParametersException
- This exception is thrown out when the process specified
is invalid and was rejected by the calendar.public void setTalking(boolean yesOrNo)
yesOrNo
- Flag saying whether to switch talking on or off.public boolean getTalking()
public java.io.PrintStream getTalkStream()
public java.io.PrintStream changeTalkStream(java.io.PrintStream newStream)
newStream
- A new stream that should be used for talking.
public void talk(boolean x)
x
- The value to be printed out.public void talk(char x)
x
- The value to be printed out.public void talk(char[] x)
x
- The value to be printed out.public void talk(double x)
x
- The value to be printed out.public void talk(float x)
x
- The value to be printed out.public void talk(int x)
x
- The value to be printed out.public void talk(long x)
x
- The value to be printed out.public void talk(java.lang.Object x)
x
- The object to be printed out.public void talk(java.lang.String x)
x
- The string to be printed out.public void printString(java.lang.String s, int code, boolean newLine)
s
- The text message to be printed out.code
- Code saying whether it is an info message (PRN_MESSAGE) or an error (PRN_ERROR).newLine
- Flag indicating that the new line character should be appended to the text.public final boolean isRunningGUI()
public final boolean runGUI() throws JSimMethodNotSupportedException
JSimMethodNotSupportedException
- This exception is thrown out if the simulation
is not running in GUI interactive mode.private final boolean runBatchGUI()
public final void windowIsClosing(JSimMainWindow caller)
caller
- The main window informing about its closure.public void waitForWindowClosure() throws JSimMethodNotSupportedException
JSimMethodNotSupportedException
- This exception is thrown out if the simulation is not
running in GUI batch mode.public boolean getWaitingForWindowClosure()
public void message(java.lang.String s)
s
- The message to be printed out.public void messageNoNL(java.lang.String s)
s
- The message to be printed out.public void error(java.lang.String s)
s
- The error message to be printed out.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |