simulator
Class Connection

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

class Connection
extends java.lang.Thread

This is the class that mantains the connection between the client and server and executes the comunication with it


Field Summary
protected  Semaphore[] availableCells
          This is the array of semaphore that contains the available resources of the index-array type (It's a reference to Server's)
static java.lang.String availableCommands
          Contains the list of commands available for clients.
protected  java.net.Socket client
          Contains the socket that cliet uses to comunicate
protected  java.net.InetAddress clientAddress
          Contains the IP client address
protected  java.util.Hashtable clientCommands
          Contains the available client commands; the hash key is the name of the command, the value is an ClientCommand object
protected  java.lang.String clientName
          Contains a string name of the client
protected  int clientPort
          Contais the local client port for connecting to server
protected  java.util.Hashtable connectedUsers
          Contains the list of client users that are connected
protected  int dimQueue
          Max dimension for the queue
protected  ProcessesHandler GP
          Contains the time handler of processes
protected  java.io.DataInputStream in
          This is the input client-socket stream
protected  java.lang.String line
          This contains a line read by the socket
protected  java.util.Hashtable nodesList
          Contains the list of nodes of virtual world
protected  java.io.PrintStream out
          This is the output client-socket stream
protected  Semaphore[] presentMessage
          This is the array of semaphore that contains the occupied resources of the index-array type (It's a reference to Server's)
protected  java.util.Hashtable processesList
          Contains the list of agents processes (It's a reference to Server's)
protected  Queue[] processesQueue
          A queue of message changed by client agents and the server (It's a reference to Server's)
protected  ServerAmbient ServAmb
          Contains the process for serving an ambient (It's a reference to Server's)
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 (It's a reference to Server's)
protected  SendVRML SV
          This is the thread that updates the simulator state and send the VRML view to the 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
Connection(java.net.Socket client_socket, Server server)
          initialize the streams and start thread
 
Method Summary
 void broadcast(java.lang.String s)
          Send a string command to all the connected users
static void fail(java.lang.Exception e, java.lang.String msg)
          Print fail information and exit from server program
 void logActivity(java.lang.String message)
          Print log activities information
 void logException(java.lang.Exception e, java.lang.String message)
          Print exception information
 java.lang.String readFile(java.lang.String fileName)
          Read a file and return a string rappresentation of it
 void run()
          This is the thread that reads command from socket and runs them
private  boolean runCommand(java.lang.String comm)
          Execute a command that a user client pass to it.
 java.lang.String whoString()
          Gets the names of the connected users
 
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

availableCommands

public static java.lang.String availableCommands
Contains the list of commands available for clients. It will be initilaized using clientCommands Hashtable.

client

protected java.net.Socket client
Contains the socket that cliet uses to comunicate

in

protected java.io.DataInputStream in
This is the input client-socket stream

out

protected java.io.PrintStream out
This is the output client-socket stream

clientAddress

protected java.net.InetAddress clientAddress
Contains the IP client address

clientPort

protected int clientPort
Contais the local client port for connecting to server

clientName

protected java.lang.String clientName
Contains a string name of the client

line

protected java.lang.String line
This contains a line read by the socket

clientCommands

protected java.util.Hashtable clientCommands
Contains the available client commands; the hash key is the name of the command, the value is an ClientCommand object

processesList

protected java.util.Hashtable processesList
Contains the list of agents processes (It's a reference to Server's)

ServAmb

protected ServerAmbient ServAmb
Contains the process for serving an ambient (It's a reference to Server's)

availableCells

protected Semaphore[] availableCells
This is the array of semaphore that contains the available resources of the index-array type (It's a reference to Server's)

presentMessage

protected Semaphore[] presentMessage
This is the array of semaphore that contains the occupied resources of the index-array type (It's a reference to Server's)

processesQueue

protected Queue[] processesQueue
A queue of message changed by client agents and the server (It's a reference to Server's)

dimQueue

protected int dimQueue
Max dimension for the queue

staticAmb

protected Ambient staticAmb
This is the abstract class to build your static ambient (It's a reference to Server's)

state

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

SV

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

GP

protected ProcessesHandler GP
Contains the time handler of processes

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
Constructor Detail

Connection

public Connection(java.net.Socket client_socket,
                  Server server)
initialize the streams and start thread
Method Detail

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

whoString

public java.lang.String whoString()
Gets the names of the connected users
Returns:
the string of all the connected users

run

public void run()
This is the thread that reads command from socket and runs them
Overrides:
run in class java.lang.Thread

logException

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

logActivity

public void logActivity(java.lang.String message)
Print log activities information
Parameters:
message - the message to print

broadcast

public void broadcast(java.lang.String s)
Send a string command to all the connected users
Parameters:
s - the string command to send

runCommand

private boolean runCommand(java.lang.String comm)
Execute a command that a user client pass to it. The string command are tokenized and passed to the appropriate ClientCommand object that is stored in the clientCommands hashtable.
Parameters:
comm - the string that rappresent the command
Returns:
true if we must exit from connection, false otherwise
See Also:
ClientCommand, Server.clientCommands

readFile

public java.lang.String readFile(java.lang.String fileName)
Read a file and return a string rappresentation of it
Parameters:
fileName - the string name of the file
Returns:
the string that contains the files