Luky Library - 4.1.1 (20061117-1148)

luky.serverSimple
Class Handler

java.lang.Object
  extended by java.lang.Thread
      extended by luky.serverSimple.Handler
All Implemented Interfaces:
Runnable

public class Handler
extends Thread

The Handler class is a template class for the luky server handler thread. The class is beeing invoked by the Server on receipt of a socket connection. For each connection a new Thread of the handler class will be spawned. This handler will then handle the incomming commands, some of the commands are standarized like : HELLO, CLOSE and SHUTDOWN.
In order to make use of this class you must extend from it and add your extended class to your extention of the luky.server.server class. From there you will make sure that your class is called and not the default Handler.
Handler will serve the incomming connection and handle the HELLO, CLOSE, HELP and SHUTDOWN command for you. If it cannot identify the command, it will call upon the 'handleUserCommand method. This method is protected and should be overwritten by you. You can handle this command and return OK or NOK to the super class.
If for some reason you need to parse all incomming lines (like when they are encrypted) you can overload the 'decrypt' method. All incomming lines are passed through this function.
the in and out variables give you direct access to the socket you are connected to and you may use the propsMan to get any properties. Further you will have protected access to the luky variable which will handle all database access for you.
User specific data is available in the hashtable userData. You can use this table in the server class to pass some specific data to your Handler, like a crypt object for example.
The Handler uses the Log class for it's loggings
Version 1.10 also supports the CLEAN command, that forces the garbage collector clean up. (handy for testin)

Version:
1.10
Author:
Chris Lukassen
 

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  BufferedReader in
          in is your input stream, directly connected to the user you are supposed to handle
protected  PrintWriter out
          out is your connection to the user you are supposed to handle, you can use it to tell him how well you are doing with his commands
protected  Server parent
          parent access can be overloaded for convieniance
protected  PropertyManager propsMan
          this propertyManager holds all settings read from the .ini file at the startup of the server
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Handler(Hashtable userData, Server parent, BufferedReader in, PrintWriter out, PropertyManager propsMan, String caller)
          constructor, there is no need to call this constructor yourself, it will be called from the luky.server.server class.
 
Method Summary
protected  String decrypt(String in)
          decrypt is fed with every command string before it is passed to the internal command handler.
protected  int destroy(BufferedReader in, PrintWriter out)
          destroy is called before the thread is closed, it allows for the user to close existing streams or handle notifications when overriding, please remember to close the in and out streams !
protected  int handleUserCommand(BufferedReader in, PrintWriter out, String command)
          handleUserCommand, overwrite this function with your own version in which you must handle 'command' passed to this method.
 void run()
          run method, there is no need to call this constructor yourself, it will be called from the luky.server.server class.
 
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

propsMan

protected PropertyManager propsMan
this propertyManager holds all settings read from the .ini file at the startup of the server


in

protected BufferedReader in
in is your input stream, directly connected to the user you are supposed to handle


out

protected PrintWriter out
out is your connection to the user you are supposed to handle, you can use it to tell him how well you are doing with his commands


parent

protected Server parent
parent access can be overloaded for convieniance

Constructor Detail

Handler

public Handler(Hashtable userData,
               Server parent,
               BufferedReader in,
               PrintWriter out,
               PropertyManager propsMan,
               String caller)
constructor, there is no need to call this constructor yourself, it will be called from the luky.server.server class. (So don't sweat over it)

Method Detail

run

public void run()
run method, there is no need to call this constructor yourself, it will be called from the luky.server.server class. (So don't sweat over it)

Specified by:
run in interface Runnable
Overrides:
run in class Thread

handleUserCommand

protected int handleUserCommand(BufferedReader in,
                                PrintWriter out,
                                String command)
handleUserCommand, overwrite this function with your own version in which you must handle 'command' passed to this method. You can read/write to your corresponding party using the in/out parameters.

Parameters:
in - the input reader of the socket connection you are serving
out - the output writer of the socket connection you are serving
command - the command you should handle
Returns:
OK or NOK

decrypt

protected String decrypt(String in)
decrypt is fed with every command string before it is passed to the internal command handler. Implement a decryption function here if you need to parse all incomming lines.
the standard function simply returns the input string.

Parameters:
in - the input string
Returns:
the decrypted string

destroy

protected int destroy(BufferedReader in,
                      PrintWriter out)
destroy is called before the thread is closed, it allows for the user to close existing streams or handle notifications when overriding, please remember to close the in and out streams !


Luky Library - 4.1.1 (20061117-1148)