server
Class ConnectionHandlerThread

java.lang.Object
  extended by java.lang.Thread
      extended by server.ConnectionHandlerThread
All Implemented Interfaces:
java.lang.Runnable, DAO<java.lang.Long,java.io.Serializable>

public class ConnectionHandlerThread
extends java.lang.Thread
implements DAO<java.lang.Long,java.io.Serializable>

This class instantiates threads in charge of answering requests made via socket channels. It is the server side of the implementation of a DAO.

Author:
Fernando

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface server.DAO
ADD, DELETE, GET, HOST, PORT, SIZE, UPDATE
 
Constructor Summary
ConnectionHandlerThread(java.net.Socket newSocket, java.util.Map<java.lang.Long,java.io.Serializable> newDatabase)
          Creates a new handler.
 
Method Summary
 void add(java.lang.Long key, java.io.Serializable value)
          Adds a new Serializable object into the database.
 void delete(java.lang.Long key)
          Removes an object from the database.
 java.io.Serializable get(java.lang.Long key)
          Returns a reference to an object in the database.
 void run()
          Runs the thread that is in charge of answering client requests.
 int size()
          Informs the number of elements currently stored in the database.
 void update(java.lang.Long key, java.io.Serializable value)
          Updates an object in the database.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConnectionHandlerThread

public ConnectionHandlerThread(java.net.Socket newSocket,
                               java.util.Map<java.lang.Long,java.io.Serializable> newDatabase)
Creates a new handler.

Parameters:
newSocket - the network connection where this handler will be listening.
newDatabase - the database of students.
Method Detail

run

public final void run()
Runs the thread that is in charge of answering client requests.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

add

public final void add(java.lang.Long key,
                      java.io.Serializable value)
Adds a new Serializable object into the database.

Specified by:
add in interface DAO<java.lang.Long,java.io.Serializable>
Parameters:
key - the key of the new object.
value - the value that is going to be inserted into the database.

delete

public final void delete(java.lang.Long key)
Removes an object from the database.

Specified by:
delete in interface DAO<java.lang.Long,java.io.Serializable>
Parameters:
key - the id of the object that will be removed.

get

public final java.io.Serializable get(java.lang.Long key)
Returns a reference to an object in the database.

Specified by:
get in interface DAO<java.lang.Long,java.io.Serializable>
Parameters:
key - the id of the object that is being looked up.
Returns:
a serializable element. The return value is marked serializable because it will be sent through a network connection.

update

public final void update(java.lang.Long key,
                         java.io.Serializable value)
Updates an object in the database.

Specified by:
update in interface DAO<java.lang.Long,java.io.Serializable>
Parameters:
key - the id of the object that will be replaced.
value - the value of the new object.

size

public final int size()
Informs the number of elements currently stored in the database.

Specified by:
size in interface DAO<java.lang.Long,java.io.Serializable>
Returns:
an integer number.