|
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.Server
public class Server
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 :
![]() |
![]() |
![]() |
![]() |
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 |
---|
protected Vector myHandlers
protected PropertyManager propsMan
protected String version
protected Hashtable userData
protected EventListenerList listenerList
Constructor Detail |
---|
public Server(String[] args, String _version, String iniFile)
args
- the arguments that were used to start the server_version
- the version of this serveriniFile
- the filepublic Server(boolean log, int logLevel, boolean _quiet, String _version, PropertyManager props)
Method Detail |
---|
public void setQuit(boolean status)
status
- TRUE or FALSE, on TRUE the server will stopprotected int userInit()
public PropertyManager getPropsMan()
public void print(String msg)
msg
- the string that is to be printedpublic void println(String msg)
msg
- the string that is to be printedpublic void removeHandler(Handler handler)
protected Handler makeNewHandler(Hashtable userData, BufferedReader in, PrintWriter out, PropertyManager propsMan, String caller)
public void myEventOccurred(MyEvent evt)
myEventOccurred
in interface MyEventListener
public void addMyEventListener(MyEventListener listener)
public void removeMyEventListener(MyEventListener listener)
public void fireMyEvent(MyEvent evt)
public void childEventOccurred(MyEvent evt)
public void run()
run
in interface Runnable
run
in class Thread
|
Luky Library - 4.1.1 (20061117-1148) | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |