|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcz.zcu.fav.kiv.jsim.JSimSimulation
public class 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 | |
---|---|
private JSimCalendar |
calendar
The simulation's calendar of events. |
protected 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. |
protected JSimChange |
guiUpdate
Observable object notifying the GUI about possible changes. |
protected double |
lastGUIUpdate
Last GUI update time. |
private static java.util.logging.Logger |
logger
Common logger for all instances of this class. |
protected JSimMainWindow |
mainWindow
The simulation's main window. |
protected boolean |
mainWindowHasAlreadyExisted
Flag indicating that the main window has already been opened (and maybe closed). |
protected JSimSimulationMode |
mode
The simulation's mode – text, GUI batch, GUI interactive. |
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. |
protected double |
nextGUIUpdateDelta
GUI update delta. |
private static int |
noOfSimulations
Number of simulations running in this JVM instance. |
private java.util.SortedSet<JSimProcess> |
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<JSimProcess> |
processes
All processes of the simulation. |
private java.util.SortedSet<JSimProcess> |
processesForGUI
All processes that have ever existed in the simulation. |
private java.util.SortedSet<JSimHead> |
queues
All queues of the simulation. |
protected JSimProcess |
runningProcess
The currently running process. |
private java.util.SortedSet<JSimSemaphore> |
semaphores
All semaphores of the simulation. |
private JSimSimulationState |
simulationState
The simulation's state – not started, in progress, terminated. |
protected java.lang.Object |
stepLock
Lock used to synchronize (possible) concurrent calls to step(). |
private 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(). |
protected 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,
JSimSimulationMode mode)
Creates a new simulation with no processes, no queues and no graphic window. |
|
JSimSimulation(java.lang.String name,
JSimSimulationMode 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. |
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<? extends JSimDisplayable> |
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. |
JSimSimulationMode |
getSimulationMode()
Returns the simulation's mode. |
java.lang.String |
getSimulationName()
Returns the simulation's name. |
int |
getSimulationNumber()
Returns the simulation's unique number. |
JSimSimulationState |
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 |
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(). |
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. |
protected 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 |
shutdown()
Shutdowns the simulation by interrupting all living processes. |
protected boolean |
startNewProcesses()
Starts all new processes. |
boolean |
step()
Executes one simulation step. |
protected void |
switchToNobody()
Switches the execution to the main thread. |
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 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 static final java.util.logging.Logger logger
private final int myNumber
private final java.lang.String myName
protected final JSimSimulationMode mode
private long numberOfProcesses
private long numberOfQueues
private long numberOfSemaphores
protected JSimProcess runningProcess
private long newProcessNumber
private long newQueueNumber
private long newSemaphoreNumber
private JSimCalendar calendar
private double time
private JSimSimulationState simulationState
private java.util.SortedSet<JSimProcess> processes
private java.util.SortedSet<JSimProcess> processesForGUI
private java.util.SortedSet<JSimHead> queues
private java.util.SortedSet<JSimSemaphore> semaphores
private java.util.SortedSet<JSimProcess> notStartedProcesses
private final java.lang.Object graphicLock
protected final java.lang.Object stepLock
private final java.lang.Object waitForWindowClosureLock
protected JSimMainWindow mainWindow
protected boolean windowOpen
private boolean waitingForWindowClosure
protected boolean firstStepExecuted
protected boolean mainWindowHasAlreadyExisted
protected JSimChange guiUpdate
protected double nextGUIUpdateDelta
protected double lastGUIUpdate
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, JSimSimulationMode mode) throws JSimInvalidParametersException
name
- Name of the simulation.mode
- Simulation mode.
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, JSimSimulationMode mode, double guiUpdateDelta) throws JSimInvalidParametersException
name
- Name of the simulation.mode
- Simulation mode.guiUpdateDelta
- A simulation time interval after which the GUI output will be updated. If set to zero, the output will be updated after
every simulation step. This may be time consuming and inappropriate for some situations.
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.protected final boolean startNewProcesses()
protected final void deleteProcess(JSimProcess process)
process
- The process to be deleted from the simulation.private final void deleteAllProcesses()
public 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 getSimulationNumber()
public java.lang.String getSimulationName()
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 JSimSimulationState getSimulationState()
public final JSimSimulationMode 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<? extends JSimDisplayable> 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 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.protected 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 |