The Server Modules

  The ServerDaemon class implements a Daemon thread that has the following tasks:
 
  1. Listen on a specific port and get the clients' requests from this port.
  2. Control the number of handler threads that are used to handle the clients' requests.
The ServerDaemon creates a server socket using the ServerSocket class and waits for requests on this socket. The ServerDaemon holds the clients' requests in a queue (connections queue). Each time a request is received, the ServerDaemon puts the request in a connections queue, and waits for the next request. Actually, the ServerSocket itself has an internal connections queue and next connection is returned by invoking the ServerSocket accept method (if the queue is empty - wait for a session request). We created our own connections queue to increase the server throughput. While the ServerDaemon creates the handler threads and adjusts their number, the working handler threads can get session requests from the connections queue and handle them.

The ServerDaemon is desinged to keep an optimal number of live handler threads. If there are no more available handler threads to handle the session requests from the connections queue, the ServerDaemon creates more handler threads. If a handler thread waits more than 5 seconds for a connection it dies, so there are no unemployed threads in the ServerDaemon.

When the ServerDaemon is created, the server's port numbers and the supported methods are set. The ServerDaemon passes the supported methods to the handler threads and only the specified methods are handled. Basically there are two groups of methods: the standard HTTP methods (GET, PUT, HEAD, POST and DELETE) and the RSMC methods (SEND, RECEIVE, INFO and LOG).
In our server, we create two ServerDaemon threads. The first thread handles only valid HTTP requests and is intended to serve the clients requests. The second thread handles only valid RSMC commands and intended for communication with the manager process.
 

The ServerHandler class implements the request handler threads. The handler threads are created by one of the daemons. An handler thread knows its daemon and handles only its supported methods (HTTP or RSMC). The handler takes a connection from the daemon's connections queue and handles the requests in this connection. There might by more than one request per connection (when the client asks for Keep-Alive connection), in multi-request case the same handler will handle all the requests for the connection. The handler uses the Request and Response classes to simplify the request and response parsing. The handler invokes the proper request method (according to the request)  in the HttpMethods or RsmcMethods classes. After an handler have finished to handle all the requests in his connection, it waits up to 5 seconds for another connection. After this timeout, the handler thread dies because there are no more connections to handle and the handler is probably unneeded in the system. A timeout interval was taken to prevent handler threads to pop and die frequently - that will create extra load in the system.
Synchronization problems may occur when two threads try to access a certain file in certain modes (for example: one thread tries to read the file and another thread tries to write to the same file). These scenarios are very rare so in these cases, the server returns an error to the client.

 

The Request and Response modules are used to perform an easy parsing on the HTTP and RSMC requests and responses. The Request / Response can be parsed directly from the input stream or built from the Request / Response attributes. The Request and Response classes provide a powerfull interface to get and set all the required information.
These classes support:  

        The Server Properties module

The ServerProperties module is used to hold the server's configuration. Server configuration includes root path, ports, operation mode etc.. .This information is saved on a configuration file and when the server is loaded it uses the ServerProperties module
to get the information. When the configuration changes it is saved by this moudle. All the modules are using the ServerProperties module to obtain the current server configuration.
 
 

        The File Properties module

The FileProperties module is used to save the properties of each file in the server (requests number, no-cache etc..). There is a properties file in each directory that contains the properties of all the files in this directory. The FileProperties module is used to get and set the properties of the files.
 
 

        The Log File module

The LogFile moudle is used to save all the transactions executed by the server. The log file can be retrieved by the manager by invoking the LOG RSMC method of the Server module.
 
 

        The HttpMethods and RsmcMethods modules

These modules implements the HTTP and RSMP protocols.