simulator
Class Server

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--simulator.Server

abstract class Server
extends java.lang.Thread

Implements a base function of a server as a thread. To use this class, you must extend it like this:

     class MyServer extends Server{
       public MyServer(String argv[]) {
         super(argv);   // this is the constructor that call the super
       }

       protected void init() {
          // initialize all undefined variable
          about="Server ...";
          resolutionTime=100;
          printerTime=100;
          agentsTime=300;
          timeToSend=4;
          GSV=new MySendVRML; //this is the implementation of GenericSendVRML
          GSA=new MyServerAmbient; //this is the implementation of GenericServerAmbient
          staticAmb=new MyAmbient(); //this is the implementation of Ambient
          ExitClientCommand C1=new ExitClientCommand();
          clientCommands.put(C1.getName(),C1); //insert the client commands
          ...
       }

       public static void main(String[] argv){
         new MyServer(argv);
       }
     }
 

How you must see your class must only initilize all the undefined variables and creates your object that performes your commands (refer to the other abstract class for details) for the simulation.

See Also:
SendVRML, GenericSendVRML, ServerAmbient, GenericServerAmbient, Connection, Ambient

Field Summary
static java.lang.String about
          This is undefined string avoided to contain the about information of server program.
static int agentsTime
          This is undefined integer avoided to contain the time to resume the agents.
protected  Semaphore[] availableCells
          This is the array of semaphore that contains the available resources of the index-array type
protected  java.util.Hashtable clientCommands
          Contains the list of commands that the client can execute.
protected  java.util.Hashtable connectedUsers
          Contains the list of client users that are connected
static int DEFAULT_PORT
           
static int dimQueue
          Max dimension for the queue
protected  ProcessesHandler GP
          Contains the time handler of processes
static GenericServerAmbient GSA
          This is undefined process that is to be used with ServerAmbient
static GenericSendVRML GSV
          This is undefined process that is to be used with SendVRML
static int maxNumProc
           
protected  java.util.Hashtable nodesList
          Contains the list of nodes of virtual world
protected  int port
          contains the port number uses to create a connection with socket
protected  Semaphore[] presentMessage
          This is the array of semaphore that contains the occupied resources of the index-array type
static int printerTime
          This is undefined integer avoided to contain the time to resume the printer process.
protected  java.util.Hashtable processesList
          Contains the list of agents processes
protected  Queue[] processesQueue
          A queue of message changed by client agents and the server
static int realTime
          This variable set the real time in the simulation with a 1 value.
static int resolutionTime
          This is undefined integer avoided to contain the resolution of the time processes handler
protected  ServerAmbient SA
          Contains the process for serving an ambient
protected  java.net.ServerSocket server_socket
          Contains the server socket istance to permit the comunication
protected  java.util.Hashtable state
          Contains instance of the actual states of agents
protected  Ambient staticAmb
          This is the abstract class to build your static ambient
protected  SendVRML SV
          This is the thread that updates the simulator state and send the VRML view to the client
 int timeToSend
          Indicate how many times we must attend before send a vrml scene to client.
 
Fields inherited from class java.lang.Thread
contextClassLoader, daemon, eetop, group, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadQ, values
 
Constructor Summary
Server(java.lang.String[] args)
          Analize the command passes as string
 
Method Summary
static void fail(java.lang.Exception e, java.lang.String msg)
          Print fail information and exit from server program
static void helpScreen()
          Display a help screen
protected abstract  void init()
          This abstract method must be implemented by the derived class.
 void run()
          Execute the server thread: listen for a client connection and made it The priority of this thread is set to MIN_PRIORITY by the default contructor.
 
Methods inherited from class java.lang.Thread
, activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, exit, getContextClassLoader, getName, getPriority, getThreadGroup, init, interrupt, interrupt0, interrupted, isAlive, isDaemon, isInterrupted, isInterrupted, join, join, join, nextThreadNum, registerNatives, resume, resume0, setContextClassLoader, setDaemon, setName, setPriority, setPriority0, sleep, sleep, start, stop, stop, stop0, suspend, suspend0, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

about

public static java.lang.String about
This is undefined string avoided to contain the about information of server program.

realTime

public static int realTime
This variable set the real time in the simulation with a 1 value. If the value insert is better than the simualtion is slow down, else the simulation is fast. For example if resolutionTime is 100msec. and this is set to 3, this implies that we update the simulation event us 100msec was departed, but this is made in 300msec, so slow system can execute correctly the simulation even if no real time is performed.

resolutionTime

public static int resolutionTime
This is undefined integer avoided to contain the resolution of the time processes handler

printerTime

public static int printerTime
This is undefined integer avoided to contain the time to resume the printer process. It must be multiple of resolutionTime variable.

agentsTime

public static int agentsTime
This is undefined integer avoided to contain the time to resume the agents. It must be multiple of resolutionTime variable.

timeToSend

public int timeToSend
Indicate how many times we must attend before send a vrml scene to client. So the effective time to attend before send is: printerTime*timeToSend
See Also:
ProcessesHandler.printerTime

GSV

public static GenericSendVRML GSV
This is undefined process that is to be used with SendVRML

GSA

public static GenericServerAmbient GSA
This is undefined process that is to be used with ServerAmbient

DEFAULT_PORT

public static final int DEFAULT_PORT

maxNumProc

public static final int maxNumProc

dimQueue

public static final int dimQueue
Max dimension for the queue

port

protected int port
contains the port number uses to create a connection with socket

server_socket

protected java.net.ServerSocket server_socket
Contains the server socket istance to permit the comunication

connectedUsers

protected java.util.Hashtable connectedUsers
Contains the list of client users that are connected

nodesList

protected java.util.Hashtable nodesList
Contains the list of nodes of virtual world

processesList

protected java.util.Hashtable processesList
Contains the list of agents processes

SA

protected ServerAmbient SA
Contains the process for serving an ambient

GP

protected ProcessesHandler GP
Contains the time handler of processes

SV

protected SendVRML SV
This is the thread that updates the simulator state and send the VRML view to the client

availableCells

protected Semaphore[] availableCells
This is the array of semaphore that contains the available resources of the index-array type

presentMessage

protected Semaphore[] presentMessage
This is the array of semaphore that contains the occupied resources of the index-array type

processesQueue

protected Queue[] processesQueue
A queue of message changed by client agents and the server

staticAmb

protected Ambient staticAmb
This is the abstract class to build your static ambient

state

protected java.util.Hashtable state
Contains instance of the actual states of agents

clientCommands

protected java.util.Hashtable clientCommands
Contains the list of commands that the client can execute. It must be initiailzed by you when derived this class.
Constructor Detail

Server

public Server(java.lang.String[] args)
Analize the command passes as string
Parameters:
args - string that contain the server initial parameters
Method Detail

init

protected abstract void init()
This abstract method must be implemented by the derived class. It is called by the Server constructor to permits to define the elements that are not initialized. So the derived class may have a constructor that calls Server's and the late bilding process calls your just defined init.

helpScreen

public static void helpScreen()
Display a help screen

run

public void run()
Execute the server thread: listen for a client connection and made it The priority of this thread is set to MIN_PRIORITY by the default contructor.
Overrides:
run in class java.lang.Thread

fail

public static void fail(java.lang.Exception e,
                        java.lang.String msg)
Print fail information and exit from server program
Parameters:
e - the exception that fails server
msg - the message to print in err file