Class Server

java.lang.Object
  |
  +--Server

public class Server
extends java.lang.Object

The actual code for operating on elections: maintains the collection of elections and has methods which Worker threads and the election server manager can call. This class is effectively immutable: all operations are passed through a mapping of election names to Election objects, and the mapping does not change once the server is up and running. Concurrency control is on individual elections, since we don't need concurrency control on the server itself.

Operations called by the election server manager have a display argument, which is how they display results (i.e. no return values); they may also throw a DisplayException to display an error. Operations called by worker threads throw exceptions to indicate errors, and return results normally.


Field Summary
 short port
          Port to open server socket on.
 
Method Summary
 void closeElection(java.lang.String name, ServerDisplay display)
          Close the specified election, called by election server manager only.
 void displayElections(ServerDisplay display)
          Show the list of elections on the indicated display, called by election server manager only.
 java.util.LinkedList getCandidates(java.lang.String poll)
          Called by worker thread to get candidates for election "poll".
 java.util.LinkedList getElections()
          Called by worker thread to get a list of elections (not used).
 void openElection(java.lang.String name, ServerDisplay display)
          Open the specified election, called by election server manager only.
 void viewElection(java.lang.String poll, ServerDisplay display)
           
 void vote(java.lang.String poll, java.lang.String candidate)
          Called by worker thread to vote for a candidate for election "poll".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

port

public short port
Port to open server socket on.

Method Detail

openElection

public void openElection(java.lang.String name,
                         ServerDisplay display)
                  throws DisplayException,
                         UndefinedElectionException
Open the specified election, called by election server manager only. Resets vote counts for the election to zero.

DisplayException
UndefinedElectionException

closeElection

public void closeElection(java.lang.String name,
                          ServerDisplay display)
                   throws DisplayException,
                          UndefinedElectionException
Close the specified election, called by election server manager only.

DisplayException
UndefinedElectionException

viewElection

public void viewElection(java.lang.String poll,
                         ServerDisplay display)
                  throws DisplayException,
                         UndefinedElectionException
DisplayException
UndefinedElectionException

displayElections

public void displayElections(ServerDisplay display)
Show the list of elections on the indicated display, called by election server manager only.


getElections

public java.util.LinkedList getElections()
Called by worker thread to get a list of elections (not used).


getCandidates

public java.util.LinkedList getCandidates(java.lang.String poll)
                                   throws UndefinedElectionException,
                                          ElectionNotOpenException
Called by worker thread to get candidates for election "poll".

UndefinedElectionException
ElectionNotOpenException

vote

public void vote(java.lang.String poll,
                 java.lang.String candidate)
          throws ElectionNotOpenException,
                 UndefinedElectionException,
                 UndefinedCandidateException
Called by worker thread to vote for a candidate for election "poll".

ElectionNotOpenException
UndefinedElectionException
UndefinedCandidateException