cz.zcu.fav.kiv.cs
Class CSSimulation

java.lang.Object
  extended bycz.zcu.fav.kiv.jsim.JSimSimulation
      extended bycz.zcu.fav.kiv.cs.CSSimulation

public class CSSimulation
extends cz.zcu.fav.kiv.jsim.JSimSimulation

The main class describing the simulation submodel.

Version:
2.0
Author:
Antonin Kunes

Field Summary
 
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
 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.
 boolean isInternal(int ID)
          True, if a process with specified ID is located in this submodel.
 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.
 
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
 

Constructor Detail

CSSimulation

public CSSimulation(java.lang.String name,
                    java.lang.String host,
                    int port)
             throws cz.zcu.fav.kiv.jsim.JSimInvalidParametersException
Creates a new class representing the simulation submodel. The simulation will run in the text (console) mode and no graphic output will be allowed.

Parameters:
name - String The name of this submodel.
host - String The address of the server.
port - int The port is the server connected to.

CSSimulation

public CSSimulation(java.lang.String name,
                    int mode,
                    java.lang.String host,
                    int port)
             throws cz.zcu.fav.kiv.jsim.JSimInvalidParametersException
Creates a new class representing the simulation submodel. According to the simulation mode specified as a parameter, it will / will not be allowed to use graphic output later.

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

CSSimulation

public CSSimulation(java.lang.String name,
                    int mode,
                    double whenUpdate,
                    java.lang.String host,
                    int port)
             throws cz.zcu.fav.kiv.jsim.JSimInvalidParametersException
Creates a new class representing the simulation submodel. According to the simulation mode specified as a parameter, it will / will not be allowed to use graphic output later.

Parameters:
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

simulate

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
Executes the simulation. Repeatedly calls method step() from J-Sim. At first are simulated events with time stamp 0.0 and one JSimProcess is scheduled for time maxTime + 1. It ensures, that method step() will never terminate the simulation because of empty calendar. Then are simulated all steps of the distributed simulation. In the beginning of the next step we have to wait for others till they finish the current step too. Then we have to wait for the safe time from the server. It means the ammount of simulation time, we will simulate in the next step.

Parameters:
maxTime - double The simulation time till the user wish to simulate.
Throws:
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.JSimSecurityException

isInternal

public final boolean isInternal(int ID)
True, if a process with specified ID is located in this submodel.


getInternalProcID

public final int getInternalProcID(int who)
Returns the ID assigned by submodel of process specified by ID assigned by user.

Parameters:
who - int ID assigned by user.
Returns:
int Local ID assigned by submodel.

somethingForMe

public final boolean somethingForMe(int ID)
Returns true, if there is some event for the specified process in this step of the distributed simulation.

Parameters:
ID - int Local ID assigned by submodel.

getNextTimeForMe

public final double getNextTimeForMe(int ID)
Returns the time of next execution of the specified process in this step of the distributed simulation.

Parameters:
ID - int Local ID assigned by submodel.

getNextMessageForMe

public final java.lang.String getNextMessageForMe(int ID)
Returns the message for the next execution of the specified process in this step of the distributed simulation.

Parameters:
ID - int Local ID assigned by submodel.

getNextFromWhoForMe

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

Parameters:
ID - int Local ID assigned by submodel.

getNextCEForMe

public final CSCalendarEvent getNextCEForMe(int ID)
Returns the event for the next execution of the specified process in this step of the distributed simulation.

Parameters:
ID - int Local ID assigned by submodel.