|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcz.zcu.fav.kiv.jsim.JSimSimulation
cz.zcu.fav.kiv.cs.CSSimulation
The main class describing the simulation submodel.
| Field Summary | |
private java.util.LinkedList |
calFinal
The list of events that will be simulated in the current step of the distributed simulation. |
private java.util.LinkedList |
calTemp
Into that list insert other processes events of local proceses. |
private int |
counterOfDist
Counter of received distances to submodels. |
private java.lang.Object |
distanceLock
His wait() and notify() methods are used to wait for message from server with distances to the other submodels . |
private double[][] |
distances
Distances of internal processes to the other submodels. |
private boolean |
distancesReceived
True, if distances to all submodels have been received from server. |
private int |
ID
ID of this submodel assigned by the server. |
private java.io.BufferedReader |
in
The input channel for messages from the server or other submodels. |
private java.util.ArrayList |
internalProc
Array of CSProcesses located in that submodel |
private java.util.HashMap |
internalProcIDs
The left side of this map is an ID of a process assigned by user and the right side is the ID assigned by submodel to this process. |
private double |
lastTimeFromServer
The value of the safe time to simulate in this step of the distributed simulation. |
private int |
numberOfInternalProc
The number of CSProcesses in that submodel. |
private int |
numberOfProc
The number of all CSProcesses in the distributed simulation. |
private int |
numberOfSimul
The number of all simulation submodels in the distributed simulation. |
private java.io.PrintWriter |
out
The output channel for messages to the server or other submodels. |
private CSReadingThread |
readT
the thread taking care of reading messages on input channel. |
private java.lang.String |
remoteERROR
Indicates an error in remote submodel. |
private java.lang.Object |
safeTimeLock
His wait() and notify() methods are used to wait for message from server with next safe time. |
private java.net.Socket |
socket
The socket for a communication between the submodel and the thread of the server. |
private boolean |
timeFromServerAvailable
True, if the reading thread has received a message with an actual safe time. |
private double |
timeWindow
No submodel can advance its local simulation time more than this value ahead of another process. |
private java.util.LinkedList |
toCancel
The list of requests to cancel a local process. |
private java.lang.Object |
waitForOthersLock
His wait() and notify() methods are used to wait for message from server indicating that all submodels have finished current step of the distributes simulation. |
| Fields inherited from class cz.zcu.fav.kiv.jsim.JSimSimulation |
calendar, MODE_GUI_BATCH, MODE_GUI_INTERACTIVE, MODE_TXT, NEW_PROCESS_FORBIDDEN, NEW_QUEUE_FORBIDDEN, NEW_SEMAPHORE_FORBIDDEN, PRN_ERROR, PRN_MESSAGE, SIMULATION_IN_PROGRESS, SIMULATION_NOT_STARTED, SIMULATION_TERMINATED, time |
| Constructor Summary | |
CSSimulation(java.lang.String name,
int mode,
double whenUpdate,
java.lang.String host,
int port)
Creates a new class representing the simulation submodel. |
|
CSSimulation(java.lang.String name,
int mode,
java.lang.String host,
int port)
Creates a new class representing the simulation submodel. |
|
CSSimulation(java.lang.String name,
java.lang.String host,
int port)
Creates a new class representing the simulation submodel. |
|
| Method Summary | |
private void |
activateShadows()
Activates the processes, that should run in the next step of the distributed simulation. |
(package private) void |
addInternal(int ID,
CSProcess proc)
Adds references to the internal process. |
(package private) void |
addToCancel(int who,
java.lang.String message)
Adds a request to cancel a process to the list toCancel. |
(package private) void |
addToCSCalFinal(double when,
int whichOne,
java.lang.String message,
int fromWho)
Adds a specified new event to the final calendar. |
(package private) void |
addToCSCalTemp(double when,
int whichOne,
java.lang.String message,
int fromWho)
Adds a specified new event to the temporary calendar. |
(package private) void |
calendarJump(int whichOne,
java.lang.String message,
int fromWho)
Removes the first specified event from the final calender. |
private void |
carryOutCancel()
Removes requested events from temporary calendar. |
private void |
construct(java.lang.String host,
int port)
This method is called in constructor, in principle this is the constructor. |
private java.lang.String |
decode(java.lang.String line)
Decodes the incoming message. |
(package private) int |
getIDForCSProc()
Returns an unique number for every CSProcess in this submodel. |
int |
getInternalProcID(int who)
Returns the ID assigned by submodel of process specified by ID assigned by user. |
CSCalendarEvent |
getNextCEForMe(int ID)
Returns the event for the next execution of the specified process in this step of the distributed simulation. |
int |
getNextFromWhoForMe(int ID)
Returns the ID of the neighbour who has scheduled the next execution of the specified process in this step of the distributed simulation. |
java.lang.String |
getNextMessageForMe(int ID)
Returns the message for the next execution of the specified process in this step of the distributed simulation. |
double |
getNextTimeForMe(int ID)
Returns the time of next execution of the specified process in this step of the distributed simulation. |
(package private) java.io.PrintWriter |
getOut()
Returns the output channel for messages to the server or other submodels. |
(package private) CSProcess |
getProc(int ID)
Returns a reference to the specified process. |
(package private) double |
getSafeTime()
Returns the last safe time from the server. |
private double |
getSafeTimeFromServer()
Waits for and returns the next safe time from the server. |
private double[] |
getTimesForOthers()
Goes through sorted temporary calendar and sets safe times for other submodels. |
private void |
changeCal()
Removes events for the next step of the distributed simulation (with time stamp smaller than the safe time from the server) from the temporary calendar and puts them to the final calendar. |
boolean |
isInternal(int ID)
True, if a process with specified ID is located in this submodel. |
private void |
othersReady()
Tells that the others has finished the current step of the distributed simulation too. |
(package private) boolean |
readFromServer()
Takes care of receiving of all messages from the sever. |
private void |
receiveBeginning(java.lang.String line)
Takes care of the beginning message. |
private void |
receiveCancel(java.lang.String line)
Takes care of receiving of a request to cancel a process. |
private void |
receiveDistance(java.lang.String line)
Takes care of receiving distances from a process to other submodels. |
private void |
receiveMessage(java.lang.String line)
Takes care of receiving of a message from a neighbour. |
private void |
receiveSafeTime(java.lang.String line)
Takes care of receiving of the safe time from the server. |
private void |
sendTimesForOthers(double[] timesForOthers)
Sends to the server the safe times for other submodels. |
void |
simulate(double maxTime)
Executes the simulation. |
boolean |
somethingForMe(int ID)
Returns true, if there is some event for the specified process in this step of the distributed simulation. |
private void |
waitForDistances()
Waits untill distances from all processes to all submodels are received. |
private void |
waitForOthers()
Sends to the server a message, that this submodel has finished the current step of the distributed simulation and waits for the others. |
| Methods inherited from class cz.zcu.fav.kiv.jsim.JSimSimulation |
addEntryToCalendar, addProcess, addQueue, addSemaphore, deleteEntriesInCalendar, deleteProcess, error, getCurrentTime, getFreeProcessNumber, getFreeQueueNumber, getFreeSemaphoreNumber, getGraphicLock, getChange, getName, getNumber, getNumberOfProcesses, getNumberOfQueues, getNumberOfSemaphores, getObjectsToBeDisplayed, getRunningProcess, getSimulationMode, getSimulationState, getStepLock, getTalking, getTalkStream, getWaitingForWindowClosure, getWindowClosureLock, changeTalkStream, isRunningGUI, message, messageNoNL, printString, runGUI, setTalking, shutdown, step, switchToNobody, talk, talk, talk, talk, talk, talk, talk, talk, talk, waitForWindowClosure, windowIsClosing |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private int ID
private java.net.Socket socket
private java.io.PrintWriter out
private java.io.BufferedReader in
private CSReadingThread readT
private java.lang.String remoteERROR
private java.lang.Object distanceLock
private boolean distancesReceived
private int counterOfDist
private double[][] distances
private java.lang.Object safeTimeLock
private boolean timeFromServerAvailable
private double lastTimeFromServer
private java.lang.Object waitForOthersLock
private int numberOfProc
private int numberOfSimul
private double timeWindow
private int numberOfInternalProc
private java.util.ArrayList internalProc
private java.util.HashMap internalProcIDs
private java.util.LinkedList calFinal
private java.util.LinkedList calTemp
private java.util.LinkedList toCancel
| Constructor Detail |
public CSSimulation(java.lang.String name,
java.lang.String host,
int port)
throws cz.zcu.fav.kiv.jsim.JSimInvalidParametersException
name - String The name of this submodel.host - String The address of the server.port - int The port is the server connected to.
public CSSimulation(java.lang.String name,
int mode,
java.lang.String host,
int port)
throws cz.zcu.fav.kiv.jsim.JSimInvalidParametersException
name - String The name of this submodel.mode - int The simulation mode. Possible values are JSimSimulation.MODE_TXT, JSimSimulation.MODE_GUI_BATCH.host - String The address of the server.port - int The port is the server connected to.
public CSSimulation(java.lang.String name,
int mode,
double whenUpdate,
java.lang.String host,
int port)
throws cz.zcu.fav.kiv.jsim.JSimInvalidParametersException
name - String The name of this submodel.mode - int The simulation mode. Possible values are JSimSimulation.MODE_TXT, JSimSimulation.MODE_GUI_BATCH.whenUpdate - double A simulation time interval after which the GUI output will be updated.host - String The address of the server.port - int The port is the server connected to.| Method Detail |
private final void construct(java.lang.String host,
int port)
host - String The address of the server.port - int The port is the server connected to.
public final void simulate(double maxTime)
throws CSRemoteException,
cz.zcu.fav.kiv.jsim.JSimMethodNotSupportedException,
cz.zcu.fav.kiv.jsim.JSimTooManyProcessesException,
cz.zcu.fav.kiv.jsim.JSimInvalidParametersException,
cz.zcu.fav.kiv.jsim.JSimSimulationAlreadyTerminatedException,
cz.zcu.fav.kiv.jsim.JSimSecurityException
maxTime - double The simulation time till the user wish to simulate.
CSRemoteException - Means failure of other submodel.
cz.zcu.fav.kiv.jsim.JSimMethodNotSupportedException
cz.zcu.fav.kiv.jsim.JSimTooManyProcessesException
cz.zcu.fav.kiv.jsim.JSimInvalidParametersException
cz.zcu.fav.kiv.jsim.JSimSimulationAlreadyTerminatedException
cz.zcu.fav.kiv.jsim.JSimSecurityExceptionprivate final double getSafeTimeFromServer()
private final double[] getTimesForOthers()
private final void waitForOthers()
private final void waitForDistances()
final void calendarJump(int whichOne,
java.lang.String message,
int fromWho)
whichOne - int Whos event should be removed.message - String What message has this event.fromWho - int Who has scheduled this event.private final void changeCal()
private final void carryOutCancel()
private final void activateShadows()
private final void sendTimesForOthers(double[] timesForOthers)
timesForOthers - double[] Safe times for other submodels.final double getSafeTime()
final void addToCSCalTemp(double when,
int whichOne,
java.lang.String message,
int fromWho)
final void addToCSCalFinal(double when,
int whichOne,
java.lang.String message,
int fromWho)
final void addToCancel(int who,
java.lang.String message)
who - int Events of what process should be canceled.message - String Only events with this message will be canceled.final int getIDForCSProc()
public final boolean isInternal(int ID)
final void addInternal(int ID,
CSProcess proc)
ID - int ID of beeing inserted process.proc - CSProcess Reference to him.public final int getInternalProcID(int who)
who - int ID assigned by user.
final CSProcess getProc(int ID)
ID - int Local ID of process.final java.io.PrintWriter getOut()
public final boolean somethingForMe(int ID)
ID - int Local ID assigned by submodel.public final double getNextTimeForMe(int ID)
ID - int Local ID assigned by submodel.public final java.lang.String getNextMessageForMe(int ID)
ID - int Local ID assigned by submodel.public final int getNextFromWhoForMe(int ID)
ID - int Local ID assigned by submodel.public final CSCalendarEvent getNextCEForMe(int ID)
ID - int Local ID assigned by submodel.private final java.lang.String decode(java.lang.String line)
private final void receiveBeginning(java.lang.String line)
line - String A message with ID of this submodel, number of process, number of submodels and time window.private final void receiveSafeTime(java.lang.String line)
line - String A message with safe time from server.private final void receiveMessage(java.lang.String line)
line - String A message with specification of a process that a neighbour wish to activate.private final void receiveDistance(java.lang.String line)
line - String A message with distances from a process to other submodels.private final void othersReady()
private final void receiveCancel(java.lang.String line)
line - String A message with requested ID and message.final boolean readFromServer()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||