public class DHCPCoreServer extends Object implements Runnable
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
}
}
| Modifier and Type | Field and Description |
|---|---|
protected Properties |
m_aProperties
Consolidated parameters of the server.
|
protected DHCPServlet |
m_aServlet
the servlet it must run
|
protected ThreadPoolExecutor |
m_aThreadPool
working threads pool.
|
protected Properties |
m_aUserProps
Reference of user-provided parameters
|
protected static int |
PACKET_SIZE
default MTU for ethernet
|
static String |
SERVER_ADDRESS |
static String |
SERVER_THREADS |
static String |
SERVER_THREADS_KEEPALIVE |
static String |
SERVER_THREADS_MAX |
| Modifier and Type | Method and Description |
|---|---|
protected void |
dispatch() |
protected InetSocketAddress |
getInetSocketAddress(Properties props)
Returns the
InetSocketAddress for the server (client-side). |
InetSocketAddress |
getSockAddress() |
protected void |
init()
Initialize the server context from the Properties, and open socket.
|
static DHCPCoreServer |
initServer(DHCPServlet servlet,
Properties userProps)
Creates and initializes a new DHCP Server.
|
static InetSocketAddress |
parseSocketAddress(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(DatagramPacket responseDatagram)
Send back response packet to client.
|
void |
stopServer()
This method stops the server and closes the socket.
|
protected static final int PACKET_SIZE
protected DHCPServlet m_aServlet
protected ThreadPoolExecutor m_aThreadPool
protected Properties m_aProperties
protected Properties m_aUserProps
public static final String SERVER_ADDRESS
public static final String SERVER_THREADS
public static final String SERVER_THREADS_MAX
public static final String SERVER_THREADS_KEEPALIVE
public static DHCPCoreServer initServer(DHCPServlet servlet, 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.DHCPCoreServer instance (never null).DHCPServerInitException - unable to start the server.protected void init()
throws DHCPServerInitException
DHCPServerInitException - on errorprotected void dispatch()
protected void sendResponse(DatagramPacket responseDatagram)
This is a callback method used by servlet dispatchers to send back responses.
responseDatagram - suff to send backprotected InetSocketAddress getInetSocketAddress(Properties props)
InetSocketAddress for the server (client-side).
serverAddress (default 127.0.0.1) serverPort (default 67)
This method can be overridden to specify an non default socket behaviour
props - Properties loaded from /DHCPd.propertiespublic static InetSocketAddress parseSocketAddress(String address)
address - string to parseIllegalArgumentException - if unable to parse stringpublic void run()
public void stopServer()
public InetSocketAddress getSockAddress()
Copyright © 2018 Philip Helger. All rights reserved.