cz.zcu.fav.kiv.cs
Class CSServerThread

java.lang.Object
  extended byjava.lang.Thread
      extended bycz.zcu.fav.kiv.cs.CSServerThread
All Implemented Interfaces:
java.lang.Runnable

public class CSServerThread
extends java.lang.Thread

Takes care of communication between one submodel and server.

Version:
2.0
Author:
Antonin Kunes

Field Summary
private  java.net.Socket client
          The socket for a communication between the server and the submodel.
private  int ID
          This ID is the same as ID of submodel, that is to that thread connected.
private  java.io.BufferedReader in
          The input channel.
private  java.io.PrintWriter[] outs
          Array of output channels to all submodels.
private  CSServer server
          The server which is common for all threads, offers common methods.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CSServerThread(int ID, java.net.Socket client, CSServer server)
          Creates the new thread, taking care of a communication between the submodel and the server.
 
Method Summary
private  void readDistance(java.lang.String line)
          Inserts distances from one process to his neighbours into cache.
private  void readSafeTimes(java.lang.String line)
          Takes care of receiving of the safe times for other submodels from the submodel.
 void run()
          Reads messages from the submodel.
private  void sendCancel(java.lang.String line)
          Takes care of sending of a request to cancel a process.
private  void sendMessage(java.lang.String line)
          Takes care of sending of a message from the submodel to a neighbour.
private  void simFinished()
          This method is called, when the submodel has finished his simulation.
 
Methods inherited from class java.lang.Thread
activeCount, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, checkAccess, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ID

private int ID
This ID is the same as ID of submodel, that is to that thread connected.


client

private java.net.Socket client
The socket for a communication between the server and the submodel.


server

private CSServer server
The server which is common for all threads, offers common methods.


in

private java.io.BufferedReader in
The input channel. Receives messages from the submodel.


outs

private java.io.PrintWriter[] outs
Array of output channels to all submodels.

Constructor Detail

CSServerThread

public CSServerThread(int ID,
                      java.net.Socket client,
                      CSServer server)
Creates the new thread, taking care of a communication between the submodel and the server. Sends to the submodel number of processes, number of submodels and time window.

Parameters:
client - Socket Socket for this connection
server - CSServer The main server, offering common methods.
Method Detail

run

public void run()
Reads messages from the submodel.


simFinished

private final void simFinished()
This method is called, when the submodel has finished his simulation. It's necessary to fill in the row in the matrix with safe times, representing safe times from this submodel for others with Infinity.


readSafeTimes

private void readSafeTimes(java.lang.String line)
Takes care of receiving of the safe times for other submodels from the submodel.

Parameters:
line - String A message from the submodel with safe times for others.

sendMessage

private final void sendMessage(java.lang.String line)
Takes care of sending of a message from the submodel to a neighbour.

Parameters:
line - String A message from the submodel to the other.

readDistance

private void readDistance(java.lang.String line)
Inserts distances from one process to his neighbours into cache. From this cache will be filled out the distance matrix.

Parameters:
line - String A message from the submodel with distances from one process to his neigbours.

sendCancel

private final void sendCancel(java.lang.String line)
Takes care of sending of a request to cancel a process.

Parameters:
line - String A message describing what events of what process should be canceled.