Server
Class SocketThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--Server.SocketThread
All Implemented Interfaces:
java.lang.Runnable

public final class SocketThread
extends java.lang.Thread

A thread responsible for handling all of the traffic of an open socket


Field Summary
private  boolean isAfterOpenCommand
          A predicate that indicates whether we are after the open command
private  SessionWrapper sessionWrapper
          The session thread associated with this object
private  java.net.Socket socket
          The socket associated with this socket thread.
private  java.io.BufferedReader sockIn
          An input for the socket
private  java.io.BufferedWriter sockOut
          An output for the socket
private  User user
          The user associated with this socket thread
 
Fields inherited from class java.lang.Thread
contextClassLoader, daemon, eetop, group, inheritableThreadLocals, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadLocals, threadQ
 
Constructor Summary
(package private) SocketThread(java.net.Socket socket)
          A constructor that that associates a given socket with this object
 
Method Summary
(package private)  Session doAddSession(Session newSession)
          Retrieve or create a session
(package private)  void doAddUser(User newUser, Session session)
          Retrieve or create a user
private  void doGetReaderWriter()
          A procedure that sets the global 'sockIn' variable to wrap the socket InputStreamReader, and 'sockOut' to wrap the socket OutputStreamWriter.
(package private)  User doIdentifyUser()
          Identify the user
private  void finish()
           
private  SessionWrapper getSessionWrapper()
          Returns the session thread associated with this object
 java.io.BufferedWriter getSockOut()
          Returns a BufferedWriter output for the associated socket
 User getUser()
          Returns the user associated with this socket thread
private  void handleLine(java.lang.String line)
          Handle a given input line from the network; If we have identified a user-session matching, send it to the session member, otherwise, take care of authentication and book-keeping.
private  void handleOpenCommand(java.lang.String line)
          Handle an open command
(package private)  Session parseOpenCommand(java.lang.String line)
          A front-end to parse an open command
 void run()
          A front-end for this thread; 1.
private  void setSessionThread(SessionWrapper thread)
          Sets the session thread associated with this object
private  void setUser(User user)
          Sets the user associated with this socket thread
 
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

sockOut

private java.io.BufferedWriter sockOut
An output for the socket

sockIn

private java.io.BufferedReader sockIn
An input for the socket

user

private User user
The user associated with this socket thread

socket

private final java.net.Socket socket
The socket associated with this socket thread. It is being initialized once in the constructor.

isAfterOpenCommand

private boolean isAfterOpenCommand
A predicate that indicates whether we are after the open command

sessionWrapper

private SessionWrapper sessionWrapper
The session thread associated with this object
Constructor Detail

SocketThread

SocketThread(java.net.Socket socket)
A constructor that that associates a given socket with this object
Parameters:
socket - The socket to associate
Method Detail

doGetReaderWriter

private final void doGetReaderWriter()
A procedure that sets the global 'sockIn' variable to wrap the socket InputStreamReader, and 'sockOut' to wrap the socket OutputStreamWriter.

doAddUser

void doAddUser(User newUser,
               Session session)
Retrieve or create a user
Parameters:
newUser - The temporary user instance
session - The session to add the user to

doAddSession

Session doAddSession(Session newSession)
Retrieve or create a session
Parameters:
newSession - The temporary session instance
Returns:
The session retrieved or created

doIdentifyUser

User doIdentifyUser()
Identify the user
Returns:
The user instance

parseOpenCommand

Session parseOpenCommand(java.lang.String line)
A front-end to parse an open command
Parameters:
line - The open command string
Returns:
The parsed session

handleOpenCommand

private void handleOpenCommand(java.lang.String line)
Handle an open command
Parameters:
line - The open command string

handleLine

private final void handleLine(java.lang.String line)
Handle a given input line from the network; If we have identified a user-session matching, send it to the session member, otherwise, take care of authentication and book-keeping.
Parameters:
line - The line to handle

run

public void run()
A front-end for this thread; 1. Infinitely block until a line is recieved over the network. 2. Handle the line.
Overrides:
run in class java.lang.Thread

finish

private void finish()

getUser

public User getUser()
Returns the user associated with this socket thread
Returns:
the user associated with this socket thread

setUser

private void setUser(User user)
Sets the user associated with this socket thread
Parameters:
user - The user to associate with this socket thread

getSockOut

public java.io.BufferedWriter getSockOut()
Returns a BufferedWriter output for the associated socket
Returns:
a BufferedWriter output for the associated socket

getSessionWrapper

private SessionWrapper getSessionWrapper()
Returns the session thread associated with this object
Returns:
the session thread associated with this object

setSessionThread

private void setSessionThread(SessionWrapper thread)
Sets the session thread associated with this object
Parameters:
thread - The thread to save