Luky Library - 4.1.1 (20061117-1148)

luky.serverSimple
Class Server

java.lang.Object
  extended by java.lang.Thread
      extended by luky.serverSimple.Server
All Implemented Interfaces:
Runnable, EventListener, MyEventListener

public class Server
extends Thread
implements MyEventListener

Server class is a template class which can be used to create a socket server program. It implents a standard interface which can easily be extended.
In order to use it properly one must also extend the Handler class and override it's methods to add the wanted functionality.
To give this extended handler to the server, one must override the server method "makeNewHandler" and use this function to create a new handler object of the derived type. The server will call this method each time a new connection is made and pass this connection to the handler.
When one needs special initialization, eg. the creation of an encryption object or a connection to a special database, one can override the userInit method. This method is called during the initialization and can store data in the userData hashtable. This hashtable is also passed to the handlers so the data is available where you may need it.
The properyManager is also available. You can use this object to get parameters from the initialization file that you provided for this server.
* The Server class uses the Log class and the propertyManager Revision Changes :

Version:
3.02
Author:
Chris Lukassen
 

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  EventListenerList listenerList
           
protected  Vector myHandlers
          variables
protected  PropertyManager propsMan
           
protected  Hashtable userData
           
protected  String version
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Server(boolean log, int logLevel, boolean _quiet, String _version, PropertyManager props)
          constructor, pass the arguments of the server here,
Server(String[] args, String _version, String iniFile)
          constructor, pass the arguments of the server here,
 
Method Summary
 void addMyEventListener(MyEventListener listener)
          This methods allows classes to register for MyEvents
 void childEventOccurred(MyEvent evt)
          The server can listen to events from his childeren, this can be overwritten to interact with them
 void fireMyEvent(MyEvent evt)
          This methods fires my events to registered listeners
 PropertyManager getPropsMan()
          getPropsMan() will return the property manager of this server.
protected  Handler makeNewHandler(Hashtable userData, BufferedReader in, PrintWriter out, PropertyManager propsMan, String caller)
          make a new handler class, must be overridden to add the custom handler class
 void myEventOccurred(MyEvent evt)
          The server can listen to generic events, this can be overwritten to interact with
 void print(String msg)
          print a message to the console of the server program, warning there is no newline included in this function, this may clutter your prints consideralbly since you are running in different threads.
 void println(String msg)
          print a message to the console of the server program, followed by a newline
 void removeHandler(Handler handler)
           
 void removeMyEventListener(MyEventListener listener)
          This methods allows classes to unregister for MyEvents
 void run()
          run method.
 void setQuit(boolean status)
          function that will be called by the handler class once a shutdown command is given.
protected  int userInit()
          userInit is called during the initalization of the server and can be used to add initialization to your server.
 
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

myHandlers

protected Vector myHandlers
variables


propsMan

protected PropertyManager propsMan

version

protected String version

userData

protected Hashtable userData

listenerList

protected EventListenerList listenerList
Constructor Detail

Server

public Server(String[] args,
              String _version,
              String iniFile)
constructor, pass the arguments of the server here,

Parameters:
args - the arguments that were used to start the server
_version - the version of this server
iniFile - the file

Server

public Server(boolean log,
              int logLevel,
              boolean _quiet,
              String _version,
              PropertyManager props)
constructor, pass the arguments of the server here,

Method Detail

setQuit

public void setQuit(boolean status)
function that will be called by the handler class once a shutdown command is given. It shutdowns the server loop.

Parameters:
status - TRUE or FALSE, on TRUE the server will stop

userInit

protected int userInit()
userInit is called during the initalization of the server and can be used to add initialization to your server.

Returns:
OK or NOK

getPropsMan

public PropertyManager getPropsMan()
getPropsMan() will return the property manager of this server. It is the same object that is also passed to the handlers.

Returns:
propsMan

print

public void print(String msg)
print a message to the console of the server program, warning there is no newline included in this function, this may clutter your prints consideralbly since you are running in different threads.

Parameters:
msg - the string that is to be printed

println

public void println(String msg)
print a message to the console of the server program, followed by a newline

Parameters:
msg - the string that is to be printed

removeHandler

public void removeHandler(Handler handler)

makeNewHandler

protected Handler makeNewHandler(Hashtable userData,
                                 BufferedReader in,
                                 PrintWriter out,
                                 PropertyManager propsMan,
                                 String caller)
make a new handler class, must be overridden to add the custom handler class

Returns:
new Handler

myEventOccurred

public void myEventOccurred(MyEvent evt)
The server can listen to generic events, this can be overwritten to interact with

Specified by:
myEventOccurred in interface MyEventListener

addMyEventListener

public void addMyEventListener(MyEventListener listener)
This methods allows classes to register for MyEvents


removeMyEventListener

public void removeMyEventListener(MyEventListener listener)
This methods allows classes to unregister for MyEvents


fireMyEvent

public void fireMyEvent(MyEvent evt)
This methods fires my events to registered listeners


childEventOccurred

public void childEventOccurred(MyEvent evt)
The server can listen to events from his childeren, this can be overwritten to interact with them


run

public void run()
run method. Create an instance of your derived server and start it in a seperate thread by calling the start function or in the same one by executing the run method. Note that the method will only return when a shutdown command is given.

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

Luky Library - 4.1.1 (20061117-1148)