Server processing for an individual client request. When the voter
supplies an election name, the client code makes a TCP connection
to the server. The server instantiates a Worker thread that
processes client's request.
<br/><br/>
The worker thread expects to get a request for the candidates in an
election, for which it returns the list of candidates. Then it expects
a vote for the election, which it processes and then acknowledges.
Any deviation from the expected message format, or invalid message
contents (closed election, etc) results in an error reply being sent.
<br/><br/>
All the operations on elections are done by calling methods on the
<code cref="Election">Election</code> member variable, which is set at thread initialisation time.
The server handles concurrency control between multiple workers at
the level of individual elections.
| |
 |
Members |
Description |
|
| |
|
server |
|
|
| |
|
socket |
|
|
| |
|
stm |
Objected wrapped around the socket to communicate with the server
|
|
| |
|
Worker |
Constructor. Initializes the server, socket, and creates a
NetworkStream to communicate with the client.
|
|
| |
|
run |
Method called by Network object to start processing client's
request and record the vote via initialized socket.
|
|
| |
|
processCandidatesRequest |
Process the message with <c>QUERY_CANDIDATES</c> request type, and
name of election, checks if this election exists, and responds
with the list of candidates. If the election is not defined or
closed, <c>BAD_ELECTION</c> message is sent back to the client.
|
|
| |
|
processVoteRequest |
Process the message with <c>SEND_VOTE</c> request type,
name of election, and the vote. Casts the vote and sends the
<c>ACK_VOTE</c> message back to the client. If the election is
closed, doesn't exist, or the candidate is not part of the list,
an error message is sent back to the client
|
|