|
Luky Library - 4.1.1 (20061117-1148) | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
luky.serverSimple.Handler
public class Handler
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)
![]() |
![]() |
![]() |
![]() |
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 |
---|
protected PropertyManager propsMan
protected BufferedReader in
protected PrintWriter out
protected Server parent
Constructor Detail |
---|
public Handler(Hashtable userData, Server parent, BufferedReader in, PrintWriter out, PropertyManager propsMan, String caller)
Method Detail |
---|
public void run()
run
in interface Runnable
run
in class Thread
protected int handleUserCommand(BufferedReader in, PrintWriter out, String command)
in
- the input reader of the socket connection you are servingout
- the output writer of the socket connection you are servingcommand
- the command you should handle
protected String decrypt(String in)
in
- the input string
protected int destroy(BufferedReader in, PrintWriter out)
|
Luky Library - 4.1.1 (20061117-1148) | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |