cz.zcu.fav.kiv.jsim
Class JSimProcess

java.lang.Object
  extended by java.lang.Thread
      extended by cz.zcu.fav.kiv.jsim.JSimProcess
All Implemented Interfaces:
JSimDisplayable, java.lang.Comparable<JSimProcess>, java.lang.Runnable

public class JSimProcess
extends java.lang.Thread
implements JSimDisplayable, java.lang.Comparable<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.

Since:
J-Sim version 0.0.1
Version:
J-Sim version 0.6.0
Author:
Jarda KAČER, Pavel DOMECKÝ

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

INT_REQUESTS_TO_IGNORE

public static final int INT_REQUESTS_TO_IGNORE
Methods passivate(), hold(), and reactivate() will ignore first INT_REQUESTS_TO_IGNORE requests to warn the programmer.

See Also:
Constant Field Values

logger

private static final java.util.logging.Logger logger
Common logger for all instances of this class. By default, all logging information goes to a file. Only severe events go to the console, in addition to a file.


myNumber

private final long myNumber
The process's number. It is unique for all process within the same simulation.


myName

private final java.lang.String myName
The process's name.


myState

private JSimProcessState myState
This process's state – new, passive, scheduled, active, blocked on semaphore, terminated, etc.


myParent

protected final JSimSimulation myParent
The simulation that this process is a part of. Protected because child classes will want to use it.


myOwnLock

private final java.lang.Object myOwnLock
Lock used when switching between the simulation and the process. Final – can be just created, not changed afterwards.


haveIBeenStarted

private boolean haveIBeenStarted
Flag saying whether this process has been started. Even a new thread can be scheduled, we must distinguish between being new and being started.


shouldTerminate

private boolean shouldTerminate
Flag saying whether this process has been interrupted by its simulation and should terminate.


requestsToTerminate

private int requestsToTerminate
Number of terminating warnings this process has got since it received an interrupt signal. It should be at most 1.


scheduleTime

private double scheduleTime
The simulation time that the process is scheduled for (if it is scheduled).


semaphoreIAmCurrentlyBlockedOn

private JSimSemaphore semaphoreIAmCurrentlyBlockedOn
The semaphore that this process is currently blocked on, if it is blocked at all.


myMessageBox

private JSimMessageBox myMessageBox
Every process has its own message box where messages sent directly between processes are stored.


messageClipboard

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.


messageSenderIAmWaitingFor

private JSimProcess messageSenderIAmWaitingFor
A process that this process is waiting for. This process will stay suspended inside a blocking receive operation until the sender sends it a message.

Constructor Detail

JSimProcess

public JSimProcess(java.lang.String name,
                   JSimSimulation parent)
            throws JSimSimulationAlreadyTerminatedException,
                   JSimInvalidParametersException,
                   JSimTooManyProcessesException
Creates a new process having a name and belonging to a simulation. If the simulation is already terminated or there is no free number the process is not created and an exception is thrown out. All processes must have their parent simulation object specified. If not, an exception is thrown, too. After the creation, the process is not scheduled and therefore will not run unless explicitely activated by another process or the main program using activate().

Parameters:
name - Name of the process being created.
parent - Parent simulation.
Throws:
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

getReady

protected void getReady()
Stops the process and waits until it is woken up by a signal. When a new process is started, it always blocks here and waits until the main thread switches to it when its turn comes. You should never use this method. It is called automatically from run().

Throws:
JSimProcessDeath - This internal J-Sim exception is thrown out when the simulation is shutting down. You should NEVER catch it!

finish

private final void finish()
Informs the parent simulation about its termination and switches back to the main thread. You should never use this method.


life

protected void life()
The process's life. Should be always overwritten in order to execute a meaningful action sequence. Must NOT be synchronized!


run

public final void run()
This method should never be overwritten or called directly. It call getReady(), life() and finish() and handles some extraordinary situations. You should never use or modify this method (it is final). Should be PRIVATE, but can't be – the parent's rights are public.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

start

public void start()
Starts the process. You should never use this method. All processes are started automatically when the step() method of the simulation is invoked.

Overrides:
start in class java.lang.Thread

hasBeenStarted

protected final boolean hasBeenStarted()
Returns true if the process has been started already. All processes are started automatically when the step() method of the simulation is invoked. You should never use this method.

Returns:
True if the process has been started already, false otherwise.

getPrivateLock

public java.lang.Object getPrivateLock()
Returns the process's private lock that the simulation uses for switching between itself and the process. The lock never changes. You should never use this method.

Returns:
The process's private lock.

getProcessNumber

public final long getProcessNumber()
Returns the process's number. The number is unique within the whole simulation.

Returns:
The process's number.

getProcessName

public java.lang.String getProcessName()
Returns the process's name.

Returns:
The process's name.

getParent

public JSimSimulation getParent()
Returns the simulation that this process is a part of.

Returns:
The simulation that this process is a part of.

getProcessState

public final JSimProcessState getProcessState()
Returns the process's state. Possible values are new, passive, scheduled, active, and terminated.

Returns:
The process's state.

getScheduleTime

public final double getScheduleTime()
Returns the time for which is the process scheduled. If the process is not scheduled, JSimCalendar.NEVER is returned.

Returns:
Time for which is the process scheduled or JSimCalendar.NEVER.

setProcessState

protected void setProcessState(JSimProcessState newState)
                        throws JSimInvalidProcessStateException
Switches the process to a new state. You should never use this method since this is an internal one. You should have a very serious reason to override it.

Parameters:
newState - A new state that the process has to be switched to.
Throws:
JSimInvalidProcessStateException - This exception is thrown out if the process is not allowed to change its state from the current one to the new one.

isIdle

public boolean isIdle()
Returns true if the process is idle, false otherwise. A process is idle if it is not currently running and can be freely activated. Actually, the process is idle if it is in the passive or new state.

Returns:
True if the process is idle, false otherwise.

getProcessStateAsString

public java.lang.String getProcessStateAsString()
Returns the process's state as string.

Returns:
The process's state as string.

mainSwitchingRoutine

protected final void mainSwitchingRoutine(JSimProcessState requestedBlockingState,
                                          java.lang.String callingMethodName)
                                   throws JSimSecurityException
The main switching routine, responsible for switching between the main simulation thread and the process and back. When called, it wakes the main thread up and passivates itself. Then it waits passivated until the main thread performing the simulation's step() method sends a signal to the process via notify(). You should never call this method directly. It is used internally by J-Sim in methods like passivate(), hold(), or any other method blocking the currently active simulation process.

Parameters:
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.
Throws:
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!

passivate

protected final void passivate()
                        throws JSimSecurityException
Passivates the process. Returns the control back to the parent simulation and does not add any new event to the calendar. A process cannot passivate another process, only itself. Will be called from MyProcess.life() --> protected because MyProcess will extend JSimProcess. Still `a' can call `b.passivate()' but it is taken care about.

Throws:
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!

hold

protected final void hold(double deltaT)
                   throws JSimSecurityException,
                          JSimInvalidParametersException
Passivates the process but adds a new entry to the calendar, specifying the time when the process will be activated again. A process cannot call another process's hold(), only its own. Will be called from MyProcess.life() --> protected because MyProcess will extend JSimProcess. Still `a' can call `b.hold()' but it is taken care about.

Parameters:
deltaT - The time delta specifying the difference between the current time and the time when the process will be activated.
Throws:
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!

activate

public final void activate(double when)
                    throws JSimSecurityException,
                           JSimInvalidParametersException
Activates a process at the given time. Adds a new entry to the calendar, specifying the time when the process will be activated. A process cannot activate itself but it can activate another process. Will be called from MySim.main() or MyProcess.life() --> public because MySim will not be in the same package.

Parameters:
when - Absolute simulation time when the process should be activated.
Throws:
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.

activateNow

public final void activateNow()
                       throws JSimSecurityException
Activates a process at the current simulation time. Adds a new entry to the calendar, with time set to now. A process cannot activate itself but it can activate another process. There is no guarantee that the activated process will run in the next step. It can be run later if there are more processes scheduled for the same time. Will be called from MySim.main() or MyProcess.life() --> public because MySim will not be in the same package.

Throws:
JSimSecurityException - This exception is thrown out when the process to be activated is not currently passive or new.

cancel

public final void cancel()
                  throws JSimSecurityException
Deletes all process's scheduled events from the calendar. The process will not be run anymore unless activated again by another process. A process can cancel another process but not itself. Will be called from MyProcess.life() --> public because it need not necessarily be in the same package as the called process.

Throws:
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.)

reactivate

protected final void reactivate()
                         throws JSimSecurityException
Reactivates the process. The process is temporarily suspended as with passivate() but an event is added to the calendar for the same simulation time. This means that the process will run again in a future step (not necessarily the next one) and the value of the simulation time will be the same as now. The purpose of this method is to let other processes run if they have been scheduled for the same simulation time. Since later scheduled processes are run later (if the simulation times are equal) this process will run after all processes already scheduled for the current simulation time.

Throws:
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!

wait

protected final void wait(JSimHead head)
                   throws JSimSecurityException,
                          JSimInvalidParametersException
Passivates the process and inserts it to the specified queue. The process can be later taken out from the queue and reactivated using activate().

Parameters:
head - The queue that the process has to be inserted to.
Throws:
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!

blockOnSemaphore

public final void blockOnSemaphore(JSimSemaphore semaphore)
                            throws JSimSecurityException,
                                   JSimInvalidParametersException
Blocks the process until it is unblocked by a semaphore's V() function. Returns the control back to the parent simulation and does not add any new event to the calendar. A process cannot block another process, only itself via a semaphore's P() function. Blocking on a semaphore terminates the current simulation step.

Parameters:
semaphore - The semaphore on which P() function this process is getting blocked.
Throws:
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!

unblockFromSemaphore

public final void unblockFromSemaphore(JSimSemaphore semaphore)
                                throws JSimSecurityException,
                                       JSimInvalidParametersException
Unblocks the process which has previously got blocked on a semaphore. Adds a new entry to the calendar with the current time. The process does not start running immediately but switches to the scheduled state and waits until it is re-started by the simulation from its step() method.

Parameters:
semaphore - The semaphore that this process is currently blocked on.
Throws:
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.

getMessageBox

protected JSimMessageBox getMessageBox()
Returns the process's message box. The box is used for storing messages coming directly to the process.

Returns:
The process's message box.

hasEmptyMessageClipboard

public boolean hasEmptyMessageClipboard()
Indicates whether this process's clipboard is empty or not. The clipboard is used to store a single message taken out from a message box when the process is blocked during a blocking send operation.

Returns:
True is this process's clipboard is empty, false otherwise.

copyToMessageClipboard

protected void copyToMessageClipboard(JSimMessage message)
                               throws JSimSecurityException
Copies a single message to the process's clipboard. The clipboard must be empty. No physical copying is done, just reference assignment.

Parameters:
message - The message to be put into the clipboard.
Throws:
JSimSecurityException - This exception is thrown out if the clipboard is not empty.

readFromClipboard

protected JSimMessage readFromClipboard()
Reads a message from the clipboard and returns it. If there is no message in the clipboard, null is returned. The message is taken out from the clipboard.

Returns:
A message stored in the clipboard or null.

getSenderIAmWaitingFor

public JSimProcess getSenderIAmWaitingFor()
Returns the process that this process specified as sender for its blocking receive operation. If no sender was specified or this process is not performing a blocking receive operation, null is returned.

Returns:
The process that this process specified as sender for its blocking receive operation.

unblockFromMessageSendOrReceive

private final void unblockFromMessageSendOrReceive()
                                            throws JSimSecurityException
A routine used for process reactivation after a successfully completed send or receive blocking operation.

Throws:
JSimSecurityException - This exception is thrown out if the process is not currently blocked.

sendMessageWithBlocking

public void sendMessageWithBlocking(JSimSymmetricMessage message)
                             throws JSimInvalidParametersException
Sends the specified message to the process denoted as receiver of the message. If the receiver is not currently waiting for the message, the sending process will block and the current simulation step will be terminated.

Parameters:
message - The message to be sent.
Throws:
JSimInvalidParametersException - This exception is thrown out if the message is not specified (null).

sendMessageWithBlocking

public void sendMessageWithBlocking(JSimMessageForReceiver message)
                             throws JSimInvalidParametersException
Sends the specified message to the process denoted as receiver of the message. If the receiver is not currently waiting for the message, the sending process will block and the current simulation step will be terminated.

Parameters:
message - The message to be sent.
Throws:
JSimInvalidParametersException - This exception is thrown out if the message is not specified (null).

sendMessageWithBlocking

public void sendMessageWithBlocking(JSimMessage message,
                                    JSimMessageBox box)
                             throws JSimInvalidParametersException
Sends the specified message to the specified message box. If there is no receiver currently waiting for the message, the sending process will block and the current simulation step will be terminated.

Parameters:
message - The message to be sent.
box - The message box that the message has to be put to.
Throws:
JSimInvalidParametersException - This exception is thrown out if the message or the the message box is not specified (null).

sendMessageWithoutBlocking

public void sendMessageWithoutBlocking(JSimSymmetricMessage message)
                                throws JSimInvalidParametersException
Sends the specified message to the process denoted as receiver of the message. If the receiver is not currently waiting for the message, the sending process will just store the message to its message box. In any case, the sender returns immediately.

Parameters:
message - The message to be sent.
Throws:
JSimInvalidParametersException - This exception is thrown out if the message is not specified (null).

sendMessageWithoutBlocking

public void sendMessageWithoutBlocking(JSimMessageForReceiver message)
                                throws JSimInvalidParametersException
Sends the specified message to the process denoted as receiver of the message. If the receiver is not currently waiting for the message, the sending process will just store the message to its message box. In any case, the sender returns immediately.

Parameters:
message - The message to be sent.
Throws:
JSimInvalidParametersException - This exception is thrown out if the message is not specified (null).

sendMessageWithoutBlocking

public void sendMessageWithoutBlocking(JSimMessage message,
                                       JSimMessageBox box)
                                throws JSimInvalidParametersException
Sends the specified message to the specified message box. If there is no receiver currently waiting for the message, the sending process will just store the message to the message box. In any case, the sender returns immediately.

Parameters:
message - The message to be sent.
box - The message box that the message has to be put to.
Throws:
JSimInvalidParametersException - This exception is thrown out if the message or the the message box is not specified (null).

receiveMessageWithBlocking

public JSimMessage receiveMessageWithBlocking()
Receives and returns a message previously sent to this process by any other process. If there is no message in the receiver's message box currently waiting for the receiver, the receiver blocks and the current simulation step is terminated.

Returns:
A message read from the receiver's message box.

receiveMessageWithBlocking

public JSimMessage receiveMessageWithBlocking(JSimMessageBox box)
                                       throws JSimInvalidParametersException
Receives and returns a message from the specified message box. If there is no message in the message box currently waiting for the receiver, the receiver blocks and the current simulation step is terminated.

Parameters:
box - The message box that the message has to be read from.
Returns:
A message read from the specified message box previously sent by the specified sender.
Throws:
JSimInvalidParametersException - This exception is thrown out if the message box is not specified.

receiveMessageWithBlocking

public JSimMessage receiveMessageWithBlocking(JSimProcess sender)
Receives and returns a message previously sent by the specified sender to this process. The sender need not be specified. If it is not specified (JSimMessage.UNKNOWN_SENDER), message from any sender can be returned. If there is no message in the message box of the receiver, currently waiting for the receiver and sent by the sender, the receiver blocks and the current simulation step is terminated.

Parameters:
sender - The sender of the message. Need not be specified.
Returns:
A message read from the receiver's message box previously sent by the specified sender.

receiveMessageWithBlocking

public JSimMessage receiveMessageWithBlocking(JSimMessageBox box,
                                              JSimProcess sender)
                                       throws JSimInvalidParametersException
Receives and returns a message from the specified message box previously sent by the specified sender. The sender need not be specified. If it is not specified (JSimMessage.UNKNOWN_SENDER) message from any sender can be returned. If there is no message in the message box currently waiting for the receiver and sent by the sender, the receiver blocks and the current simulation step is terminated.

Parameters:
box - The message box that the message has to be read from.
sender - The sender of the message. Need not be specified.
Returns:
A message read from the specified message box previously sent by the specified sender.
Throws:
JSimInvalidParametersException - This exception is thrown out if the message box is not specified.

receiveMessageWithoutBlocking

public JSimMessage receiveMessageWithoutBlocking()
Receives and returns a message from the receiver's message box previously sent by any process. If there is no message currently waiting for the receiver, the method returns null. In any case, the receiver returns immediately from this method.

Returns:
A message read from the receiver's message box.

receiveMessageWithoutBlocking

public JSimMessage receiveMessageWithoutBlocking(JSimMessageBox box)
                                          throws JSimInvalidParametersException
Receives and returns a message from the specified message box previously sent by any process. If there is no message in the message box currently waiting for the receiver, the method returns null. In any case, the receiver returns immediately from this method.

Parameters:
box - The message box that the message has to be read from.
Returns:
A message read from the specified message box.
Throws:
JSimInvalidParametersException - This exception is thrown out if the message box is not specified.

receiveMessageWithoutBlocking

public JSimMessage receiveMessageWithoutBlocking(JSimProcess sender)
Receives and returns a message from the receiver's message box previously sent by the specified sender. The sender need not be specified. If it is not specified (JSimMessage.UNKNOWN_SENDER) message from any sender can be returned. If there is no message in the message box currently waiting for the receiver and sent by the sender, the method returns null. In any case, the receiver returns immediately from this method.

Parameters:
sender - The sender of the message. Need not be specified.
Returns:
A message read from the receiver's message box previously sent by the specified sender.

receiveMessageWithoutBlocking

public JSimMessage receiveMessageWithoutBlocking(JSimMessageBox box,
                                                 JSimProcess sender)
                                          throws JSimInvalidParametersException
Receives and returns a message from the specified message box previously sent by the specified sender. The sender need not be specified. If it is not specified (JSimMessage.UNKNOWN_SENDER) message from any sender can be returned. If there is no message in the message box currently waiting for the receiver and sent by the sender, the method returns null. In any case, the receiver returns immediately from this method.

Parameters:
box - The message box that the message has to be read from.
sender - The sender of the message. Need not be specified.
Returns:
A message read from the specified message box previously sent by the specified sender.
Throws:
JSimInvalidParametersException - This exception is thrown out if the message box is not specified.

message

public void message(java.lang.String s)
Prints out a text info message, either to the standard output or to the simulation window.

Parameters:
s - The message to be printed out.

messageNoNL

public 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.

Parameters:
s - The message to be printed out.

error

public void error(java.lang.String s)
Prints out a text error message, either to the error output or to the simulation window.

Parameters:
s - The error message to be printed out.

getObjectListItemDescription

public java.lang.String getObjectListItemDescription()
Returns a string containing basic information about the process. The string can be displayed in a JSimMainWindowList component.

Specified by:
getObjectListItemDescription in interface JSimDisplayable
Returns:
A string containing basic information about the process.

getDetailedInformationArray

public java.util.Collection<JSimPair> getDetailedInformationArray()
Returns a collection of process's characteristics. Every characteristics contains a name and a value. The collection can be displayed in a JSimDetailedInfoWindow table.

Specified by:
getDetailedInformationArray in interface JSimDisplayable
Returns:
A collection of JSimPairs.

createDetailedInfoWindow

public javax.swing.JDialog createDetailedInfoWindow(JSimMainWindow parentWindow)
Creates a detailed info window that shows information about this process. Returns a reference to the created window.

Specified by:
createDetailedInfoWindow in interface JSimDisplayable
Returns:
Reference to the created info window.

toString

public java.lang.String toString()
Returns a string representation of the process. Provided information: number, name, state, and schedule time.

Overrides:
toString in class java.lang.Thread
Returns:
A string representation of the process.

compareTo

public int compareTo(JSimProcess p)
Compares this process with another one. Returns a negative integer, zero, or a positive integer as this process is less than, equal to, or greater than the specified object. It is assumed that the argument is also a JSimProcess. This class has a natural ordering that is fully consistent with equals(). If equals() returns true for p1 and p2, then compareTo() will return 0 for the same p1 and p2, and vice versa.

Specified by:
compareTo in interface java.lang.Comparable<JSimProcess>
Returns:
Zero if the numbers of both processes are equal, a negative number if the number of this process is less than the other process's number, and a positive number if the number of this process is greater than the other process's number.
Throws:
java.lang.ClassCastException - This exception is thrown out when the specified object cannot be typecasted to JSimProcess.

equals

public boolean equals(java.lang.Object o)
Indicates whether some other object is equal to this one. This implementation compares process numbers and their simulations' numbers which is actually equal to simple reference comparison because process numbers are unique for a given simulation and simulation numbers are unique for a given JVM instance. Unique process numbers are assured by the constructor and the JSimSimulation.getFreeProcessNumber() method. Unique simulation numbers are assured by the JSimSimulation constructor.

Overrides:
equals in class java.lang.Object
Parameters:
o - The reference object with which to compare.
Returns:
True if this object is the same as the obj argument, false otherwise.

hashCode

public int hashCode()
Returns a hash code value for the object. The hash code is computed from the process's number and its simulation's number using the algorithm described in [UJJ3/166]. This implementation of hash code computation is fully consistent with equals().

Overrides:
hashCode in class java.lang.Object
Returns:
A hash code for this process.


Copyright © 2000-2006 University of West Bohemia. Licensed under the Academic Free License v. 2.1. Build date 20060812.