|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--cz.zcu.fav.kiv.jsim.JSimProcess
A JSimProcess is an independent unit of code, having its own data. Its code is placed in the life() method. Processes have possibilities to schedule themselves as well as other processes, they can also cancel another process's schedule. A process must belong to a simulation. During a simulation execution, processes are interleaved in a pseudo-parallel manner, i.e. just one process is running at the same time. When the currently running process invokes hold(), passivate(), or reactivate(), it is suspended and another process can be executed instead.
Field Summary | |
private boolean |
haveIBeenStarted
Flag saying whether this process has been started. |
static int |
INT_REQUESTS_TO_IGNORE
|
private JSimMessage |
messageClipboard
The message clipboard is a single message passed from a process to this process when this process has invoked a blocking receive operation and got blocked inside it. |
private JSimProcess |
messageSenderIAmWaitingFor
A process that this process is waiting for. |
private JSimMessageBox |
myMessageBox
Every process has its own message box where messages sent directly between processes are stored. |
private long |
myNumber
The process's number. |
private java.lang.Object |
myOwnLock
Lock used when switching between the simulation and the process. |
protected JSimSimulation |
myParent
The simulation that this process is a part of. |
private int |
myState
This process's state -- new, passive, scheduled, active, blocked on semaphore or terminated. |
private int |
requestsToTerminate
Number of terminating warnings this process has got since it received an interrupt signal. |
protected JSimSemaphore |
semaphoreIAmCurrentlyBlockedOn
The semaphore that this process is currently blocked on, if it is blocked at all. |
private boolean |
shouldTerminate
Flag saying whether this process has been interrupted by its simulation and should terminate. |
private double |
scheduleTime
The simulation time that the process is scheduled for (if it is scheduled). |
static int |
STATE_ACTIVE
A process is active if it is just now running. |
static int |
STATE_BLOCKEDONMESSAGERECEIVE
A process gets blocked on receiving a message if the blocking version of the receive method is used and no message is currently available to be read. |
static int |
STATE_BLOCKEDONMESSAGESEND
A process gets blocked on sending a message if the blocking version of the send method is used and the receiver is not ready yet to read the message. |
static int |
STATE_BLOCKEDONSEMAPHORE
A process gets blocked on a semaphore if it invokes its P() function and the semaphore's internal counter is equal to zero. |
static int |
STATE_NEW
A process is in STATE_NEW state if it has been created but not started and not scheduled yet. |
static int |
STATE_PASSIVE
A process is passive if it has been started and it has no event in the calendar. |
static int |
STATE_SCHEDULED
A process is scheduled if it has an event in the calendar so it will run in the future. |
static int |
STATE_TERMINATED
A process is terminated if it has reached the end of its life() method. |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
JSimProcess(java.lang.String name,
JSimSimulation parent)
Creates a new process having a name and belonging to a simulation. |
Method Summary | |
void |
activate(double when)
Activates a process at the given time. |
void |
blockOnSemaphore(JSimSemaphore semaphore)
Blocks the process until it is unblocked by a semaphore's V() function. |
void |
cancel()
Deletes all process's scheduled events from the calendar. |
int |
compareTo(java.lang.Object o)
Compares this process with another one. |
protected void |
copyToMessageClipboard(JSimMessage message)
Copies a single message to the process's clipboard. |
javax.swing.JDialog |
createDetailedInfoWindow(JSimMainWindow parentWindow)
Creates a detailed info window that shows information about this process. |
boolean |
equals(java.lang.Object o)
Indicates whether some other object is equal to this one. |
void |
error(java.lang.String s)
Prints out a text error message, either to the error output or to the simulation window. |
private void |
finish()
Informs the parent simulation about its termination and switches back to the main thread. |
java.util.Collection |
getDetailedInformationArray()
Returns a collection of process's characteristics. |
protected JSimMessageBox |
getMessageBox()
Returns the process's message box. |
long |
getNumber()
Returns the process's number. |
java.lang.String |
getObjectListItemDescription()
Returns a string containing basic information about the process. |
JSimSimulation |
getParent()
Returns the simulation that this process is a part of. |
protected java.lang.Object |
getPrivateLock()
Returns the process's private lock that the simulation uses for switching between itself and the process. |
private void |
getReady()
Stops the process and waits until it is woken up by a signal. |
JSimProcess |
getSenderIAmWaitingFor()
Returns the process that this process specified as sender for its blocking receive operation. |
double |
getScheduleTime()
Returns the time for which is the process scheduled. |
int |
getState()
Returns the process's state. |
java.lang.String |
getStateAsString()
Returns the process's state as string. |
static java.lang.String |
getStateAsString(int state)
Returns a corresponding string representation for any given process state. |
protected boolean |
hasBeenStarted()
Returns true if the process has been started already. |
boolean |
hasEmptyMessageClipboard()
Indicates whether this process's clipboard is empty or not. |
int |
hashCode()
Returns a hash code value for the object. |
protected void |
hold(double deltaT)
Passivates the process but adds a new entry to the calendar, specifying the time when the process will be activated again. |
boolean |
isIdle()
Returns true if the process is idle, false otherwise. |
protected void |
life()
The process's life. |
void |
message(java.lang.String s)
Prints out a text info message, either to the standard output or to the simulation window. |
void |
messageNoNL(java.lang.String s)
Prints a text info message, either to the standard output or to the simulation window, but does not teminate the line. |
protected void |
passivate()
Passivates the process. |
protected void |
reactivate()
Reactivates the process. |
protected JSimMessage |
readFromClipboard()
Reads a message from the clipboard and returns it. |
JSimMessage |
receiveMessageWithBlocking()
Receives and returns a message previously sent to this process by any other process. |
JSimMessage |
receiveMessageWithBlocking(JSimMessageBox box)
Receives and returns a message from the specified message box. |
JSimMessage |
receiveMessageWithBlocking(JSimMessageBox box,
JSimProcess sender)
Receives and returns a message from the specified message box previously sent by the specified sender. |
JSimMessage |
receiveMessageWithBlocking(JSimProcess sender)
Receives and returns a message previously sent by the specified sender to this process. |
JSimMessage |
receiveMessageWithoutBlocking()
Receives and returns a message from the receiver's message box previously sent by any process. |
JSimMessage |
receiveMessageWithoutBlocking(JSimMessageBox box)
Receives and returns a message from the specified message box previously sent by any process. |
JSimMessage |
receiveMessageWithoutBlocking(JSimMessageBox box,
JSimProcess sender)
Receives and returns a message from the specified message box previously sent by the specified sender. |
JSimMessage |
receiveMessageWithoutBlocking(JSimProcess sender)
Receives and returns a message from the receiver's message box previously sent by the specified sender. |
void |
run()
This method should never be overwritten or called directly. |
void |
sendMessageWithBlocking(JSimMessageForReceiver message)
Sends the specified message to the process denoted as receiver of the message. |
void |
sendMessageWithBlocking(JSimMessage message,
JSimMessageBox box)
Sends the specified message to the specified message box. |
void |
sendMessageWithBlocking(JSimSymmetricMessage message)
Sends the specified message to the process denoted as receiver of the message. |
void |
sendMessageWithoutBlocking(JSimMessageForReceiver message)
Sends the specified message to the process denoted as receiver of the message. |
void |
sendMessageWithoutBlocking(JSimMessage message,
JSimMessageBox box)
Sends the specified message to the specified message box. |
void |
sendMessageWithoutBlocking(JSimSymmetricMessage message)
Sends the specified message to the process denoted as receiver of the message. |
private void |
setProcessState(int newState)
Switches the process to a new state. |
void |
start()
Starts the process. |
java.lang.String |
toString()
Returns a string representation of the process. |
private void |
unblockFromMessageSendOrReceive()
A routine used for process reactivation after a successfully completed send or receive blocking operation. |
void |
unblockFromSemaphore(JSimSemaphore semaphore)
Unblocks the process which has previously got blocked on a semaphore. |
protected void |
wait(JSimHead head)
Passivates the process and inserts it to the specified queue. |
Methods inherited from class java.lang.Thread |
activeCount, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, checkAccess, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, stop, stop, suspend, yield |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int STATE_NEW
public static final int STATE_PASSIVE
public static final int STATE_SCHEDULED
public static final int STATE_ACTIVE
public static final int STATE_BLOCKEDONSEMAPHORE
public static final int STATE_BLOCKEDONMESSAGESEND
public static final int STATE_BLOCKEDONMESSAGERECEIVE
public static final int STATE_TERMINATED
public static final int INT_REQUESTS_TO_IGNORE
private final long myNumber
private int myState
protected final JSimSimulation myParent
private final java.lang.Object myOwnLock
private boolean haveIBeenStarted
private boolean shouldTerminate
private int requestsToTerminate
private double scheduleTime
protected JSimSemaphore semaphoreIAmCurrentlyBlockedOn
private JSimMessageBox myMessageBox
private JSimMessage messageClipboard
private JSimProcess messageSenderIAmWaitingFor
Constructor Detail |
public JSimProcess(java.lang.String name, JSimSimulation parent) throws JSimSimulationAlreadyTerminatedException, JSimInvalidParametersException, JSimTooManyProcessesException
name
- Name of the process being created.parent
- Pparent simulation.
JSimSimulationAlreadyTerminatedException
- This exception is thrown out if the simulation
has already been terminated.
JSimInvalidParametersException
- This exception is thrown out if no parent was
specified.
JSimTooManyProcessesException
- This exception is thrown out if no other process
can be added to the simulation specified.
JSimKernelPanicException
- This exception is thrown out if the simulation
is in a unknown state. Do NOT catch this exception!Method Detail |
private final void getReady()
JSimProcessDeath
- This internal J-Sim exception is thrown out when the simulation is
shutting down. You should NEVER catch it!private final void finish()
protected void life()
public final void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void start()
start
in class java.lang.Thread
protected final boolean hasBeenStarted()
protected java.lang.Object getPrivateLock()
public final long getNumber()
public JSimSimulation getParent()
public final int getState()
public final double getScheduleTime()
private final void setProcessState(int newState) throws JSimInvalidProcessStateException
newState
- A new state that the process has to be switched to.
JSimInvalidProcessStateException
- This exception is thrown out if the process is not
allowed to change its state from the current one to the
new one.public boolean isIdle()
public java.lang.String getStateAsString()
public static java.lang.String getStateAsString(int state)
state
- The state to be converted to a string.
protected final void passivate() throws JSimSecurityException
JSimSecurityException
- This exception is thrown out when the process to be passivated
is not currently active or if another process calls this
process's passivate() method. (Note: The two conditions should
be equivalent.)
JSimProcessDeath
- This internal J-Sim exception is thrown out when the simulation
is shutting down. You should NEVER catch it!protected final void hold(double deltaT) throws JSimSecurityException
deltaT
- The time delta specifying the difference between the current time and the time when
the process will be activated.
JSimSecurityException
- This exception is thrown out when the process to be hold is not
currently active or if another process calls this process's
hold() method. (Note: The two conditions should be equivalent.)
JSimProcessDeath
- This internal J-Sim exception is thrown out when the simulation
is shutting down. You should NEVER catch it!public final void activate(double when) throws JSimSecurityException, JSimInvalidParametersException
when
- Absolute simulation time when the process should be activated.
JSimSecurityException
- This exception is thrown out when the process to be
activated is not currently passive or new.
JSimInvalidParametersException
- This exception is thrown out if the time of activation
is less than current simulation time.public final void cancel() throws JSimSecurityException
JSimSecurityException
- This exception is thrown out when the process to be cancelled is
not currently scheduled or if the process calls its own cancel()
method. (Note: The latter condition is a subset of the former one
because the currently running process can never be scheduled.)protected final void reactivate() throws JSimSecurityException
JSimSecurityException
- This exception is thrown out when the process to be reactivated
is not currently active or if another process calls this process's
reactivate() method. (Note: The two conditions should be equivalent.)
JSimProcessDeath
- This internal J-Sim exception is thrown out when the simulation
is shutting down. You should NEVER catch it!protected final void wait(JSimHead head) throws JSimSecurityException, JSimInvalidParametersException
head
- The queue that the process has to be inserted to.
JSimInvalidParametersException
- This exception is thrown out if the queue to which the
process should be inserted is null.
JSimSecurityException
- This exception is thrown out when the process of which
wait() method is called is not currently active or if another
process calls this process's wait() method. (Note: The two
conditions should be equivalent.)
JSimProcessDeath
- This internal J-Sim exception is thrown out when the simulation
is shutting down. You should NEVER catch it!public final void blockOnSemaphore(JSimSemaphore semaphore) throws JSimSecurityException, JSimInvalidParametersException
semaphore
- The semaphore on which P() function this process is getting blocked.
JSimSecurityException
- This exception is thrown out when the process to be blocked
is not currently active or if another process calls this
process's blockOnSemaphore() method. (Note: The two conditions
should be equivalent.)
JSimInvalidParametersException
- This exception is thrown out if the semaphore in not
specified (is null) or if its parent is not this
process's parent.
JSimProcessDeath
- This internal J-Sim exception is thrown out when the simulation
is shutting down. You should NEVER catch it!public final void unblockFromSemaphore(JSimSemaphore semaphore) throws JSimSecurityException, JSimInvalidParametersException
semaphore
- The semaphore that this process is currently blocked on.
JSimSecurityException
- This exception is thrown out when the process to be
unblocked is not currently blocked.
JSimInvalidParametersException
- This exception is thrown out if the semaphore is null
or its parent is not this process's parent or it is
not the semaphore that this process is blocked on.protected JSimMessageBox getMessageBox()
public boolean hasEmptyMessageClipboard()
protected void copyToMessageClipboard(JSimMessage message) throws JSimSecurityException
message
- The message to be put into the clipboard.
JSimSecurityException
- This exception is thrown out if the clipboard is not empty.protected JSimMessage readFromClipboard()
public JSimProcess getSenderIAmWaitingFor()
private final void unblockFromMessageSendOrReceive() throws JSimSecurityException
JSimSecurityException
- This exception is thrown out if the process is not
currently blocked.public void sendMessageWithBlocking(JSimSymmetricMessage message) throws JSimInvalidParametersException
message
- The message to be sent.
JSimInvalidParametersException
- This exception is thrown out if the message
is not specified (null).public void sendMessageWithBlocking(JSimMessageForReceiver message) throws JSimInvalidParametersException
message
- The message to be sent.
JSimInvalidParametersException
- This exception is thrown out if the message
is not specified (null).public void sendMessageWithBlocking(JSimMessage message, JSimMessageBox box) throws JSimInvalidParametersException
message
- The message to be sent.box
- The message box that the message has to be put to.
JSimInvalidParametersException
- This exception is thrown out if the message or the
the message box is not specified (null).public void sendMessageWithoutBlocking(JSimSymmetricMessage message) throws JSimInvalidParametersException
message
- The message to be sent.
JSimInvalidParametersException
- This exception is thrown out if the message
is not specified (null).public void sendMessageWithoutBlocking(JSimMessageForReceiver message) throws JSimInvalidParametersException
message
- The message to be sent.
JSimInvalidParametersException
- This exception is thrown out if the message
is not specified (null).public void sendMessageWithoutBlocking(JSimMessage message, JSimMessageBox box) throws JSimInvalidParametersException
message
- The message to be sent.box
- The message box that the message has to be put to.
JSimInvalidParametersException
- This exception is thrown out if the message or the
the message box is not specified (null).public JSimMessage receiveMessageWithBlocking()
public JSimMessage receiveMessageWithBlocking(JSimMessageBox box) throws JSimInvalidParametersException
box
- The message box that the message has to be read from.
JSimInvalidParametersException
- This exception is thrown out if the message box
is not specified.public JSimMessage receiveMessageWithBlocking(JSimProcess sender)
sender
- The sender of the message. Need not be specified.
public JSimMessage receiveMessageWithBlocking(JSimMessageBox box, JSimProcess sender) throws JSimInvalidParametersException
box
- The message box that the message has to be read from.sender
- The sender of the message. Need not be specified.
JSimInvalidParametersException
- This exception is thrown out if the message box
is not specified.public JSimMessage receiveMessageWithoutBlocking()
public JSimMessage receiveMessageWithoutBlocking(JSimMessageBox box) throws JSimInvalidParametersException
box
- The message box that the message has to be read from.
JSimInvalidParametersException
- This exception is thrown out if the message box
is not specified.public JSimMessage receiveMessageWithoutBlocking(JSimProcess sender)
sender
- The sender of the message. Need not be specified.
public JSimMessage receiveMessageWithoutBlocking(JSimMessageBox box, JSimProcess sender) throws JSimInvalidParametersException
box
- The message box that the message has to be read from.sender
- The sender of the message. Need not be specified.
JSimInvalidParametersException
- This exception is thrown out if the message box
is not specified.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.public java.lang.String getObjectListItemDescription()
getObjectListItemDescription
in interface JSimDisplayable
public java.util.Collection getDetailedInformationArray()
getDetailedInformationArray
in interface JSimDisplayable
public javax.swing.JDialog createDetailedInfoWindow(JSimMainWindow parentWindow)
createDetailedInfoWindow
in interface JSimDisplayable
public java.lang.String toString()
toString
in class java.lang.Thread
public int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable
java.lang.ClassCastException
- This exception is thrown out when the specified object cannot be
typecasted to JSimProcess.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- The reference object with which to compare.
public int hashCode()
hashCode
in class java.lang.Object
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |