cz.zcu.fav.kiv.cs
Class CSProcess

java.lang.Object
  extended bycz.zcu.fav.kiv.cs.CSProcess

public class CSProcess
extends java.lang.Object

One of the most importatnt classes for the user, he should extend this class, if he wants to describe a process of the distributed simulation.

Version:
2.0
Author:
Antonin Kunes

Field Summary
protected  CSSimulation parent
          The simulation submodel that this process is a part of.
 
Constructor Summary
CSProcess(java.lang.String name, CSSimulation parent, int ID, int[] neighbours, double[] timeToNeighbour)
          Creates the CSProcess and sends his description to the server.
 
Method Summary
protected  void activate(double when, int who)
          Schedules the specified neighbour for the specified time with null message.
protected  void activate(double when, int who, java.lang.String message)
          Schedules the specified neighbour for the specified time with the specified message.
protected  void cancel(int who, java.lang.String message)
          Cancel events of the specified process with the specified message.
protected  void cancelAll(int who)
          Cancel all events of the specified process.
protected  void csLife()
          The programmer should overwrite this method.
protected  void error(java.lang.String line)
          Prints out a text error message, either to the error output or to the simulation window.
protected  int getAutoID()
          Returns the local ID assigned by the submodel.
protected  int getFromWho()
          Returns an ID of a neighbour, who has me scheduled for now.
protected  int getID()
          Returns an ID specified by user.
protected  java.lang.String getMessage()
          Returns the actual message for this process in the current part of his life.
 java.lang.String getName()
          Returns the local ID assigned by the submodel.
protected  CSCalendarEvent getNextCE()
          Returns the event of my next execution in this step of the distributed simulation.
protected  int getNextFromWho()
          Returns the neighbour who has scheduled my next execution in this step of the distributed simulation.
protected  java.lang.String getNextMessage()
          Returns the message for my next execution in this step of the distributed simulation.
protected  double getNextTime()
          Returns the time of my next execution in this step of the distributed simulation.
protected  long getNumber()
          Returns the ID assigned by J-Sim.
protected  void hold(double howLong)
          Holds this process for the specified time with the null message.
protected  void hold(double howLong, java.lang.String message)
          Holds this process for the specified time with the specified message.
protected  void life()
          It's here only to tell the user, that this method is not used in CSProcess.
protected  void message(java.lang.String line)
          Prints out a text message, either to the standard output or to the simulation window.
protected  boolean somethingNext()
          Returns True, if there is a message for me in this step of the distributed simulation.
 void startAt(double when, java.lang.String message)
          Schedules the first execution of this process.
protected  void waitForNextMessage()
          Passivates the current process, he will be woken up with a new message for him.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

protected CSSimulation parent
The simulation submodel that this process is a part of.

Constructor Detail

CSProcess

public CSProcess(java.lang.String name,
                 CSSimulation parent,
                 int ID,
                 int[] neighbours,
                 double[] timeToNeighbour)
          throws cz.zcu.fav.kiv.jsim.JSimSimulationAlreadyTerminatedException,
                 cz.zcu.fav.kiv.jsim.JSimInvalidParametersException,
                 cz.zcu.fav.kiv.jsim.JSimTooManyProcessesException
Creates the CSProcess and sends his description to the server.

Parameters:
name - String Name of this process.
parent - CSSimulation Parent submodel.
ID - int ID of this process from the user.
neighbours - int[] Array of neigbours.
timeToNeighbour - double[] Distances to these neighbours.
Method Detail

csLife

protected void csLife()
The programmer should overwrite this method. Describes the body of this process.


life

protected final void life()
It's here only to tell the user, that this method is not used in CSProcess. Use csLife() instead.


waitForNextMessage

protected final void waitForNextMessage()
                                 throws cz.zcu.fav.kiv.jsim.JSimSecurityException
Passivates the current process, he will be woken up with a new message for him. If there is an event for current step, he will be holded, otherwise passivated and waiting for activation by a message from a neighbour.

Throws:
cz.zcu.fav.kiv.jsim.JSimSecurityException

hold

protected final void hold(double howLong)
                   throws cz.zcu.fav.kiv.jsim.JSimSecurityException
Holds this process for the specified time with the null message.

Parameters:
howLong - double The time how long should I sleep.
Throws:
cz.zcu.fav.kiv.jsim.JSimSecurityException

hold

protected final void hold(double howLong,
                          java.lang.String message)
                   throws cz.zcu.fav.kiv.jsim.JSimSecurityException
Holds this process for the specified time with the specified message. If he wants to be woken up in the current step of the distributed simulation, his event will be inserted to the final calendar and he will be holded to the time of his next event, otherwise he will be passivated and his event will be inserted to the temporary calendar, so he will be activated in some of next steps in the future. With JSimProcess you can be sure, that a holded process won't run earlier than at current time + howLong, but here a holded process can be woken up earlier by a message from a neighbour. You can be sure only that he will be surely woken up at specified time with specified message.

Parameters:
howLong - double The time how long should I sleep.
message - String The message I will have after sleep.
Throws:
cz.zcu.fav.kiv.jsim.JSimSecurityException

startAt

public final void startAt(double when,
                          java.lang.String message)
                   throws cz.zcu.fav.kiv.jsim.JSimSecurityException,
                          cz.zcu.fav.kiv.jsim.JSimInvalidParametersException,
                          CSSecurityException
Schedules the first execution of this process.

Parameters:
when - double When
message - String With what message.
Throws:
CSSecurityException - This process has already started.
cz.zcu.fav.kiv.jsim.JSimSecurityException
cz.zcu.fav.kiv.jsim.JSimInvalidParametersException

activate

protected final void activate(double when,
                              int who)
                       throws CSSecurityException
Schedules the specified neighbour for the specified time with null message.

Throws:
CSSecurityException - Attempt to activate wrong neighbour and/or at wrong time.

activate

protected final void activate(double when,
                              int who,
                              java.lang.String message)
                       throws CSSecurityException
Schedules the specified neighbour for the specified time with the specified message. If the neighbour is internal, it means it is located in the same submodel as this process, no message to the server is sent and his event is only inserted to the temporary calender.

Parameters:
when - double When should he be woken up.
who - int Who is this message for.
message - String What message will he have in scheduling part of life.
Throws:
CSSecurityException - Attempt to activate a wrong neighbour and/or at a wrong time.

cancelAll

protected final void cancelAll(int who)
Cancel all events of the specified process. They will be canceled after this step of the distributed simulation.

Parameters:
who - int ID of requested process

cancel

protected final void cancel(int who,
                            java.lang.String message)
Cancel events of the specified process with the specified message. They will be canceled after this step of the distributed simulation.

Parameters:
who - int ID of requested process
message - String Requested messages

message

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


error

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


getMessage

protected final java.lang.String getMessage()
Returns the actual message for this process in the current part of his life.


getFromWho

protected final int getFromWho()
Returns an ID of a neighbour, who has me scheduled for now.


getID

protected final int getID()
Returns an ID specified by user.


getAutoID

protected final int getAutoID()
Returns the local ID assigned by the submodel.


getNumber

protected final long getNumber()
Returns the ID assigned by J-Sim.


getName

public final java.lang.String getName()
Returns the local ID assigned by the submodel.


somethingNext

protected final boolean somethingNext()
Returns True, if there is a message for me in this step of the distributed simulation.


getNextTime

protected final double getNextTime()
Returns the time of my next execution in this step of the distributed simulation.


getNextMessage

protected final java.lang.String getNextMessage()
Returns the message for my next execution in this step of the distributed simulation.


getNextFromWho

protected final int getNextFromWho()
Returns the neighbour who has scheduled my next execution in this step of the distributed simulation.


getNextCE

protected final CSCalendarEvent getNextCE()
Returns the event of my next execution in this step of the distributed simulation.