|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
cz.zcu.fav.kiv.jsim.JSimProcess
public class 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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
private boolean |
haveIBeenStarted
Flag saying whether this process has been started. |
static int |
INT_REQUESTS_TO_IGNORE
Methods passivate(), hold(), and reactivate() will ignore first INT_REQUESTS_TO_IGNORE requests to warn the programmer. |
private static java.util.logging.Logger |
logger
Common logger for all instances of this class. |
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 java.lang.String |
myName
The process's name. |
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 JSimProcessState |
myState
This process's state – new, passive, scheduled, active, blocked on semaphore, terminated, etc. |
private int |
requestsToTerminate
Number of terminating warnings this process has got since it received an interrupt signal. |
private 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). |
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 |
activateNow()
Activates a process at the current simulation 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(JSimProcess p)
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<JSimPair> |
getDetailedInformationArray()
Returns a collection of process's characteristics. |
protected JSimMessageBox |
getMessageBox()
Returns the process's message box. |
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. |
java.lang.Object |
getPrivateLock()
Returns the process's private lock that the simulation uses for switching between itself and the process. |
java.lang.String |
getProcessName()
Returns the process's name. |
long |
getProcessNumber()
Returns the process's number. |
JSimProcessState |
getProcessState()
Returns the process's state. |
java.lang.String |
getProcessStateAsString()
Returns the process's state as string. |
protected 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. |
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. |
protected void |
mainSwitchingRoutine(JSimProcessState requestedBlockingState,
java.lang.String callingMethodName)
The main switching routine, responsible for switching between the main simulation thread and the process and back. |
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. |
protected void |
setProcessState(JSimProcessState 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, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, checkAccess, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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 INT_REQUESTS_TO_IGNORE
private static final java.util.logging.Logger logger
private final long myNumber
private final java.lang.String myName
private JSimProcessState myState
protected final JSimSimulation myParent
private final java.lang.Object myOwnLock
private boolean haveIBeenStarted
private boolean shouldTerminate
private int requestsToTerminate
private double scheduleTime
private 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
- Parent 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 |
---|
protected 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()
public java.lang.Object getPrivateLock()
public final long getProcessNumber()
public java.lang.String getProcessName()
public JSimSimulation getParent()
public final JSimProcessState getProcessState()
public final double getScheduleTime()
protected void setProcessState(JSimProcessState 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 getProcessStateAsString()
protected final void mainSwitchingRoutine(JSimProcessState requestedBlockingState, java.lang.String callingMethodName) throws JSimSecurityException
requestedBlockingState
- The process will be set to this state during its passivation. Pay attention! The setState() method must allow to set the
new state!callingMethodName
- The name of the method calling the switching routine.
JSimSecurityException
- This exception is thrown out when the process to be switched over is not currently active or if another process calls
this process's method. Note: The two conditions should be equivalent since there can be at most one active J-Sim
process at one time.
JSimProcessDeath
- This internal J-Sim exception is thrown out when the simulation is shutting down. You should NEVER catch it!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, JSimInvalidParametersException
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.
JSimInvalidParametersException
- This exception is thrown out if the time difference is negative. Processes cannot be scheduled to the past.
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 activateNow() throws JSimSecurityException
JSimSecurityException
- This exception is thrown out when the process to be activated is not currently passive or new.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<JSimPair> 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(JSimProcess p)
compareTo
in interface java.lang.Comparable<JSimProcess>
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 |