triptracker.server
Class ClientHandler

java.lang.Object
  extended by triptracker.server.ClientHandler
Direct Known Subclasses:
GPSHandler, MapHandler

public abstract class ClientHandler
extends Object

Message handler for connected clients.


Field Summary
protected  PersistenceAdapter db
           
protected  BufferedReader in
           
protected  InputStream inStream
           
protected  PrintStream out
           
protected  OutputStream outStream
           
protected  Route route
           
protected  Server server
           
protected  User user
           
 
Constructor Summary
protected ClientHandler(Server server, Socket socket, User user)
          Sets up socket streams for client communication and creates the message reader thread for message processing.
 
Method Summary
protected  Route getActiveRoute()
          Returns the currently active route for this client handler.
protected  void log(String message)
          This method is used for logging messages on the server.
protected abstract  boolean messageHandler(String message)
          Invoked when a new message has been recieved.
protected  void messageLoop()
          Checks for messages recieved from the server, and pass them to the message handler for further processing.
protected  void sendMessage(Object... message)
          Sends a message to the client.
protected  void sendMessage(OutputStream out, Object... message)
          Uses method in protocol to send message to client.
protected  void sendZipMessage(OutputStream out, Object... message)
          Sends compressed data to client.
protected  void startHandler()
          Start the socket data reader thread.
protected  void stopHandler()
          Invoked when the client has disconnected.
protected  void viewRoutes(String username)
          Get all routes from a specific user send them to the reciever.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

db

protected PersistenceAdapter db

server

protected Server server

user

protected User user

route

protected Route route

inStream

protected final InputStream inStream

outStream

protected final OutputStream outStream

in

protected final BufferedReader in

out

protected final PrintStream out
Constructor Detail

ClientHandler

protected ClientHandler(Server server,
                        Socket socket,
                        User user)
                 throws IOException
Sets up socket streams for client communication and creates the message reader thread for message processing.

Parameters:
server - main server instance
socket - client communication socket
user - client user data
Throws:
IOException - on connection failure
Method Detail

stopHandler

protected void stopHandler()
Invoked when the client has disconnected. Sub-classes can override this method to implement their own clean up procedure when a connection is closed down in order to release resources and object references.


startHandler

protected void startHandler()
Start the socket data reader thread.


messageLoop

protected void messageLoop()
                    throws IOException
Checks for messages recieved from the server, and pass them to the message handler for further processing. Subclasses can override this method to provide their own message loop if message processing needs to be more fine grained than simple line based delimiting.

Throws:
IOException

messageHandler

protected abstract boolean messageHandler(String message)
Invoked when a new message has been recieved. Sub-classes must implement this method to provide handing of recieved messages.

Parameters:
message - received message from client

viewRoutes

protected void viewRoutes(String username)
Get all routes from a specific user send them to the reciever.

Parameters:
username - username to get routes from

sendMessage

protected void sendMessage(OutputStream out,
                           Object... message)
Uses method in protocol to send message to client.

Parameters:
out - output stream
message - fields

sendMessage

protected void sendMessage(Object... message)
Sends a message to the client.

Parameters:
message - message to send

sendZipMessage

protected void sendZipMessage(OutputStream out,
                              Object... message)
Sends compressed data to client.

Parameters:
out - output stream
message - fields

log

protected void log(String message)
This method is used for logging messages on the server.

Parameters:
message - log message

getActiveRoute

protected Route getActiveRoute()
Returns the currently active route for this client handler.

Returns:
currently active route


Copyright © 2006 Team Trip Tracker. All Rights Reserved.