org.nhindirect.dns
Class UDPServer

java.lang.Object
  extended by org.nhindirect.dns.DNSSocketServer
      extended by org.nhindirect.dns.UDPServer

public class UDPServer
extends DNSSocketServer

UDP socket server that handled DNS requests over UDP.

Since:
1.0
Author:
Greg Meyer

Nested Class Summary
 class UDPServer.RequestTask
           
 
Constructor Summary
UDPServer(DNSServerSettings settings, DNSResponder responder)
          Creates a UDP server that listens to datagram packets.
 
Method Summary
 void createServerSocket()
          Creates and initializes the socket implementation that will accept incoming requests.
 Runnable getDNSRequestTask(Object packet)
          Gets the Runnable task that will process a DNS request.
 Runnable getSocketAcceptTask()
          Gets the Runnable task that will be responsible for accepting connections.
 void start()
          Starts the socket server and initializes the dispatch threads.
 void stop()
          Shuts down the socket server and terminates the server from accepting additional requests.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UDPServer

public UDPServer(DNSServerSettings settings,
                 DNSResponder responder)
          throws DNSException
Creates a UDP server that listens to datagram packets. The server will not start accepting messages until the start() method is called.

Parameters:
settings - The server settings. The settings contain specific IP and socket configuration parameters.
responsder - The DNS responder that will handle lookups.
Throws:
DNSException
Method Detail

start

public void start()
           throws DNSException
Starts the socket server and initializes the dispatch threads. After this method has been called, the server will start accepting DNS requests.

Overrides:
start in class DNSSocketServer
Throws:
DNSException

stop

public void stop()
          throws DNSException
Shuts down the socket server and terminates the server from accepting additional requests. The server attempts to gracefully shutdown the processing threads and gives currently running processing threads a chance to finish.

Overrides:
stop in class DNSSocketServer
Throws:
DNSException

createServerSocket

public void createServerSocket()
                        throws DNSException
Creates and initializes the socket implementation that will accept incoming requests.

Specified by:
createServerSocket in class DNSSocketServer
Throws:
DNSException

getSocketAcceptTask

public Runnable getSocketAcceptTask()
Gets the Runnable task that will be responsible for accepting connections. This task is placed in a single thread, so it should loop until the running flag is set to false.

Specified by:
getSocketAcceptTask in class DNSSocketServer
Returns:
The Runnable task that will be responsible for accepting connections

getDNSRequestTask

public Runnable getDNSRequestTask(Object packet)
Gets the Runnable task that will process a DNS request. Each accepted request will create a new instance of the Runnable task and run it in its own thread.

Specified by:
getDNSRequestTask in class DNSSocketServer
Parameters:
packet - An arbitrary parameter passed to the Runnable task. This parameter generally contain the DNS request information. This may be the TCP socket from the accept() server socket call or a UDP datagram packet.
Returns:
The Runnable task that will process a DNS request


Copyright © 2010-2011 The Direct Project. All Rights Reserved.