|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.dhcp4java.DHCPCoreServer
public class DHCPCoreServer
A simple generic DHCP Server. The DHCP Server provided is based on a multi-thread model. The main thread listens at the socket, then dispatches work to a pool of threads running the servlet.
Configuration: the Server reads the following properties in "/DHCPd.properties" at the root of the class path. You can however provide a properties set when contructing the server. Default values are:
serverAddress=127.0.0.1:67 [address:port]
serverThreads=2 [number of concurrent threads for servlets]
Note: this class implements Runnable allowing it to be run in a dedicated thread.
Example:
public static void main(String[] args) { try { DHCPCoreServer server = DHCPCoreServer.initServer(new DHCPStaticServlet(), null); new Thread(server).start(); } catch (DHCPServerInitException e) { // die gracefully } }
Field Summary | |
---|---|
protected static int |
PACKET_SIZE
default MTU for ethernet |
protected java.util.Properties |
properties
Consolidated parameters of the server. |
static java.lang.String |
SERVER_ADDRESS
|
static java.lang.String |
SERVER_THREADS
|
static java.lang.String |
SERVER_THREADS_KEEPALIVE
|
static java.lang.String |
SERVER_THREADS_MAX
|
protected DHCPServlet |
servlet
the servlet it must run |
protected java.util.concurrent.ThreadPoolExecutor |
threadPool
working threads pool. |
protected java.util.Properties |
userProps
Reference of user-provided parameters |
Method Summary | |
---|---|
protected void |
dispatch()
|
protected java.net.InetSocketAddress |
getInetSocketAddress(java.util.Properties props)
Returns the InetSocketAddress for the server (client-side). |
java.net.InetSocketAddress |
getSockAddress()
|
protected void |
init()
Initialize the server context from the Properties, and open socket. |
static DHCPCoreServer |
initServer(DHCPServlet servlet,
java.util.Properties userProps)
Creates and initializes a new DHCP Server. |
static java.net.InetSocketAddress |
parseSocketAddress(java.lang.String address)
Parse a string of the form 'server:port' or '192.168.1.10:67'. |
void |
run()
This is the main loop for accepting new request and delegating work to servlets in different threads. |
protected void |
sendResponse(java.net.DatagramPacket responseDatagram)
Send back response packet to client. |
void |
stopServer()
This method stops the server and closes the socket. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int PACKET_SIZE
protected DHCPServlet servlet
protected java.util.concurrent.ThreadPoolExecutor threadPool
protected java.util.Properties properties
protected java.util.Properties userProps
public static final java.lang.String SERVER_ADDRESS
public static final java.lang.String SERVER_THREADS
public static final java.lang.String SERVER_THREADS_MAX
public static final java.lang.String SERVER_THREADS_KEEPALIVE
Method Detail |
---|
public static DHCPCoreServer initServer(DHCPServlet servlet, java.util.Properties userProps) throws DHCPServerInitException
It instanciates the object, then calls init() method.
servlet
- the DHCPServlet instance processing incoming requests,
must not be null.userProps
- specific properties, overriding file and default properties,
may be null.
DHCPServerInitException
- unable to start the server.protected void init() throws DHCPServerInitException
DHCPServerInitException
protected void dispatch()
protected void sendResponse(java.net.DatagramPacket responseDatagram)
This is a callback method used by servlet dispatchers to send back responses.
protected java.net.InetSocketAddress getInetSocketAddress(java.util.Properties props)
serverAddress (default 127.0.0.1) serverPort (default 67)
This method can be overriden to specify an non default socket behaviour
props
- Properties loaded from /DHCPd.properties
public static java.net.InetSocketAddress parseSocketAddress(java.lang.String address)
address
- string to parse
java.lang.IllegalArgumentException
- if unable to parse stringpublic void run()
run
in interface java.lang.Runnable
public void stopServer()
public java.net.InetSocketAddress getSockAddress()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |